| OLD | NEW |
| 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_proxy.h" | 5 #include "ppapi/proxy/ppb_flash_proxy.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "ppapi/c/dev/ppb_font_dev.h" | 10 #include "ppapi/c/dev/ppb_font_dev.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 if (dispatcher) { | 36 if (dispatcher) { |
| 37 dispatcher->Send(new PpapiHostMsg_PPBFlash_SetInstanceAlwaysOnTop( | 37 dispatcher->Send(new PpapiHostMsg_PPBFlash_SetInstanceAlwaysOnTop( |
| 38 API_ID_PPB_FLASH, pp_instance, on_top)); | 38 API_ID_PPB_FLASH, pp_instance, on_top)); |
| 39 } | 39 } |
| 40 } | 40 } |
| 41 | 41 |
| 42 PP_Bool DrawGlyphs(PP_Instance instance, | 42 PP_Bool DrawGlyphs(PP_Instance instance, |
| 43 PP_Resource pp_image_data, | 43 PP_Resource pp_image_data, |
| 44 const PP_FontDescription_Dev* font_desc, | 44 const PP_FontDescription_Dev* font_desc, |
| 45 uint32_t color, | 45 uint32_t color, |
| 46 PP_Point position, | 46 const PP_Point* position, |
| 47 PP_Rect clip, | 47 const PP_Rect* clip, |
| 48 const float transformation[3][3], | 48 const float transformation[3][3], |
| 49 PP_Bool allow_subpixel_aa, |
| 49 uint32_t glyph_count, | 50 uint32_t glyph_count, |
| 50 const uint16_t glyph_indices[], | 51 const uint16_t glyph_indices[], |
| 51 const PP_Point glyph_advances[]) { | 52 const PP_Point glyph_advances[]) { |
| 52 Resource* image_data = | 53 Resource* image_data = |
| 53 PpapiGlobals::Get()->GetResourceTracker()->GetResource(pp_image_data); | 54 PpapiGlobals::Get()->GetResourceTracker()->GetResource(pp_image_data); |
| 54 if (!image_data) | 55 if (!image_data) |
| 55 return PP_FALSE; | 56 return PP_FALSE; |
| 56 // The instance parameter isn't strictly necessary but we check that it | 57 // The instance parameter isn't strictly necessary but we check that it |
| 57 // matches anyway. | 58 // matches anyway. |
| 58 if (image_data->pp_instance() != instance) | 59 if (image_data->pp_instance() != instance) |
| 59 return PP_FALSE; | 60 return PP_FALSE; |
| 60 | 61 |
| 61 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance( | 62 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance( |
| 62 image_data->pp_instance()); | 63 image_data->pp_instance()); |
| 63 if (!dispatcher) | 64 if (!dispatcher) |
| 64 return PP_FALSE; | 65 return PP_FALSE; |
| 65 | 66 |
| 66 PPBFlash_DrawGlyphs_Params params; | 67 PPBFlash_DrawGlyphs_Params params; |
| 67 params.image_data = image_data->host_resource(); | 68 params.image_data = image_data->host_resource(); |
| 68 params.font_desc.SetFromPPFontDescription(dispatcher, *font_desc, true); | 69 params.font_desc.SetFromPPFontDescription(dispatcher, *font_desc, true); |
| 69 params.color = color; | 70 params.color = color; |
| 70 params.position = position; | 71 params.position = *position; |
| 71 params.clip = clip; | 72 params.clip = *clip; |
| 72 for (int i = 0; i < 3; i++) { | 73 for (int i = 0; i < 3; i++) { |
| 73 for (int j = 0; j < 3; j++) | 74 for (int j = 0; j < 3; j++) |
| 74 params.transformation[i][j] = transformation[i][j]; | 75 params.transformation[i][j] = transformation[i][j]; |
| 75 } | 76 } |
| 77 params.allow_subpixel_aa = allow_subpixel_aa; |
| 76 | 78 |
| 77 params.glyph_indices.insert(params.glyph_indices.begin(), | 79 params.glyph_indices.insert(params.glyph_indices.begin(), |
| 78 &glyph_indices[0], | 80 &glyph_indices[0], |
| 79 &glyph_indices[glyph_count]); | 81 &glyph_indices[glyph_count]); |
| 80 params.glyph_advances.insert(params.glyph_advances.begin(), | 82 params.glyph_advances.insert(params.glyph_advances.begin(), |
| 81 &glyph_advances[0], | 83 &glyph_advances[0], |
| 82 &glyph_advances[glyph_count]); | 84 &glyph_advances[glyph_count]); |
| 83 | 85 |
| 84 PP_Bool result = PP_FALSE; | 86 PP_Bool result = PP_FALSE; |
| 85 dispatcher->Send(new PpapiHostMsg_PPBFlash_DrawGlyphs( | 87 dispatcher->Send(new PpapiHostMsg_PPBFlash_DrawGlyphs( |
| 86 API_ID_PPB_FLASH, params, &result)); | 88 API_ID_PPB_FLASH, params, &result)); |
| 87 return result; | 89 return result; |
| 88 } | 90 } |
| 89 | 91 |
| 92 PP_Bool DrawGlyphs11(PP_Instance instance, |
| 93 PP_Resource pp_image_data, |
| 94 const PP_FontDescription_Dev* font_desc, |
| 95 uint32_t color, |
| 96 PP_Point position, |
| 97 PP_Rect clip, |
| 98 const float transformation[3][3], |
| 99 uint32_t glyph_count, |
| 100 const uint16_t glyph_indices[], |
| 101 const PP_Point glyph_advances[]) { |
| 102 // Backwards-compatible version. |
| 103 return DrawGlyphs(instance, pp_image_data, font_desc, color, &position, |
| 104 &clip, transformation, PP_TRUE, glyph_count, glyph_indices, |
| 105 glyph_advances); |
| 106 } |
| 107 |
| 90 PP_Var GetProxyForURL(PP_Instance instance, const char* url) { | 108 PP_Var GetProxyForURL(PP_Instance instance, const char* url) { |
| 91 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 109 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 92 if (!dispatcher) | 110 if (!dispatcher) |
| 93 return PP_MakeUndefined(); | 111 return PP_MakeUndefined(); |
| 94 | 112 |
| 95 ReceiveSerializedVarReturnValue result; | 113 ReceiveSerializedVarReturnValue result; |
| 96 dispatcher->Send(new PpapiHostMsg_PPBFlash_GetProxyForURL( | 114 dispatcher->Send(new PpapiHostMsg_PPBFlash_GetProxyForURL( |
| 97 API_ID_PPB_FLASH, instance, url, &result)); | 115 API_ID_PPB_FLASH, instance, url, &result)); |
| 98 return result.Return(dispatcher); | 116 return result.Return(dispatcher); |
| 99 } | 117 } |
| 100 | 118 |
| 101 int32_t Navigate(PP_Resource request_id, | 119 int32_t Navigate(PP_Resource request_id, |
| 102 const char* target, | 120 const char* target, |
| 103 bool from_user_action) { | 121 PP_Bool from_user_action) { |
| 104 thunk::EnterResource<thunk::PPB_URLRequestInfo_API> enter(request_id, true); | 122 thunk::EnterResource<thunk::PPB_URLRequestInfo_API> enter(request_id, true); |
| 105 if (enter.failed()) | 123 if (enter.failed()) |
| 106 return PP_ERROR_BADRESOURCE; | 124 return PP_ERROR_BADRESOURCE; |
| 107 PP_Instance instance = enter.resource()->pp_instance(); | 125 PP_Instance instance = enter.resource()->pp_instance(); |
| 108 | 126 |
| 109 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 127 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 110 if (!dispatcher) | 128 if (!dispatcher) |
| 111 return PP_ERROR_FAILED; | 129 return PP_ERROR_FAILED; |
| 112 | 130 |
| 113 int32_t result = PP_ERROR_FAILED; | 131 int32_t result = PP_ERROR_FAILED; |
| 114 dispatcher->Send(new PpapiHostMsg_PPBFlash_Navigate( | 132 dispatcher->Send(new PpapiHostMsg_PPBFlash_Navigate( |
| 115 API_ID_PPB_FLASH, | 133 API_ID_PPB_FLASH, |
| 116 instance, enter.object()->GetData(), target, from_user_action, | 134 instance, enter.object()->GetData(), target, from_user_action, |
| 117 &result)); | 135 &result)); |
| 118 return result; | 136 return result; |
| 119 } | 137 } |
| 120 | 138 |
| 139 int32_t Navigate11(PP_Resource request_id, |
| 140 const char* target, |
| 141 bool from_user_action) { |
| 142 // Backwards-compatible version. |
| 143 return Navigate(request_id, target, PP_FromBool(from_user_action)); |
| 144 } |
| 145 |
| 121 void RunMessageLoop(PP_Instance instance) { | 146 void RunMessageLoop(PP_Instance instance) { |
| 122 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 147 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 123 if (!dispatcher) | 148 if (!dispatcher) |
| 124 return; | 149 return; |
| 125 IPC::SyncMessage* msg = new PpapiHostMsg_PPBFlash_RunMessageLoop( | 150 IPC::SyncMessage* msg = new PpapiHostMsg_PPBFlash_RunMessageLoop( |
| 126 API_ID_PPB_FLASH, instance); | 151 API_ID_PPB_FLASH, instance); |
| 127 msg->EnableMessagePumping(); | 152 msg->EnableMessagePumping(); |
| 128 dispatcher->Send(msg); | 153 dispatcher->Send(msg); |
| 129 } | 154 } |
| 130 | 155 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 151 dispatcher->Send(new PpapiHostMsg_PPBFlash_GetLocalTimeZoneOffset( | 176 dispatcher->Send(new PpapiHostMsg_PPBFlash_GetLocalTimeZoneOffset( |
| 152 API_ID_PPB_FLASH, instance, t, &result)); | 177 API_ID_PPB_FLASH, instance, t, &result)); |
| 153 return result; | 178 return result; |
| 154 } | 179 } |
| 155 | 180 |
| 156 PP_Var GetCommandLineArgs(PP_Module /*pp_module*/) { | 181 PP_Var GetCommandLineArgs(PP_Module /*pp_module*/) { |
| 157 std::string args = ProxyModule::GetInstance()->GetFlashCommandLineArgs(); | 182 std::string args = ProxyModule::GetInstance()->GetFlashCommandLineArgs(); |
| 158 return StringVar::StringToPPVar(args); | 183 return StringVar::StringToPPVar(args); |
| 159 } | 184 } |
| 160 | 185 |
| 161 const PPB_Flash flash_interface = { | 186 void PreLoadFontInWindows(const void* logfontw) { |
| 187 // TODO(brettw) implement this. |
| 188 } |
| 189 |
| 190 const PPB_Flash_11 flash_interface_11 = { |
| 191 &SetInstanceAlwaysOnTop, |
| 192 &DrawGlyphs11, |
| 193 &GetProxyForURL, |
| 194 &Navigate11, |
| 195 &RunMessageLoop, |
| 196 &QuitMessageLoop, |
| 197 &GetLocalTimeZoneOffset, |
| 198 &GetCommandLineArgs |
| 199 }; |
| 200 |
| 201 const PPB_Flash flash_interface_12 = { |
| 162 &SetInstanceAlwaysOnTop, | 202 &SetInstanceAlwaysOnTop, |
| 163 &DrawGlyphs, | 203 &DrawGlyphs, |
| 164 &GetProxyForURL, | 204 &GetProxyForURL, |
| 165 &Navigate, | 205 &Navigate, |
| 166 &RunMessageLoop, | 206 &RunMessageLoop, |
| 167 &QuitMessageLoop, | 207 &QuitMessageLoop, |
| 168 &GetLocalTimeZoneOffset, | 208 &GetLocalTimeZoneOffset, |
| 169 &GetCommandLineArgs | 209 &GetCommandLineArgs, |
| 210 &PreLoadFontInWindows |
| 170 }; | 211 }; |
| 171 | 212 |
| 172 InterfaceProxy* CreateFlashProxy(Dispatcher* dispatcher) { | |
| 173 return new PPB_Flash_Proxy(dispatcher); | |
| 174 } | |
| 175 | |
| 176 } // namespace | 213 } // namespace |
| 177 | 214 |
| 178 PPB_Flash_Proxy::PPB_Flash_Proxy(Dispatcher* dispatcher) | 215 PPB_Flash_Proxy::PPB_Flash_Proxy(Dispatcher* dispatcher) |
| 179 : InterfaceProxy(dispatcher), | 216 : InterfaceProxy(dispatcher), |
| 180 ppb_flash_impl_(NULL) { | 217 ppb_flash_impl_(NULL) { |
| 181 if (!dispatcher->IsPlugin()) | 218 if (!dispatcher->IsPlugin()) |
| 182 ppb_flash_impl_ = static_cast<const PPB_Flash*>( | 219 ppb_flash_impl_ = static_cast<const PPB_Flash*>( |
| 183 dispatcher->local_get_interface()(PPB_FLASH_INTERFACE)); | 220 dispatcher->local_get_interface()(PPB_FLASH_INTERFACE)); |
| 184 } | 221 } |
| 185 | 222 |
| 186 PPB_Flash_Proxy::~PPB_Flash_Proxy() { | 223 PPB_Flash_Proxy::~PPB_Flash_Proxy() { |
| 187 } | 224 } |
| 188 | 225 |
| 189 // static | 226 // static |
| 190 const PPB_Flash* PPB_Flash_Proxy::GetInterface() { | 227 const PPB_Flash_11* PPB_Flash_Proxy::GetInterface11() { |
| 191 return &flash_interface; | 228 return &flash_interface_11; |
| 229 } |
| 230 |
| 231 // static |
| 232 const PPB_Flash* PPB_Flash_Proxy::GetInterface12() { |
| 233 return &flash_interface_12; |
| 192 } | 234 } |
| 193 | 235 |
| 194 bool PPB_Flash_Proxy::OnMessageReceived(const IPC::Message& msg) { | 236 bool PPB_Flash_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 195 // Prevent the dispatcher from going away during a call to Navigate. | 237 // Prevent the dispatcher from going away during a call to Navigate. |
| 196 // This must happen OUTSIDE of OnMsgNavigate since the handling code use | 238 // This must happen OUTSIDE of OnMsgNavigate since the handling code use |
| 197 // the dispatcher upon return of the function (sending the reply message). | 239 // the dispatcher upon return of the function (sending the reply message). |
| 198 ScopedModuleReference death_grip(dispatcher()); | 240 ScopedModuleReference death_grip(dispatcher()); |
| 199 | 241 |
| 200 bool handled = true; | 242 bool handled = true; |
| 201 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Proxy, msg) | 243 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Proxy, msg) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 231 PP_FontDescription_Dev font_desc; | 273 PP_FontDescription_Dev font_desc; |
| 232 params.font_desc.SetToPPFontDescription(dispatcher(), &font_desc, false); | 274 params.font_desc.SetToPPFontDescription(dispatcher(), &font_desc, false); |
| 233 | 275 |
| 234 if (params.glyph_indices.size() != params.glyph_advances.size() || | 276 if (params.glyph_indices.size() != params.glyph_advances.size() || |
| 235 params.glyph_indices.empty()) | 277 params.glyph_indices.empty()) |
| 236 return; | 278 return; |
| 237 | 279 |
| 238 *result = ppb_flash_impl_->DrawGlyphs( | 280 *result = ppb_flash_impl_->DrawGlyphs( |
| 239 0, // Unused instance param. | 281 0, // Unused instance param. |
| 240 params.image_data.host_resource(), &font_desc, | 282 params.image_data.host_resource(), &font_desc, |
| 241 params.color, params.position, params.clip, | 283 params.color, ¶ms.position, ¶ms.clip, |
| 242 const_cast<float(*)[3]>(params.transformation), | 284 const_cast<float(*)[3]>(params.transformation), |
| 285 params.allow_subpixel_aa, |
| 243 static_cast<uint32_t>(params.glyph_indices.size()), | 286 static_cast<uint32_t>(params.glyph_indices.size()), |
| 244 const_cast<uint16_t*>(¶ms.glyph_indices[0]), | 287 const_cast<uint16_t*>(¶ms.glyph_indices[0]), |
| 245 const_cast<PP_Point*>(¶ms.glyph_advances[0])); | 288 const_cast<PP_Point*>(¶ms.glyph_advances[0])); |
| 246 } | 289 } |
| 247 | 290 |
| 248 void PPB_Flash_Proxy::OnMsgGetProxyForURL(PP_Instance instance, | 291 void PPB_Flash_Proxy::OnMsgGetProxyForURL(PP_Instance instance, |
| 249 const std::string& url, | 292 const std::string& url, |
| 250 SerializedVarReturnValue result) { | 293 SerializedVarReturnValue result) { |
| 251 result.Return(dispatcher(), ppb_flash_impl_->GetProxyForURL( | 294 result.Return(dispatcher(), ppb_flash_impl_->GetProxyForURL( |
| 252 instance, url.c_str())); | 295 instance, url.c_str())); |
| 253 } | 296 } |
| 254 | 297 |
| 255 void PPB_Flash_Proxy::OnMsgNavigate(PP_Instance instance, | 298 void PPB_Flash_Proxy::OnMsgNavigate(PP_Instance instance, |
| 256 const PPB_URLRequestInfo_Data& data, | 299 const PPB_URLRequestInfo_Data& data, |
| 257 const std::string& target, | 300 const std::string& target, |
| 258 bool from_user_action, | 301 PP_Bool from_user_action, |
| 259 int32_t* result) { | 302 int32_t* result) { |
| 260 DCHECK(!dispatcher()->IsPlugin()); | 303 DCHECK(!dispatcher()->IsPlugin()); |
| 261 | 304 |
| 262 // Validate the PP_Instance since we'll be constructing resources on its | 305 // Validate the PP_Instance since we'll be constructing resources on its |
| 263 // behalf. | 306 // behalf. |
| 264 HostDispatcher* host_dispatcher = static_cast<HostDispatcher*>(dispatcher()); | 307 HostDispatcher* host_dispatcher = static_cast<HostDispatcher*>(dispatcher()); |
| 265 if (HostDispatcher::GetForInstance(instance) != host_dispatcher) { | 308 if (HostDispatcher::GetForInstance(instance) != host_dispatcher) { |
| 266 NOTREACHED(); | 309 NOTREACHED(); |
| 267 *result = PP_ERROR_BADARGUMENT; | 310 *result = PP_ERROR_BADARGUMENT; |
| 268 return; | 311 return; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 299 } | 342 } |
| 300 | 343 |
| 301 void PPB_Flash_Proxy::OnMsgGetLocalTimeZoneOffset(PP_Instance instance, | 344 void PPB_Flash_Proxy::OnMsgGetLocalTimeZoneOffset(PP_Instance instance, |
| 302 PP_Time t, | 345 PP_Time t, |
| 303 double* result) { | 346 double* result) { |
| 304 *result = ppb_flash_impl_->GetLocalTimeZoneOffset(instance, t); | 347 *result = ppb_flash_impl_->GetLocalTimeZoneOffset(instance, t); |
| 305 } | 348 } |
| 306 | 349 |
| 307 } // namespace proxy | 350 } // namespace proxy |
| 308 } // namespace ppapi | 351 } // namespace ppapi |
| OLD | NEW |