Chromium Code Reviews| 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_font_proxy.h" | 5 #include "ppapi/proxy/ppb_font_proxy.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "ppapi/c/dev/ppb_font_dev.h" | 9 #include "ppapi/c/dev/ppb_font_dev.h" |
| 10 #include "ppapi/proxy/plugin_dispatcher.h" | 10 #include "ppapi/proxy/plugin_dispatcher.h" |
| 11 #include "ppapi/proxy/ppapi_messages.h" | 11 #include "ppapi/proxy/ppapi_messages.h" |
| 12 #include "ppapi/proxy/ppb_image_data_proxy.h" | 12 #include "ppapi/proxy/ppb_image_data_proxy.h" |
| 13 #include "ppapi/proxy/serialized_var.h" | 13 #include "ppapi/proxy/serialized_var.h" |
| 14 #include "ppapi/shared_impl/ppapi_preferences.h" | 14 #include "ppapi/shared_impl/ppapi_preferences.h" |
| 15 #include "ppapi/shared_impl/resource.h" | 15 #include "ppapi/shared_impl/resource.h" |
| 16 #include "ppapi/shared_impl/var.h" | 16 #include "ppapi/shared_impl/var.h" |
| 17 #include "ppapi/thunk/enter.h" | 17 #include "ppapi/thunk/enter.h" |
| 18 #include "ppapi/thunk/ppb_image_data_api.h" | 18 #include "ppapi/thunk/ppb_image_data_api.h" |
| 19 #include "ppapi/thunk/thunk.h" | 19 #include "ppapi/thunk/thunk.h" |
| 20 | 20 |
| 21 using ppapi::HostResource; | |
| 22 using ppapi::Resource; | |
| 23 using ppapi::StringVar; | |
| 24 using ppapi::thunk::EnterResourceNoLock; | 21 using ppapi::thunk::EnterResourceNoLock; |
| 25 using ppapi::thunk::PPB_ImageData_API; | 22 using ppapi::thunk::PPB_ImageData_API; |
|
bbudge
2011/08/16 22:40:49
Why not also declare PPB_Font_API and PPB_Font_Fun
| |
| 26 using ppapi::WebKitForwarding; | |
| 27 | 23 |
| 28 namespace pp { | 24 namespace ppapi { |
| 29 namespace proxy { | 25 namespace proxy { |
| 30 | 26 |
| 31 namespace { | 27 namespace { |
| 32 | 28 |
| 33 bool PPTextRunToTextRun(const PP_TextRun_Dev* run, | 29 bool PPTextRunToTextRun(const PP_TextRun_Dev* run, |
| 34 WebKitForwarding::Font::TextRun* output) { | 30 WebKitForwarding::Font::TextRun* output) { |
| 35 scoped_refptr<StringVar> str(StringVar::FromPPVar(run->text)); | 31 scoped_refptr<StringVar> str(StringVar::FromPPVar(run->text)); |
| 36 if (!str) | 32 if (!str) |
| 37 return false; | 33 return false; |
| 38 | 34 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 53 const void* target_interface) | 49 const void* target_interface) |
| 54 : InterfaceProxy(dispatcher, target_interface) { | 50 : InterfaceProxy(dispatcher, target_interface) { |
| 55 } | 51 } |
| 56 | 52 |
| 57 PPB_Font_Proxy::~PPB_Font_Proxy() { | 53 PPB_Font_Proxy::~PPB_Font_Proxy() { |
| 58 } | 54 } |
| 59 | 55 |
| 60 // static | 56 // static |
| 61 const InterfaceProxy::Info* PPB_Font_Proxy::GetInfo() { | 57 const InterfaceProxy::Info* PPB_Font_Proxy::GetInfo() { |
| 62 static const Info info = { | 58 static const Info info = { |
| 63 ::ppapi::thunk::GetPPB_Font_Thunk(), | 59 thunk::GetPPB_Font_Thunk(), |
| 64 PPB_FONT_DEV_INTERFACE, | 60 PPB_FONT_DEV_INTERFACE, |
| 65 INTERFACE_ID_PPB_FONT, | 61 INTERFACE_ID_PPB_FONT, |
| 66 false, | 62 false, |
| 67 &CreateFontProxy, | 63 &CreateFontProxy, |
| 68 }; | 64 }; |
| 69 return &info; | 65 return &info; |
| 70 } | 66 } |
| 71 | 67 |
| 72 ::ppapi::thunk::PPB_Font_FunctionAPI* PPB_Font_Proxy::AsPPB_Font_FunctionAPI() { | 68 thunk::PPB_Font_FunctionAPI* PPB_Font_Proxy::AsPPB_Font_FunctionAPI() { |
| 73 return this; | 69 return this; |
| 74 } | 70 } |
| 75 | 71 |
| 76 PP_Var PPB_Font_Proxy::GetFontFamilies(PP_Instance instance) { | 72 PP_Var PPB_Font_Proxy::GetFontFamilies(PP_Instance instance) { |
| 77 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 73 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 78 if (!dispatcher) | 74 if (!dispatcher) |
| 79 return PP_MakeUndefined(); | 75 return PP_MakeUndefined(); |
| 80 | 76 |
| 81 // Assume the font families don't change, so we can cache the result globally. | 77 // Assume the font families don't change, so we can cache the result globally. |
| 82 static std::string families; | 78 static std::string families; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 110 &webkit_event_, desc, | 106 &webkit_event_, desc, |
| 111 face.get() ? face->value() : std::string(), | 107 face.get() ? face->value() : std::string(), |
| 112 dispatcher->preferences(), | 108 dispatcher->preferences(), |
| 113 &font_forwarding_)); | 109 &font_forwarding_)); |
| 114 } | 110 } |
| 115 | 111 |
| 116 Font::~Font() { | 112 Font::~Font() { |
| 117 RunOnWebKitThread(false, base::Bind(&DeleteFontForwarding, font_forwarding_)); | 113 RunOnWebKitThread(false, base::Bind(&DeleteFontForwarding, font_forwarding_)); |
| 118 } | 114 } |
| 119 | 115 |
| 120 ppapi::thunk::PPB_Font_API* Font::AsPPB_Font_API() { | 116 thunk::PPB_Font_API* Font::AsPPB_Font_API() { |
| 121 return this; | 117 return this; |
| 122 } | 118 } |
| 123 | 119 |
| 124 PP_Bool Font::Describe(PP_FontDescription_Dev* description, | 120 PP_Bool Font::Describe(PP_FontDescription_Dev* description, |
| 125 PP_FontMetrics_Dev* metrics) { | 121 PP_FontMetrics_Dev* metrics) { |
| 126 TRACE_EVENT0("ppapi proxy", "Font::Describe"); | 122 TRACE_EVENT0("ppapi proxy", "Font::Describe"); |
| 127 std::string face; | 123 std::string face; |
| 128 PP_Bool result = PP_FALSE; | 124 PP_Bool result = PP_FALSE; |
| 129 RunOnWebKitThread(true, | 125 RunOnWebKitThread(true, |
| 130 base::Bind(&WebKitForwarding::Font::Describe, | 126 base::Bind(&WebKitForwarding::Font::Describe, |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 return result; | 218 return result; |
| 223 } | 219 } |
| 224 | 220 |
| 225 void Font::RunOnWebKitThread(bool blocking, const base::Closure& task) { | 221 void Font::RunOnWebKitThread(bool blocking, const base::Closure& task) { |
| 226 PluginDispatcher::GetForResource(this)->PostToWebKitThread(FROM_HERE, task); | 222 PluginDispatcher::GetForResource(this)->PostToWebKitThread(FROM_HERE, task); |
| 227 if (blocking) | 223 if (blocking) |
| 228 webkit_event_.Wait(); | 224 webkit_event_.Wait(); |
| 229 } | 225 } |
| 230 | 226 |
| 231 // static | 227 // static |
| 232 void Font::DeleteFontForwarding( | 228 void Font::DeleteFontForwarding(WebKitForwarding::Font* font_forwarding) { |
| 233 ppapi::WebKitForwarding::Font* font_forwarding) { | |
| 234 delete font_forwarding; | 229 delete font_forwarding; |
| 235 } | 230 } |
| 236 | 231 |
| 237 } // namespace proxy | 232 } // namespace proxy |
| 238 } // namespace pp | 233 } // namespace ppapi |
| OLD | NEW |