OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/renderer/pepper/pepper_pdf_host.h" | 5 #include "chrome/renderer/pepper/pepper_pdf_host.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/common/render_messages.h" | 8 #include "chrome/common/render_messages.h" |
9 #include "chrome/renderer/printing/print_web_view_helper.h" | 9 #include "chrome/renderer/printing/print_web_view_helper.h" |
| 10 #include "content/public/common/referrer.h" |
10 #include "content/public/renderer/render_thread.h" | 11 #include "content/public/renderer/render_thread.h" |
11 #include "content/public/renderer/render_view.h" | 12 #include "content/public/renderer/render_view.h" |
12 #include "content/public/renderer/renderer_ppapi_host.h" | 13 #include "content/public/renderer/renderer_ppapi_host.h" |
13 #include "grit/webkit_resources.h" | 14 #include "grit/webkit_resources.h" |
14 #include "grit/webkit_strings.h" | 15 #include "grit/webkit_strings.h" |
15 #include "ppapi/host/dispatch_host_message.h" | 16 #include "ppapi/host/dispatch_host_message.h" |
16 #include "ppapi/host/host_message_context.h" | 17 #include "ppapi/host/host_message_context.h" |
17 #include "ppapi/host/ppapi_host.h" | 18 #include "ppapi/host/ppapi_host.h" |
18 #include "ppapi/proxy/host_dispatcher.h" | 19 #include "ppapi/proxy/host_dispatcher.h" |
19 #include "ppapi/proxy/ppapi_messages.h" | 20 #include "ppapi/proxy/ppapi_messages.h" |
20 #include "ppapi/proxy/ppb_image_data_proxy.h" | 21 #include "ppapi/proxy/ppb_image_data_proxy.h" |
21 #include "ppapi/shared_impl/scoped_pp_resource.h" | 22 #include "ppapi/shared_impl/scoped_pp_resource.h" |
22 #include "ppapi/thunk/enter.h" | 23 #include "ppapi/thunk/enter.h" |
23 #include "third_party/WebKit/public/web/WebDocument.h" | 24 #include "third_party/WebKit/public/web/WebDocument.h" |
24 #include "third_party/WebKit/public/web/WebElement.h" | 25 #include "third_party/WebKit/public/web/WebElement.h" |
25 #include "third_party/WebKit/public/web/WebFrame.h" | 26 #include "third_party/WebKit/public/web/WebFrame.h" |
26 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 27 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
| 28 #include "third_party/WebKit/public/web/WebView.h" |
27 #include "third_party/skia/include/core/SkBitmap.h" | 29 #include "third_party/skia/include/core/SkBitmap.h" |
28 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
29 #include "ui/base/layout.h" | 31 #include "ui/base/layout.h" |
30 #include "ui/base/resource/resource_bundle.h" | 32 #include "ui/base/resource/resource_bundle.h" |
31 #include "ui/gfx/image/image_skia.h" | 33 #include "ui/gfx/image/image_skia.h" |
32 #include "ui/gfx/image/image_skia_rep.h" | 34 #include "ui/gfx/image/image_skia_rep.h" |
33 #include "ui/gfx/point.h" | 35 #include "ui/gfx/point.h" |
34 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 36 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
35 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" | 37 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
36 | 38 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 | 173 |
172 context->reply_msg = PpapiPluginMsg_PDF_GetLocalizedStringReply(rv); | 174 context->reply_msg = PpapiPluginMsg_PDF_GetLocalizedStringReply(rv); |
173 return PP_OK; | 175 return PP_OK; |
174 } | 176 } |
175 | 177 |
176 int32_t PepperPDFHost::OnHostMsgDidStartLoading( | 178 int32_t PepperPDFHost::OnHostMsgDidStartLoading( |
177 ppapi::host::HostMessageContext* context) { | 179 ppapi::host::HostMessageContext* context) { |
178 PluginInstance* instance = host_->GetPluginInstance(pp_instance()); | 180 PluginInstance* instance = host_->GetPluginInstance(pp_instance()); |
179 if (!instance) | 181 if (!instance) |
180 return PP_ERROR_FAILED; | 182 return PP_ERROR_FAILED; |
181 instance->delegate()->DidStartLoading(); | 183 instance->render_view()->DidStartLoading(); |
182 return PP_OK; | 184 return PP_OK; |
183 } | 185 } |
184 | 186 |
185 int32_t PepperPDFHost::OnHostMsgDidStopLoading( | 187 int32_t PepperPDFHost::OnHostMsgDidStopLoading( |
186 ppapi::host::HostMessageContext* context) { | 188 ppapi::host::HostMessageContext* context) { |
187 PluginInstance* instance = host_->GetPluginInstance(pp_instance()); | 189 PluginInstance* instance = host_->GetPluginInstance(pp_instance()); |
188 if (!instance) | 190 if (!instance) |
189 return PP_ERROR_FAILED; | 191 return PP_ERROR_FAILED; |
190 instance->delegate()->DidStopLoading(); | 192 instance->render_view()->DidStopLoading(); |
191 return PP_OK; | 193 return PP_OK; |
192 } | 194 } |
193 | 195 |
194 int32_t PepperPDFHost::OnHostMsgSetContentRestriction( | 196 int32_t PepperPDFHost::OnHostMsgSetContentRestriction( |
195 ppapi::host::HostMessageContext* context, int restrictions) { | 197 ppapi::host::HostMessageContext* context, int restrictions) { |
196 PluginInstance* instance = host_->GetPluginInstance(pp_instance()); | 198 PluginInstance* instance = host_->GetPluginInstance(pp_instance()); |
197 if (!instance) | 199 if (!instance) |
198 return PP_ERROR_FAILED; | 200 return PP_ERROR_FAILED; |
199 instance->delegate()->SetContentRestriction(restrictions); | 201 instance->render_view()->Send( |
| 202 new ChromeViewHostMsg_PDFUpdateContentRestrictions( |
| 203 instance->render_view()->GetRoutingID(), restrictions)); |
200 return PP_OK; | 204 return PP_OK; |
201 } | 205 } |
202 | 206 |
203 int32_t PepperPDFHost::OnHostMsgUserMetricsRecordAction( | 207 int32_t PepperPDFHost::OnHostMsgUserMetricsRecordAction( |
204 ppapi::host::HostMessageContext* context, | 208 ppapi::host::HostMessageContext* context, |
205 const std::string& action) { | 209 const std::string& action) { |
206 bool valid = false; | 210 bool valid = false; |
207 for (size_t i = 0; i < arraysize(kValidUserMetricsActions); ++i) { | 211 for (size_t i = 0; i < arraysize(kValidUserMetricsActions); ++i) { |
208 if (action == kValidUserMetricsActions[i]) { | 212 if (action == kValidUserMetricsActions[i]) { |
209 valid = true; | 213 valid = true; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 } | 259 } |
256 #endif | 260 #endif |
257 return PP_ERROR_FAILED; | 261 return PP_ERROR_FAILED; |
258 } | 262 } |
259 | 263 |
260 int32_t PepperPDFHost::OnHostMsgSaveAs( | 264 int32_t PepperPDFHost::OnHostMsgSaveAs( |
261 ppapi::host::HostMessageContext* context) { | 265 ppapi::host::HostMessageContext* context) { |
262 PluginInstance* instance = host_->GetPluginInstance(pp_instance()); | 266 PluginInstance* instance = host_->GetPluginInstance(pp_instance()); |
263 if (!instance) | 267 if (!instance) |
264 return PP_ERROR_FAILED; | 268 return PP_ERROR_FAILED; |
265 instance->delegate()->SaveURLAs(instance->plugin_url()); | 269 GURL url = instance->plugin_url(); |
| 270 content::RenderView* render_view = instance->render_view(); |
| 271 WebKit::WebFrame* frame = render_view->GetWebView()->mainFrame(); |
| 272 content::Referrer referrer(frame->document().url(), |
| 273 frame->document().referrerPolicy()); |
| 274 render_view->Send(new ChromeViewHostMsg_PDFSaveURLAs( |
| 275 render_view->GetRoutingID(), url, referrer)); |
266 return PP_OK; | 276 return PP_OK; |
267 } | 277 } |
268 | 278 |
269 int32_t PepperPDFHost::OnHostMsgGetResourceImage( | 279 int32_t PepperPDFHost::OnHostMsgGetResourceImage( |
270 ppapi::host::HostMessageContext* context, | 280 ppapi::host::HostMessageContext* context, |
271 PP_ResourceImage image_id, | 281 PP_ResourceImage image_id, |
272 float scale) { | 282 float scale) { |
273 int res_id = 0; | 283 int res_id = 0; |
274 for (size_t i = 0; i < arraysize(kResourceImageMap); ++i) { | 284 for (size_t i = 0; i < arraysize(kResourceImageMap); ++i) { |
275 if (kResourceImageMap[i].pp_id == image_id) { | 285 if (kResourceImageMap[i].pp_id == image_id) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 | 379 |
370 const SkBitmap* bitmap = image_data->GetMappedBitmap(); | 380 const SkBitmap* bitmap = image_data->GetMappedBitmap(); |
371 pixels_to_write.copyPixelsTo(bitmap->getPixels(), | 381 pixels_to_write.copyPixelsTo(bitmap->getPixels(), |
372 bitmap->getSize(), | 382 bitmap->getSize(), |
373 bitmap->rowBytes()); | 383 bitmap->rowBytes()); |
374 | 384 |
375 return true; | 385 return true; |
376 } | 386 } |
377 | 387 |
378 } // namespace chrome | 388 } // namespace chrome |
OLD | NEW |