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

Side by Side Diff: content/renderer/pepper/pepper_flash_renderer_host.cc

Issue 11576016: Revert 172806 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years 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 | « content/renderer/pepper/pepper_flash_renderer_host.h ('k') | ppapi/proxy/flash_resource.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/renderer/pepper/pepper_flash_renderer_host.h" 5 #include "content/renderer/pepper/pepper_flash_renderer_host.h"
6 6
7 #include <vector>
8
9 #include "content/common/view_messages.h" 7 #include "content/common/view_messages.h"
10 #include "content/public/renderer/renderer_ppapi_host.h" 8 #include "content/public/renderer/renderer_ppapi_host.h"
11 #include "content/renderer/render_thread_impl.h" 9 #include "content/renderer/render_thread_impl.h"
12 #include "googleurl/src/gurl.h" 10 #include "googleurl/src/gurl.h"
13 #include "ipc/ipc_message_macros.h" 11 #include "ipc/ipc_message_macros.h"
14 #include "ppapi/c/pp_errors.h" 12 #include "ppapi/c/pp_errors.h"
15 #include "ppapi/c/trusted/ppb_browser_font_trusted.h"
16 #include "ppapi/host/dispatch_host_message.h" 13 #include "ppapi/host/dispatch_host_message.h"
17 #include "ppapi/proxy/host_dispatcher.h"
18 #include "ppapi/proxy/ppapi_messages.h" 14 #include "ppapi/proxy/ppapi_messages.h"
19 #include "ppapi/proxy/resource_message_params.h" 15 #include "ppapi/proxy/resource_message_params.h"
20 #include "ppapi/proxy/serialized_structs.h"
21 #include "ppapi/thunk/enter.h"
22 #include "ppapi/thunk/ppb_image_data_api.h"
23 #include "skia/ext/platform_canvas.h"
24 #include "third_party/skia/include/core/SkCanvas.h"
25 #include "third_party/skia/include/core/SkMatrix.h"
26 #include "third_party/skia/include/core/SkPaint.h"
27 #include "third_party/skia/include/core/SkPoint.h"
28 #include "third_party/skia/include/core/SkTemplates.h"
29 #include "third_party/skia/include/core/SkTypeface.h"
30 #include "ui/gfx/rect.h"
31 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
32 #include "webkit/plugins/ppapi/ppb_image_data_impl.h"
33
34 using ppapi::thunk::EnterResourceNoLock;
35 using ppapi::thunk::PPB_ImageData_API;
36 16
37 namespace content { 17 namespace content {
38 18
39 PepperFlashRendererHost::PepperFlashRendererHost( 19 PepperFlashRendererHost::PepperFlashRendererHost(
40 RendererPpapiHost* host, 20 RendererPpapiHost* host,
41 PP_Instance instance, 21 PP_Instance instance,
42 PP_Resource resource) 22 PP_Resource resource)
43 : ResourceHost(host->GetPpapiHost(), instance, resource), 23 : ResourceHost(host->GetPpapiHost(), instance, resource) {
44 host_(host) {
45 } 24 }
46 25
47 PepperFlashRendererHost::~PepperFlashRendererHost() { 26 PepperFlashRendererHost::~PepperFlashRendererHost() {
48 } 27 }
49 28
50 int32_t PepperFlashRendererHost::OnResourceMessageReceived( 29 int32_t PepperFlashRendererHost::OnResourceMessageReceived(
51 const IPC::Message& msg, 30 const IPC::Message& msg,
52 ppapi::host::HostMessageContext* context) { 31 ppapi::host::HostMessageContext* context) {
53 IPC_BEGIN_MESSAGE_MAP(PepperFlashRendererHost, msg) 32 IPC_BEGIN_MESSAGE_MAP(PepperFlashRendererHost, msg)
54 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Flash_GetProxyForURL, 33 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Flash_GetProxyForURL,
55 OnMsgGetProxyForURL); 34 OnMsgGetProxyForURL);
56 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Flash_SetInstanceAlwaysOnTop,
57 OnMsgSetInstanceAlwaysOnTop);
58 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Flash_DrawGlyphs,
59 OnMsgDrawGlyphs);
60 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Flash_Navigate,
61 OnMsgNavigate);
62 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Flash_IsRectTopmost,
63 OnMsgIsRectTopmost);
64 IPC_END_MESSAGE_MAP() 35 IPC_END_MESSAGE_MAP()
65 return PP_ERROR_FAILED; 36 return PP_ERROR_FAILED;
66 } 37 }
67 38
68 int32_t PepperFlashRendererHost::OnMsgGetProxyForURL( 39 int32_t PepperFlashRendererHost::OnMsgGetProxyForURL(
69 ppapi::host::HostMessageContext* host_context, 40 ppapi::host::HostMessageContext* host_context,
70 const std::string& url) { 41 const std::string& url) {
71 GURL gurl(url); 42 GURL gurl(url);
72 if (!gurl.is_valid()) 43 if (!gurl.is_valid())
73 return PP_ERROR_FAILED; 44 return PP_ERROR_FAILED;
74 bool result; 45 bool result;
75 std::string proxy; 46 std::string proxy;
76 RenderThreadImpl::current()->Send( 47 RenderThreadImpl::current()->Send(
77 new ViewHostMsg_ResolveProxy(gurl, &result, &proxy)); 48 new ViewHostMsg_ResolveProxy(gurl, &result, &proxy));
78 if (!result) 49 if (!result)
79 return PP_ERROR_FAILED; 50 return PP_ERROR_FAILED;
80 host_context->reply_msg = PpapiPluginMsg_Flash_GetProxyForURLReply(proxy); 51 host_context->reply_msg = PpapiPluginMsg_Flash_GetProxyForURLReply(proxy);
81 return PP_OK; 52 return PP_OK;
82 } 53 }
83 54
84 int32_t PepperFlashRendererHost::OnMsgSetInstanceAlwaysOnTop(
85 ppapi::host::HostMessageContext* host_context,
86 bool on_top) {
87 webkit::ppapi::PluginInstance* plugin_instance =
88 host_->GetPluginInstance(pp_instance());
89 if (plugin_instance)
90 plugin_instance->set_always_on_top(on_top);
91 // Since no reply is sent for this message, it doesn't make sense to return an
92 // error.
93 return PP_OK;
94 }
95
96 int32_t PepperFlashRendererHost::OnMsgDrawGlyphs(
97 ppapi::host::HostMessageContext* host_context,
98 ppapi::proxy::PPBFlash_DrawGlyphs_Params params) {
99 if (params.glyph_indices.size() != params.glyph_advances.size() ||
100 params.glyph_indices.empty())
101 return PP_ERROR_FAILED;
102
103 EnterResourceNoLock<PPB_ImageData_API> enter(
104 params.image_data.host_resource(), true);
105 if (enter.failed())
106 return PP_ERROR_FAILED;
107 webkit::ppapi::PPB_ImageData_Impl* image_resource =
108 static_cast<webkit::ppapi::PPB_ImageData_Impl*>(enter.object());
109
110 webkit::ppapi::ImageDataAutoMapper mapper(image_resource);
111 if (!mapper.is_valid())
112 return PP_ERROR_FAILED;
113
114 // Set up the typeface.
115 int style = SkTypeface::kNormal;
116 if (static_cast<PP_BrowserFont_Trusted_Weight>(params.font_desc.weight) >=
117 PP_BROWSERFONT_TRUSTED_WEIGHT_BOLD)
118 style |= SkTypeface::kBold;
119 if (params.font_desc.italic)
120 style |= SkTypeface::kItalic;
121 skia::RefPtr<SkTypeface> typeface = skia::AdoptRef(
122 SkTypeface::CreateFromName(params.font_desc.face.c_str(),
123 static_cast<SkTypeface::Style>(style)));
124 if (!typeface)
125 return PP_ERROR_FAILED;
126
127 // Set up the canvas.
128 SkCanvas* canvas = image_resource->GetPlatformCanvas();
129 SkAutoCanvasRestore acr(canvas, true);
130
131 // Clip is applied in pixels before the transform.
132 SkRect clip_rect = {
133 SkIntToScalar(params.clip.point.x),
134 SkIntToScalar(params.clip.point.y),
135 SkIntToScalar(params.clip.point.x + params.clip.size.width),
136 SkIntToScalar(params.clip.point.y + params.clip.size.height)
137 };
138 canvas->clipRect(clip_rect);
139
140 // Convert & set the matrix.
141 SkMatrix matrix;
142 matrix.set(SkMatrix::kMScaleX, SkFloatToScalar(params.transformation[0][0]));
143 matrix.set(SkMatrix::kMSkewX, SkFloatToScalar(params.transformation[0][1]));
144 matrix.set(SkMatrix::kMTransX, SkFloatToScalar(params.transformation[0][2]));
145 matrix.set(SkMatrix::kMSkewY, SkFloatToScalar(params.transformation[1][0]));
146 matrix.set(SkMatrix::kMScaleY, SkFloatToScalar(params.transformation[1][1]));
147 matrix.set(SkMatrix::kMTransY, SkFloatToScalar(params.transformation[1][2]));
148 matrix.set(SkMatrix::kMPersp0, SkFloatToScalar(params.transformation[2][0]));
149 matrix.set(SkMatrix::kMPersp1, SkFloatToScalar(params.transformation[2][1]));
150 matrix.set(SkMatrix::kMPersp2, SkFloatToScalar(params.transformation[2][2]));
151 canvas->concat(matrix);
152
153 SkPaint paint;
154 paint.setColor(params.color);
155 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
156 paint.setAntiAlias(true);
157 paint.setHinting(SkPaint::kFull_Hinting);
158 paint.setTextSize(SkIntToScalar(params.font_desc.size));
159 paint.setTypeface(typeface.get()); // Takes a ref and manages lifetime.
160 if (params.allow_subpixel_aa) {
161 paint.setSubpixelText(true);
162 paint.setLCDRenderText(true);
163 }
164
165 SkScalar x = SkIntToScalar(params.position.x);
166 SkScalar y = SkIntToScalar(params.position.y);
167
168 // Build up the skia advances.
169 size_t glyph_count = params.glyph_indices.size();
170 if (glyph_count == 0)
171 return PP_OK;
172 std::vector<SkPoint> storage;
173 storage.resize(glyph_count);
174 SkPoint* sk_positions = &storage[0];
175 for (uint32_t i = 0; i < glyph_count; i++) {
176 sk_positions[i].set(x, y);
177 x += SkFloatToScalar(params.glyph_advances[i].x);
178 y += SkFloatToScalar(params.glyph_advances[i].y);
179 }
180
181 canvas->drawPosText(&params.glyph_indices[0], glyph_count * 2, sk_positions,
182 paint);
183
184 return PP_OK;
185 }
186
187 int32_t PepperFlashRendererHost::OnMsgNavigate(
188 ppapi::host::HostMessageContext* host_context,
189 const ppapi::URLRequestInfoData& data,
190 const std::string& target,
191 bool from_user_action) {
192 webkit::ppapi::PluginInstance* plugin_instance =
193 host_->GetPluginInstance(pp_instance());
194 if (!plugin_instance)
195 return PP_ERROR_FAILED;
196
197 // We need to allow re-entrancy here, because this may call into Javascript
198 // (e.g. with a "javascript:" URL), or do things like navigate away from the
199 // page, either one of which will need to re-enter into the plugin.
200 // It is safe, because it is essentially equivalent to NPN_GetURL, where Flash
201 // would expect re-entrancy.
202 ppapi::proxy::HostDispatcher* host_dispatcher =
203 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance());
204 host_dispatcher->set_allow_plugin_reentrancy();
205
206 plugin_instance->Navigate(data, target.c_str(), from_user_action);
207 return PP_OK;
208 }
209
210 int32_t PepperFlashRendererHost::OnMsgIsRectTopmost(
211 ppapi::host::HostMessageContext* host_context,
212 const PP_Rect& rect) {
213 webkit::ppapi::PluginInstance* plugin_instance =
214 host_->GetPluginInstance(pp_instance());
215 if (plugin_instance && plugin_instance->IsRectTopmost(
216 gfx::Rect(rect.point.x, rect.point.y,rect.size.width, rect.size.height)))
217 return PP_OK;
218 return PP_ERROR_FAILED;
219 }
220
221 } // namespace content 55 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_flash_renderer_host.h ('k') | ppapi/proxy/flash_resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698