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

Side by Side Diff: chrome/renderer/pepper/ppb_pdf_impl.cc

Issue 10836055: Add PPB_PDF API to load scaled image resources (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months 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 | « no previous file | ppapi/c/private/ppb_pdf.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 "chrome/renderer/pepper/ppb_pdf_impl.h" 5 #include "chrome/renderer/pepper/ppb_pdf_impl.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 11 matching lines...) Expand all
22 #include "ppapi/shared_impl/resource.h" 22 #include "ppapi/shared_impl/resource.h"
23 #include "ppapi/shared_impl/resource_tracker.h" 23 #include "ppapi/shared_impl/resource_tracker.h"
24 #include "ppapi/shared_impl/var.h" 24 #include "ppapi/shared_impl/var.h"
25 #include "skia/ext/platform_canvas.h" 25 #include "skia/ext/platform_canvas.h"
26 #include "third_party/skia/include/core/SkBitmap.h" 26 #include "third_party/skia/include/core/SkBitmap.h"
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
31 #include "ui/base/l10n/l10n_util.h" 31 #include "ui/base/l10n/l10n_util.h"
32 #include "ui/base/layout.h"
32 #include "ui/base/resource/resource_bundle.h" 33 #include "ui/base/resource/resource_bundle.h"
34 #include "ui/gfx/image/image_skia.h"
35 #include "ui/gfx/image/image_skia_rep.h"
33 #include "unicode/usearch.h" 36 #include "unicode/usearch.h"
34 #include "webkit/plugins/ppapi/host_globals.h" 37 #include "webkit/plugins/ppapi/host_globals.h"
35 #include "webkit/plugins/ppapi/plugin_delegate.h" 38 #include "webkit/plugins/ppapi/plugin_delegate.h"
36 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 39 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
37 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" 40 #include "webkit/plugins/ppapi/ppb_image_data_impl.h"
38 41
39 using ppapi::PpapiGlobals; 42 using ppapi::PpapiGlobals;
40 using webkit::ppapi::HostGlobals; 43 using webkit::ppapi::HostGlobals;
41 using webkit::ppapi::PluginInstance; 44 using webkit::ppapi::PluginInstance;
42 using WebKit::WebElement; 45 using WebKit::WebElement;
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 switch (feature) { 359 switch (feature) {
357 case PP_PDFFEATURE_HIDPI: 360 case PP_PDFFEATURE_HIDPI:
358 if (CommandLine::ForCurrentProcess()->HasSwitch( 361 if (CommandLine::ForCurrentProcess()->HasSwitch(
359 switches::kEnableHighDPIPDFPlugin)) 362 switches::kEnableHighDPIPDFPlugin))
360 result = PP_TRUE; 363 result = PP_TRUE;
361 break; 364 break;
362 } 365 }
363 return result; 366 return result;
364 } 367 }
365 368
369 PP_Resource GetResourceImageForScale(PP_Instance instance_id,
brettw 2012/08/01 21:20:51 This is mostly copied fromGetResourceImage. I wond
Josh Horwich 2012/08/01 21:53:52 Done.
370 PP_ResourceImage image_id,
371 float scale) {
372 int res_id = 0;
373 for (size_t i = 0; i < arraysize(kResourceImageMap); ++i) {
374 if (kResourceImageMap[i].pp_id == image_id) {
375 res_id = kResourceImageMap[i].res_id;
376 break;
377 }
378 }
379 if (res_id == 0)
380 return 0;
381
382 ui::ScaleFactor scale_factor = ui::GetScaleFactorFromScale(scale);
383
384 gfx::ImageSkia* res_image_skia =
385 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(res_id);
386
387 if (!res_image_skia)
388 return 0;
389
390 // Validate the instance.
391 if (!content::GetHostGlobals()->GetInstance(instance_id))
392 return 0;
393
394 if (!res_image_skia->HasRepresentation(scale_factor))
395 return 0;
396
397 gfx::ImageSkiaRep image_skia_rep = res_image_skia->GetRepresentation(
398 scale_factor);
399
400 scoped_refptr<webkit::ppapi::PPB_ImageData_Impl> image_data(
401 new webkit::ppapi::PPB_ImageData_Impl(
402 instance_id,
403 webkit::ppapi::PPB_ImageData_Impl::PLATFORM));
404 if (!image_data->Init(
405 webkit::ppapi::PPB_ImageData_Impl::GetNativeImageDataFormat(),
406 image_skia_rep.pixel_width(),
407 image_skia_rep.pixel_height(),
408 false)) {
409 return 0;
410 }
411
412 webkit::ppapi::ImageDataAutoMapper mapper(image_data);
413 if (!mapper.is_valid())
414 return 0;
415
416 skia::PlatformCanvas* canvas = image_data->GetPlatformCanvas();
417 // Note: Do not skBitmap::copyTo the canvas bitmap directly because it will
418 // ignore the allocated pixels in shared memory and re-allocate a new buffer.
419 canvas->writePixels(image_skia_rep.sk_bitmap(), 0, 0);
420
421 return image_data->GetReference();
422 }
423
366 const PPB_PDF ppb_pdf = { 424 const PPB_PDF ppb_pdf = {
367 &GetLocalizedString, 425 &GetLocalizedString,
368 &GetResourceImage, 426 &GetResourceImage,
369 &GetFontFileWithFallback, 427 &GetFontFileWithFallback,
370 &GetFontTableForPrivateFontFile, 428 &GetFontTableForPrivateFontFile,
371 &SearchString, 429 &SearchString,
372 &DidStartLoading, 430 &DidStartLoading,
373 &DidStopLoading, 431 &DidStopLoading,
374 &SetContentRestriction, 432 &SetContentRestriction,
375 &HistogramPDFPageCount, 433 &HistogramPDFPageCount,
376 &UserMetricsRecordAction, 434 &UserMetricsRecordAction,
377 &HasUnsupportedFeature, 435 &HasUnsupportedFeature,
378 &SaveAs, 436 &SaveAs,
379 &PPB_PDF_Impl::InvokePrintingForInstance, 437 &PPB_PDF_Impl::InvokePrintingForInstance,
380 &IsFeatureEnabled 438 &IsFeatureEnabled,
439 &GetResourceImageForScale
381 }; 440 };
382 441
383 } // namespace 442 } // namespace
384 443
385 // static 444 // static
386 const PPB_PDF* PPB_PDF_Impl::GetInterface() { 445 const PPB_PDF* PPB_PDF_Impl::GetInterface() {
387 return &ppb_pdf; 446 return &ppb_pdf;
388 } 447 }
389 448
390 // static 449 // static
391 void PPB_PDF_Impl::InvokePrintingForInstance(PP_Instance instance_id) { 450 void PPB_PDF_Impl::InvokePrintingForInstance(PP_Instance instance_id) {
392 #if defined(ENABLE_PRINTING) 451 #if defined(ENABLE_PRINTING)
393 PluginInstance* instance = HostGlobals::Get()->GetInstance(instance_id); 452 PluginInstance* instance = HostGlobals::Get()->GetInstance(instance_id);
394 if (!instance) 453 if (!instance)
395 return; 454 return;
396 455
397 WebKit::WebElement element = instance->container()->element(); 456 WebKit::WebElement element = instance->container()->element();
398 WebKit::WebView* view = element.document().frame()->view(); 457 WebKit::WebView* view = element.document().frame()->view();
399 content::RenderView* render_view = content::RenderView::FromWebView(view); 458 content::RenderView* render_view = content::RenderView::FromWebView(view);
400 459
401 PrintWebViewHelper* print_view_helper = PrintWebViewHelper::Get(render_view); 460 PrintWebViewHelper* print_view_helper = PrintWebViewHelper::Get(render_view);
402 if (print_view_helper) 461 if (print_view_helper)
403 print_view_helper->PrintNode(element); 462 print_view_helper->PrintNode(element);
404 #endif 463 #endif
405 } 464 }
OLDNEW
« no previous file with comments | « no previous file | ppapi/c/private/ppb_pdf.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698