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

Side by Side Diff: components/pdf/renderer/ppb_pdf_impl.cc

Issue 506473003: pdf: Move the string/image resources for the pdf plugin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pdf-host-component
Patch Set: Created 6 years, 3 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
OLDNEW
1 // Copyright 2014 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 "components/pdf/renderer/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"
11 #include "build/build_config.h" 10 #include "build/build_config.h"
12 #include "components/pdf/common/pdf_messages.h" 11 #include "components/pdf/common/pdf_messages.h"
13 #include "content/app/resources/grit/content_resources.h" 12 #include "components/pdf/renderer/pdf_resource_util.h"
14 #include "content/app/strings/grit/content_strings.h"
15 #include "content/public/common/child_process_sandbox_support_linux.h" 13 #include "content/public/common/child_process_sandbox_support_linux.h"
16 #include "content/public/common/referrer.h" 14 #include "content/public/common/referrer.h"
17 #include "content/public/renderer/pepper_plugin_instance.h" 15 #include "content/public/renderer/pepper_plugin_instance.h"
18 #include "content/public/renderer/render_thread.h" 16 #include "content/public/renderer/render_thread.h"
19 #include "content/public/renderer/render_view.h" 17 #include "content/public/renderer/render_view.h"
20 #include "ppapi/c/pp_resource.h" 18 #include "ppapi/c/pp_resource.h"
21 #include "ppapi/c/private/ppb_pdf.h" 19 #include "ppapi/c/private/ppb_pdf.h"
22 #include "ppapi/c/trusted/ppb_browser_font_trusted.h" 20 #include "ppapi/c/trusted/ppb_browser_font_trusted.h"
23 #include "ppapi/shared_impl/ppapi_globals.h" 21 #include "ppapi/shared_impl/ppapi_globals.h"
24 #include "ppapi/shared_impl/resource.h" 22 #include "ppapi/shared_impl/resource.h"
25 #include "ppapi/shared_impl/resource_tracker.h" 23 #include "ppapi/shared_impl/resource_tracker.h"
26 #include "ppapi/shared_impl/var.h" 24 #include "ppapi/shared_impl/var.h"
27 #include "third_party/WebKit/public/web/WebDocument.h" 25 #include "third_party/WebKit/public/web/WebDocument.h"
28 #include "third_party/WebKit/public/web/WebElement.h" 26 #include "third_party/WebKit/public/web/WebElement.h"
29 #include "third_party/WebKit/public/web/WebLocalFrame.h" 27 #include "third_party/WebKit/public/web/WebLocalFrame.h"
30 #include "third_party/WebKit/public/web/WebPluginContainer.h" 28 #include "third_party/WebKit/public/web/WebPluginContainer.h"
31 #include "third_party/WebKit/public/web/WebView.h" 29 #include "third_party/WebKit/public/web/WebView.h"
32 #include "third_party/icu/source/i18n/unicode/usearch.h" 30 #include "third_party/icu/source/i18n/unicode/usearch.h"
33 #include "third_party/skia/include/core/SkBitmap.h" 31 #include "third_party/skia/include/core/SkBitmap.h"
34 #include "ui/base/l10n/l10n_util.h"
35 #include "ui/base/resource/resource_bundle.h"
36 32
37 namespace pdf { 33 namespace pdf {
38 namespace { 34 namespace {
39 35
40 PPB_PDF_Impl::PrintDelegate* print_delegate = NULL; 36 PPB_PDF_Impl::PrintDelegate* print_delegate = NULL;
41 37
42 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) 38 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
43 class PrivateFontFile : public ppapi::Resource { 39 class PrivateFontFile : public ppapi::Resource {
44 public: 40 public:
45 PrivateFontFile(PP_Instance instance, int fd) 41 PrivateFontFile(PP_Instance instance, int fd)
(...skipping 11 matching lines...) Expand all
57 } 53 }
58 54
59 protected: 55 protected:
60 virtual ~PrivateFontFile() {} 56 virtual ~PrivateFontFile() {}
61 57
62 private: 58 private:
63 base::ScopedFD fd_; 59 base::ScopedFD fd_;
64 }; 60 };
65 #endif 61 #endif
66 62
67 struct ResourceImageInfo {
68 PP_ResourceImage pp_id;
69 int res_id;
70 };
71
72 static const ResourceImageInfo kResourceImageMap[] = {
73 {PP_RESOURCEIMAGE_PDF_BUTTON_FTP, IDR_PDF_BUTTON_FTP},
74 {PP_RESOURCEIMAGE_PDF_BUTTON_FTP_HOVER, IDR_PDF_BUTTON_FTP_HOVER},
75 {PP_RESOURCEIMAGE_PDF_BUTTON_FTP_PRESSED, IDR_PDF_BUTTON_FTP_PRESSED},
76 {PP_RESOURCEIMAGE_PDF_BUTTON_FTW, IDR_PDF_BUTTON_FTW},
77 {PP_RESOURCEIMAGE_PDF_BUTTON_FTW_HOVER, IDR_PDF_BUTTON_FTW_HOVER},
78 {PP_RESOURCEIMAGE_PDF_BUTTON_FTW_PRESSED, IDR_PDF_BUTTON_FTW_PRESSED},
79 {PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN_END, IDR_PDF_BUTTON_ZOOMIN_END},
80 {PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN_END_HOVER,
81 IDR_PDF_BUTTON_ZOOMIN_END_HOVER},
82 {PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN_END_PRESSED,
83 IDR_PDF_BUTTON_ZOOMIN_END_PRESSED},
84 {PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN, IDR_PDF_BUTTON_ZOOMIN},
85 {PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN_HOVER, IDR_PDF_BUTTON_ZOOMIN_HOVER},
86 {PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN_PRESSED, IDR_PDF_BUTTON_ZOOMIN_PRESSED},
87 {PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMOUT, IDR_PDF_BUTTON_ZOOMOUT},
88 {PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMOUT_HOVER, IDR_PDF_BUTTON_ZOOMOUT_HOVER},
89 {PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMOUT_PRESSED,
90 IDR_PDF_BUTTON_ZOOMOUT_PRESSED},
91 {PP_RESOURCEIMAGE_PDF_BUTTON_SAVE, IDR_PDF_BUTTON_SAVE},
92 {PP_RESOURCEIMAGE_PDF_BUTTON_SAVE_HOVER, IDR_PDF_BUTTON_SAVE_HOVER},
93 {PP_RESOURCEIMAGE_PDF_BUTTON_SAVE_PRESSED, IDR_PDF_BUTTON_SAVE_PRESSED},
94 {PP_RESOURCEIMAGE_PDF_BUTTON_PRINT, IDR_PDF_BUTTON_PRINT},
95 {PP_RESOURCEIMAGE_PDF_BUTTON_PRINT_HOVER, IDR_PDF_BUTTON_PRINT_HOVER},
96 {PP_RESOURCEIMAGE_PDF_BUTTON_PRINT_PRESSED, IDR_PDF_BUTTON_PRINT_PRESSED},
97 {PP_RESOURCEIMAGE_PDF_BUTTON_PRINT_DISABLED, IDR_PDF_BUTTON_PRINT_DISABLED},
98 {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_0, IDR_PDF_THUMBNAIL_0},
99 {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_1, IDR_PDF_THUMBNAIL_1},
100 {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_2, IDR_PDF_THUMBNAIL_2},
101 {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_3, IDR_PDF_THUMBNAIL_3},
102 {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_4, IDR_PDF_THUMBNAIL_4},
103 {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_5, IDR_PDF_THUMBNAIL_5},
104 {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_6, IDR_PDF_THUMBNAIL_6},
105 {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_7, IDR_PDF_THUMBNAIL_7},
106 {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_8, IDR_PDF_THUMBNAIL_8},
107 {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_9, IDR_PDF_THUMBNAIL_9},
108 {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_NUM_BACKGROUND,
109 IDR_PDF_THUMBNAIL_NUM_BACKGROUND},
110 {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_0, IDR_PDF_PROGRESS_BAR_0},
111 {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_1, IDR_PDF_PROGRESS_BAR_1},
112 {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_2, IDR_PDF_PROGRESS_BAR_2},
113 {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_3, IDR_PDF_PROGRESS_BAR_3},
114 {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_4, IDR_PDF_PROGRESS_BAR_4},
115 {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_5, IDR_PDF_PROGRESS_BAR_5},
116 {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_6, IDR_PDF_PROGRESS_BAR_6},
117 {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_7, IDR_PDF_PROGRESS_BAR_7},
118 {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_8, IDR_PDF_PROGRESS_BAR_8},
119 {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_BACKGROUND,
120 IDR_PDF_PROGRESS_BAR_BACKGROUND},
121 {PP_RESOURCEIMAGE_PDF_PAGE_INDICATOR_BACKGROUND,
122 IDR_PDF_PAGE_INDICATOR_BACKGROUND},
123 {PP_RESOURCEIMAGE_PDF_PAGE_DROPSHADOW, IDR_PDF_PAGE_DROPSHADOW},
124 {PP_RESOURCEIMAGE_PDF_PAN_SCROLL_ICON, IDR_PAN_SCROLL_ICON},
125 };
126
127 PP_Var GetLocalizedString(PP_Instance instance_id, 63 PP_Var GetLocalizedString(PP_Instance instance_id,
128 PP_ResourceString string_id) { 64 PP_ResourceString string_id) {
129 content::PepperPluginInstance* instance = 65 content::PepperPluginInstance* instance =
130 content::PepperPluginInstance::Get(instance_id); 66 content::PepperPluginInstance::Get(instance_id);
131 if (!instance) 67 if (!instance)
132 return PP_MakeUndefined(); 68 return PP_MakeUndefined();
133 69
134 std::string rv; 70 std::string rv = GetStringResource(string_id);
135 if (string_id == PP_RESOURCESTRING_PDFGETPASSWORD) {
136 rv = base::UTF16ToUTF8(l10n_util::GetStringUTF16(IDS_PDF_NEED_PASSWORD));
137 } else if (string_id == PP_RESOURCESTRING_PDFLOADING) {
138 rv = base::UTF16ToUTF8(l10n_util::GetStringUTF16(IDS_PDF_PAGE_LOADING));
139 } else if (string_id == PP_RESOURCESTRING_PDFLOAD_FAILED) {
140 rv = base::UTF16ToUTF8(l10n_util::GetStringUTF16(IDS_PDF_PAGE_LOAD_FAILED));
141 } else if (string_id == PP_RESOURCESTRING_PDFPROGRESSLOADING) {
142 rv = base::UTF16ToUTF8(l10n_util::GetStringUTF16(IDS_PDF_PROGRESS_LOADING));
143 } else {
144 NOTREACHED();
145 }
146
147 return ppapi::StringVar::StringToPPVar(rv); 71 return ppapi::StringVar::StringToPPVar(rv);
148 } 72 }
149 73
150 PP_Resource GetFontFileWithFallback( 74 PP_Resource GetFontFileWithFallback(
151 PP_Instance instance_id, 75 PP_Instance instance_id,
152 const PP_BrowserFont_Trusted_Description* description, 76 const PP_BrowserFont_Trusted_Description* description,
153 PP_PrivateFontCharset charset) { 77 PP_PrivateFontCharset charset) {
154 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) 78 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
155 // Validate the instance before using it below. 79 // Validate the instance before using it below.
156 if (!content::PepperPluginInstance::Get(instance_id)) 80 if (!content::PepperPluginInstance::Get(instance_id))
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 return (print_delegate && print_delegate->IsPrintingEnabled(instance)) 258 return (print_delegate && print_delegate->IsPrintingEnabled(instance))
335 ? PP_TRUE 259 ? PP_TRUE
336 : PP_FALSE; 260 : PP_FALSE;
337 } 261 }
338 return PP_FALSE; 262 return PP_FALSE;
339 } 263 }
340 264
341 PP_Resource GetResourceImageForScale(PP_Instance instance_id, 265 PP_Resource GetResourceImageForScale(PP_Instance instance_id,
342 PP_ResourceImage image_id, 266 PP_ResourceImage image_id,
343 float scale) { 267 float scale) {
344 int res_id = 0;
345 for (size_t i = 0; i < arraysize(kResourceImageMap); ++i) {
346 if (kResourceImageMap[i].pp_id == image_id) {
347 res_id = kResourceImageMap[i].res_id;
348 break;
349 }
350 }
351 if (res_id == 0)
352 return 0;
353
354 // Validate the instance. 268 // Validate the instance.
355 content::PepperPluginInstance* instance = 269 content::PepperPluginInstance* instance =
356 content::PepperPluginInstance::Get(instance_id); 270 content::PepperPluginInstance::Get(instance_id);
357 if (!instance) 271 if (!instance)
358 return 0; 272 return 0;
359 273
360 gfx::ImageSkia* res_image_skia = 274 gfx::ImageSkia* res_image_skia = GetImageResource(image_id);
361 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(res_id);
362 275
363 if (!res_image_skia) 276 if (!res_image_skia)
364 return 0; 277 return 0;
365 278
366 return instance->CreateImage(res_image_skia, scale); 279 return instance->CreateImage(res_image_skia, scale);
367 } 280 }
368 281
369 PP_Resource GetResourceImage(PP_Instance instance_id, 282 PP_Resource GetResourceImage(PP_Instance instance_id,
370 PP_ResourceImage image_id) { 283 PP_ResourceImage image_id) {
371 return GetResourceImageForScale(instance_id, image_id, 1.0f); 284 return GetResourceImageForScale(instance_id, image_id, 1.0f);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 bool PPB_PDF_Impl::InvokePrintingForInstance(PP_Instance instance_id) { 353 bool PPB_PDF_Impl::InvokePrintingForInstance(PP_Instance instance_id) {
441 return print_delegate ? print_delegate->Print(instance_id) : false; 354 return print_delegate ? print_delegate->Print(instance_id) : false;
442 } 355 }
443 356
444 void PPB_PDF_Impl::SetPrintDelegate(PPB_PDF_Impl::PrintDelegate* delegate) { 357 void PPB_PDF_Impl::SetPrintDelegate(PPB_PDF_Impl::PrintDelegate* delegate) {
445 CHECK(!print_delegate) << "There should only be a single PrintDelegate."; 358 CHECK(!print_delegate) << "There should only be a single PrintDelegate.";
446 print_delegate = delegate; 359 print_delegate = delegate;
447 } 360 }
448 361
449 } // namespace pdf 362 } // namespace pdf
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698