OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ppb_pdf_impl.h" | 5 #include "components/pdf/renderer/ppb_pdf_impl.h" |
6 | 6 |
7 #include "base/files/scoped_file.h" | 7 #include "base/files/scoped_file.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/numerics/safe_conversions.h" | 9 #include "base/numerics/safe_conversions.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
12 #include "chrome/common/render_messages.h" | 12 #include "components/pdf/common/pdf_messages.h" |
13 #include "chrome/renderer/printing/print_web_view_helper.h" | |
14 #include "content/app/strings/grit/content_strings.h" | 13 #include "content/app/strings/grit/content_strings.h" |
jam
2014/08/22 00:44:59
why is this include there?
| |
15 #include "content/public/common/child_process_sandbox_support_linux.h" | 14 #include "content/public/common/child_process_sandbox_support_linux.h" |
16 #include "content/public/common/referrer.h" | 15 #include "content/public/common/referrer.h" |
17 #include "content/public/renderer/pepper_plugin_instance.h" | 16 #include "content/public/renderer/pepper_plugin_instance.h" |
18 #include "content/public/renderer/render_thread.h" | 17 #include "content/public/renderer/render_thread.h" |
19 #include "content/public/renderer/render_view.h" | 18 #include "content/public/renderer/render_view.h" |
20 #include "grit/webkit_resources.h" | 19 #include "grit/webkit_resources.h" |
21 #include "ppapi/c/pp_resource.h" | 20 #include "ppapi/c/pp_resource.h" |
22 #include "ppapi/c/private/ppb_pdf.h" | 21 #include "ppapi/c/private/ppb_pdf.h" |
23 #include "ppapi/c/trusted/ppb_browser_font_trusted.h" | 22 #include "ppapi/c/trusted/ppb_browser_font_trusted.h" |
24 #include "ppapi/shared_impl/ppapi_globals.h" | 23 #include "ppapi/shared_impl/ppapi_globals.h" |
25 #include "ppapi/shared_impl/resource.h" | 24 #include "ppapi/shared_impl/resource.h" |
26 #include "ppapi/shared_impl/resource_tracker.h" | 25 #include "ppapi/shared_impl/resource_tracker.h" |
27 #include "ppapi/shared_impl/var.h" | 26 #include "ppapi/shared_impl/var.h" |
28 #include "third_party/WebKit/public/web/WebDocument.h" | 27 #include "third_party/WebKit/public/web/WebDocument.h" |
29 #include "third_party/WebKit/public/web/WebElement.h" | 28 #include "third_party/WebKit/public/web/WebElement.h" |
30 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 29 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
31 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 30 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
32 #include "third_party/WebKit/public/web/WebView.h" | 31 #include "third_party/WebKit/public/web/WebView.h" |
33 #include "third_party/icu/source/i18n/unicode/usearch.h" | 32 #include "third_party/icu/source/i18n/unicode/usearch.h" |
34 #include "third_party/skia/include/core/SkBitmap.h" | 33 #include "third_party/skia/include/core/SkBitmap.h" |
35 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
36 #include "ui/base/resource/resource_bundle.h" | 35 #include "ui/base/resource/resource_bundle.h" |
37 | 36 |
37 namespace pdf { | |
38 namespace { | 38 namespace { |
39 | 39 |
40 PPB_PDF_Impl::PrintDelegate* print_delegate = NULL; | |
41 | |
40 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 42 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
41 class PrivateFontFile : public ppapi::Resource { | 43 class PrivateFontFile : public ppapi::Resource { |
42 public: | 44 public: |
43 PrivateFontFile(PP_Instance instance, int fd) | 45 PrivateFontFile(PP_Instance instance, int fd) |
44 : Resource(ppapi::OBJECT_IS_IMPL, instance), fd_(fd) {} | 46 : Resource(ppapi::OBJECT_IS_IMPL, instance), fd_(fd) {} |
45 | 47 |
46 bool GetFontTable(uint32_t table, void* output, uint32_t* output_length) { | 48 bool GetFontTable(uint32_t table, void* output, uint32_t* output_length) { |
47 size_t temp_size = static_cast<size_t>(*output_length); | 49 size_t temp_size = static_cast<size_t>(*output_length); |
48 bool rv = content::GetFontTable( | 50 bool rv = content::GetFontTable( |
49 fd_.get(), table, 0 /* offset */, static_cast<uint8_t*>(output), | 51 fd_.get(), table, 0 /* offset */, static_cast<uint8_t*>(output), |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_6, IDR_PDF_PROGRESS_BAR_6}, | 114 {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_6, IDR_PDF_PROGRESS_BAR_6}, |
113 {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_7, IDR_PDF_PROGRESS_BAR_7}, | 115 {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_7, IDR_PDF_PROGRESS_BAR_7}, |
114 {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_8, IDR_PDF_PROGRESS_BAR_8}, | 116 {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_8, IDR_PDF_PROGRESS_BAR_8}, |
115 {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_BACKGROUND, | 117 {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_BACKGROUND, |
116 IDR_PDF_PROGRESS_BAR_BACKGROUND}, | 118 IDR_PDF_PROGRESS_BAR_BACKGROUND}, |
117 {PP_RESOURCEIMAGE_PDF_PAGE_INDICATOR_BACKGROUND, | 119 {PP_RESOURCEIMAGE_PDF_PAGE_INDICATOR_BACKGROUND, |
118 IDR_PDF_PAGE_INDICATOR_BACKGROUND}, | 120 IDR_PDF_PAGE_INDICATOR_BACKGROUND}, |
119 {PP_RESOURCEIMAGE_PDF_PAGE_DROPSHADOW, IDR_PDF_PAGE_DROPSHADOW}, | 121 {PP_RESOURCEIMAGE_PDF_PAGE_DROPSHADOW, IDR_PDF_PAGE_DROPSHADOW}, |
120 {PP_RESOURCEIMAGE_PDF_PAN_SCROLL_ICON, IDR_PAN_SCROLL_ICON}, }; | 122 {PP_RESOURCEIMAGE_PDF_PAN_SCROLL_ICON, IDR_PAN_SCROLL_ICON}, }; |
121 | 123 |
122 #if defined(ENABLE_FULL_PRINTING) | |
123 | |
124 blink::WebElement GetWebElement(PP_Instance instance_id) { | |
125 content::PepperPluginInstance* instance = | |
126 content::PepperPluginInstance::Get(instance_id); | |
127 if (!instance) | |
128 return blink::WebElement(); | |
129 return instance->GetContainer()->element(); | |
130 } | |
131 | |
132 printing::PrintWebViewHelper* GetPrintWebViewHelper( | |
133 const blink::WebElement& element) { | |
134 if (element.isNull()) | |
135 return NULL; | |
136 blink::WebView* view = element.document().frame()->view(); | |
137 content::RenderView* render_view = content::RenderView::FromWebView(view); | |
138 return printing::PrintWebViewHelper::Get(render_view); | |
139 } | |
140 | |
141 bool IsPrintingEnabled(PP_Instance instance_id) { | |
142 blink::WebElement element = GetWebElement(instance_id); | |
143 printing::PrintWebViewHelper* helper = GetPrintWebViewHelper(element); | |
144 return helper && helper->IsPrintingEnabled(); | |
145 } | |
146 | |
147 #else // ENABLE_FULL_PRINTING | |
148 | |
149 bool IsPrintingEnabled(PP_Instance instance_id) { return false; } | |
150 | |
151 #endif // ENABLE_FULL_PRINTING | |
152 | |
153 PP_Var GetLocalizedString(PP_Instance instance_id, | 124 PP_Var GetLocalizedString(PP_Instance instance_id, |
154 PP_ResourceString string_id) { | 125 PP_ResourceString string_id) { |
155 content::PepperPluginInstance* instance = | 126 content::PepperPluginInstance* instance = |
156 content::PepperPluginInstance::Get(instance_id); | 127 content::PepperPluginInstance::Get(instance_id); |
157 if (!instance) | 128 if (!instance) |
158 return PP_MakeUndefined(); | 129 return PP_MakeUndefined(); |
159 | 130 |
160 std::string rv; | 131 std::string rv; |
161 if (string_id == PP_RESOURCESTRING_PDFGETPASSWORD) { | 132 if (string_id == PP_RESOURCESTRING_PDFGETPASSWORD) { |
162 rv = base::UTF16ToUTF8(l10n_util::GetStringUTF16(IDS_PDF_NEED_PASSWORD)); | 133 rv = base::UTF16ToUTF8(l10n_util::GetStringUTF16(IDS_PDF_NEED_PASSWORD)); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 return; | 265 return; |
295 instance->GetRenderView()->DidStopLoading(); | 266 instance->GetRenderView()->DidStopLoading(); |
296 } | 267 } |
297 | 268 |
298 void SetContentRestriction(PP_Instance instance_id, int restrictions) { | 269 void SetContentRestriction(PP_Instance instance_id, int restrictions) { |
299 content::PepperPluginInstance* instance = | 270 content::PepperPluginInstance* instance = |
300 content::PepperPluginInstance::Get(instance_id); | 271 content::PepperPluginInstance::Get(instance_id); |
301 if (!instance) | 272 if (!instance) |
302 return; | 273 return; |
303 instance->GetRenderView()->Send( | 274 instance->GetRenderView()->Send( |
304 new ChromeViewHostMsg_PDFUpdateContentRestrictions( | 275 new PDFHostMsg_PDFUpdateContentRestrictions( |
305 instance->GetRenderView()->GetRoutingID(), restrictions)); | 276 instance->GetRenderView()->GetRoutingID(), restrictions)); |
306 } | 277 } |
307 | 278 |
308 void HistogramPDFPageCount(PP_Instance instance, int count) { | 279 void HistogramPDFPageCount(PP_Instance instance, int count) { |
309 UMA_HISTOGRAM_COUNTS_10000("PDF.PageCount", count); | 280 UMA_HISTOGRAM_COUNTS_10000("PDF.PageCount", count); |
310 } | 281 } |
311 | 282 |
312 void UserMetricsRecordAction(PP_Instance instance, PP_Var action) { | 283 void UserMetricsRecordAction(PP_Instance instance, PP_Var action) { |
313 scoped_refptr<ppapi::StringVar> action_str( | 284 scoped_refptr<ppapi::StringVar> action_str( |
314 ppapi::StringVar::FromPPVar(action)); | 285 ppapi::StringVar::FromPPVar(action)); |
315 if (action_str) | 286 if (action_str) |
316 content::RenderThread::Get()->RecordComputedAction(action_str->value()); | 287 content::RenderThread::Get()->RecordComputedAction(action_str->value()); |
317 } | 288 } |
318 | 289 |
319 void HasUnsupportedFeature(PP_Instance instance_id) { | 290 void HasUnsupportedFeature(PP_Instance instance_id) { |
320 content::PepperPluginInstance* instance = | 291 content::PepperPluginInstance* instance = |
321 content::PepperPluginInstance::Get(instance_id); | 292 content::PepperPluginInstance::Get(instance_id); |
322 if (!instance) | 293 if (!instance) |
323 return; | 294 return; |
324 | 295 |
325 // Only want to show an info bar if the pdf is the whole tab. | 296 // Only want to show an info bar if the pdf is the whole tab. |
326 if (!instance->IsFullPagePlugin()) | 297 if (!instance->IsFullPagePlugin()) |
327 return; | 298 return; |
328 | 299 |
329 blink::WebView* view = | 300 blink::WebView* view = |
330 instance->GetContainer()->element().document().frame()->view(); | 301 instance->GetContainer()->element().document().frame()->view(); |
331 content::RenderView* render_view = content::RenderView::FromWebView(view); | 302 content::RenderView* render_view = content::RenderView::FromWebView(view); |
332 render_view->Send(new ChromeViewHostMsg_PDFHasUnsupportedFeature( | 303 render_view->Send(new PDFHostMsg_PDFHasUnsupportedFeature( |
333 render_view->GetRoutingID())); | 304 render_view->GetRoutingID())); |
334 } | 305 } |
335 | 306 |
336 void SaveAs(PP_Instance instance_id) { | 307 void SaveAs(PP_Instance instance_id) { |
337 content::PepperPluginInstance* instance = | 308 content::PepperPluginInstance* instance = |
338 content::PepperPluginInstance::Get(instance_id); | 309 content::PepperPluginInstance::Get(instance_id); |
339 if (!instance) | 310 if (!instance) |
340 return; | 311 return; |
341 GURL url = instance->GetPluginURL(); | 312 GURL url = instance->GetPluginURL(); |
342 | 313 |
343 content::RenderView* render_view = instance->GetRenderView(); | 314 content::RenderView* render_view = instance->GetRenderView(); |
344 blink::WebLocalFrame* frame = | 315 blink::WebLocalFrame* frame = |
345 render_view->GetWebView()->mainFrame()->toWebLocalFrame(); | 316 render_view->GetWebView()->mainFrame()->toWebLocalFrame(); |
346 content::Referrer referrer(frame->document().url(), | 317 content::Referrer referrer(frame->document().url(), |
347 frame->document().referrerPolicy()); | 318 frame->document().referrerPolicy()); |
348 render_view->Send(new ChromeViewHostMsg_PDFSaveURLAs( | 319 render_view->Send(new PDFHostMsg_PDFSaveURLAs( |
349 render_view->GetRoutingID(), url, referrer)); | 320 render_view->GetRoutingID(), url, referrer)); |
350 } | 321 } |
351 | 322 |
352 PP_Bool IsFeatureEnabled(PP_Instance instance, PP_PDFFeature feature) { | 323 PP_Bool IsFeatureEnabled(PP_Instance instance, PP_PDFFeature feature) { |
353 switch (feature) { | 324 switch (feature) { |
354 case PP_PDFFEATURE_HIDPI: | 325 case PP_PDFFEATURE_HIDPI: |
355 return PP_TRUE; | 326 return PP_TRUE; |
356 case PP_PDFFEATURE_PRINTING: | 327 case PP_PDFFEATURE_PRINTING: |
357 return IsPrintingEnabled(instance) ? PP_TRUE : PP_FALSE; | 328 return (print_delegate && print_delegate->IsPrintingEnabled(instance)) |
329 ? PP_TRUE : PP_FALSE; | |
358 } | 330 } |
359 return PP_FALSE; | 331 return PP_FALSE; |
360 } | 332 } |
361 | 333 |
362 PP_Resource GetResourceImageForScale(PP_Instance instance_id, | 334 PP_Resource GetResourceImageForScale(PP_Instance instance_id, |
363 PP_ResourceImage image_id, | 335 PP_ResourceImage image_id, |
364 float scale) { | 336 float scale) { |
365 int res_id = 0; | 337 int res_id = 0; |
366 for (size_t i = 0; i < arraysize(kResourceImageMap); ++i) { | 338 for (size_t i = 0; i < arraysize(kResourceImageMap); ++i) { |
367 if (kResourceImageMap[i].pp_id == image_id) { | 339 if (kResourceImageMap[i].pp_id == image_id) { |
(...skipping 27 matching lines...) Expand all Loading... | |
395 PP_Var ModalPromptForPassword(PP_Instance instance_id, PP_Var message) { | 367 PP_Var ModalPromptForPassword(PP_Instance instance_id, PP_Var message) { |
396 content::PepperPluginInstance* instance = | 368 content::PepperPluginInstance* instance = |
397 content::PepperPluginInstance::Get(instance_id); | 369 content::PepperPluginInstance::Get(instance_id); |
398 if (!instance) | 370 if (!instance) |
399 return PP_MakeUndefined(); | 371 return PP_MakeUndefined(); |
400 | 372 |
401 std::string actual_value; | 373 std::string actual_value; |
402 scoped_refptr<ppapi::StringVar> message_string( | 374 scoped_refptr<ppapi::StringVar> message_string( |
403 ppapi::StringVar::FromPPVar(message)); | 375 ppapi::StringVar::FromPPVar(message)); |
404 | 376 |
405 IPC::SyncMessage* msg = new ChromeViewHostMsg_PDFModalPromptForPassword( | 377 IPC::SyncMessage* msg = new PDFHostMsg_PDFModalPromptForPassword( |
406 instance->GetRenderView()->GetRoutingID(), | 378 instance->GetRenderView()->GetRoutingID(), |
407 message_string->value(), | 379 message_string->value(), |
408 &actual_value); | 380 &actual_value); |
409 msg->EnableMessagePumping(); | 381 msg->EnableMessagePumping(); |
410 instance->GetRenderView()->Send(msg); | 382 instance->GetRenderView()->Send(msg); |
411 | 383 |
412 return ppapi::StringVar::StringToPPVar(actual_value); | 384 return ppapi::StringVar::StringToPPVar(actual_value); |
413 } | 385 } |
414 | 386 |
415 PP_Bool IsOutOfProcess(PP_Instance instance_id) { return PP_FALSE; } | 387 PP_Bool IsOutOfProcess(PP_Instance instance_id) { return PP_FALSE; } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
448 &SetLinkUnderCursor, // | 420 &SetLinkUnderCursor, // |
449 }; | 421 }; |
450 | 422 |
451 } // namespace | 423 } // namespace |
452 | 424 |
453 // static | 425 // static |
454 const PPB_PDF* PPB_PDF_Impl::GetInterface() { return &ppb_pdf; } | 426 const PPB_PDF* PPB_PDF_Impl::GetInterface() { return &ppb_pdf; } |
455 | 427 |
456 // static | 428 // static |
457 void PPB_PDF_Impl::InvokePrintingForInstance(PP_Instance instance_id) { | 429 void PPB_PDF_Impl::InvokePrintingForInstance(PP_Instance instance_id) { |
458 #if defined(ENABLE_FULL_PRINTING) | 430 if (print_delegate) |
459 blink::WebElement element = GetWebElement(instance_id); | 431 print_delegate->Print(instance_id); |
460 printing::PrintWebViewHelper* helper = GetPrintWebViewHelper(element); | |
461 if (helper) | |
462 helper->PrintNode(element); | |
463 #endif // ENABLE_FULL_PRINTING | |
464 } | 432 } |
433 | |
434 void PPB_PDF_Impl::SetPrintDelegate(PPB_PDF_Impl::PrintDelegate* delegate) { | |
435 CHECK(!print_delegate) << "There should only be a single PrintDelegate."; | |
436 print_delegate = delegate; | |
437 } | |
438 | |
439 } // namespace pdf | |
OLD | NEW |