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

Side by Side Diff: components/pdf/renderer/pepper_pdf_host.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/pepper_pdf_host.h" 5 #include "components/pdf/renderer/pepper_pdf_host.h"
6 6
7 #include "base/strings/utf_string_conversions.h"
8 #include "components/pdf/common/pdf_messages.h" 7 #include "components/pdf/common/pdf_messages.h"
8 #include "components/pdf/renderer/pdf_resource_util.h"
9 #include "components/pdf/renderer/ppb_pdf_impl.h" 9 #include "components/pdf/renderer/ppb_pdf_impl.h"
10 #include "content/app/resources/grit/content_resources.h"
11 #include "content/app/strings/grit/content_strings.h"
12 #include "content/public/common/referrer.h" 10 #include "content/public/common/referrer.h"
13 #include "content/public/renderer/pepper_plugin_instance.h" 11 #include "content/public/renderer/pepper_plugin_instance.h"
14 #include "content/public/renderer/render_thread.h" 12 #include "content/public/renderer/render_thread.h"
15 #include "content/public/renderer/render_view.h" 13 #include "content/public/renderer/render_view.h"
16 #include "content/public/renderer/renderer_ppapi_host.h" 14 #include "content/public/renderer/renderer_ppapi_host.h"
17 #include "ppapi/host/dispatch_host_message.h" 15 #include "ppapi/host/dispatch_host_message.h"
18 #include "ppapi/host/host_message_context.h" 16 #include "ppapi/host/host_message_context.h"
19 #include "ppapi/host/ppapi_host.h" 17 #include "ppapi/host/ppapi_host.h"
20 #include "ppapi/proxy/host_dispatcher.h" 18 #include "ppapi/proxy/host_dispatcher.h"
21 #include "ppapi/proxy/ppapi_messages.h" 19 #include "ppapi/proxy/ppapi_messages.h"
22 #include "ppapi/proxy/ppb_image_data_proxy.h" 20 #include "ppapi/proxy/ppb_image_data_proxy.h"
23 #include "ppapi/shared_impl/ppb_image_data_shared.h" 21 #include "ppapi/shared_impl/ppb_image_data_shared.h"
24 #include "ppapi/shared_impl/scoped_pp_resource.h" 22 #include "ppapi/shared_impl/scoped_pp_resource.h"
25 #include "ppapi/thunk/enter.h" 23 #include "ppapi/thunk/enter.h"
26 #include "ppapi/thunk/ppb_image_data_api.h" 24 #include "ppapi/thunk/ppb_image_data_api.h"
27 #include "skia/ext/platform_canvas.h" 25 #include "skia/ext/platform_canvas.h"
28 #include "third_party/WebKit/public/web/WebDocument.h" 26 #include "third_party/WebKit/public/web/WebDocument.h"
29 #include "third_party/WebKit/public/web/WebElement.h" 27 #include "third_party/WebKit/public/web/WebElement.h"
30 #include "third_party/WebKit/public/web/WebLocalFrame.h" 28 #include "third_party/WebKit/public/web/WebLocalFrame.h"
31 #include "third_party/WebKit/public/web/WebPluginContainer.h" 29 #include "third_party/WebKit/public/web/WebPluginContainer.h"
32 #include "third_party/WebKit/public/web/WebView.h" 30 #include "third_party/WebKit/public/web/WebView.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/layout.h" 32 #include "ui/base/layout.h"
36 #include "ui/base/resource/resource_bundle.h"
37 #include "ui/gfx/image/image_skia.h" 33 #include "ui/gfx/image/image_skia.h"
38 #include "ui/gfx/image/image_skia_rep.h" 34 #include "ui/gfx/image/image_skia_rep.h"
39 #include "ui/gfx/point.h" 35 #include "ui/gfx/point.h"
40 36
41 namespace {
42
43 struct ResourceImageInfo {
44 PP_ResourceImage pp_id;
45 int res_id;
46 };
47
48 const ResourceImageInfo kResourceImageMap[] = {
49 {PP_RESOURCEIMAGE_PDF_BUTTON_FTP, IDR_PDF_BUTTON_FTP},
50 {PP_RESOURCEIMAGE_PDF_BUTTON_FTP_HOVER, IDR_PDF_BUTTON_FTP_HOVER},
51 {PP_RESOURCEIMAGE_PDF_BUTTON_FTP_PRESSED, IDR_PDF_BUTTON_FTP_PRESSED},
52 {PP_RESOURCEIMAGE_PDF_BUTTON_FTW, IDR_PDF_BUTTON_FTW},
53 {PP_RESOURCEIMAGE_PDF_BUTTON_FTW_HOVER, IDR_PDF_BUTTON_FTW_HOVER},
54 {PP_RESOURCEIMAGE_PDF_BUTTON_FTW_PRESSED, IDR_PDF_BUTTON_FTW_PRESSED},
55 {PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN_END, IDR_PDF_BUTTON_ZOOMIN_END},
56 {PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN_END_HOVER,
57 IDR_PDF_BUTTON_ZOOMIN_END_HOVER},
58 {PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN_END_PRESSED,
59 IDR_PDF_BUTTON_ZOOMIN_END_PRESSED},
60 {PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN, IDR_PDF_BUTTON_ZOOMIN},
61 {PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN_HOVER, IDR_PDF_BUTTON_ZOOMIN_HOVER},
62 {PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN_PRESSED, IDR_PDF_BUTTON_ZOOMIN_PRESSED},
63 {PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMOUT, IDR_PDF_BUTTON_ZOOMOUT},
64 {PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMOUT_HOVER, IDR_PDF_BUTTON_ZOOMOUT_HOVER},
65 {PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMOUT_PRESSED,
66 IDR_PDF_BUTTON_ZOOMOUT_PRESSED},
67 {PP_RESOURCEIMAGE_PDF_BUTTON_SAVE, IDR_PDF_BUTTON_SAVE},
68 {PP_RESOURCEIMAGE_PDF_BUTTON_SAVE_HOVER, IDR_PDF_BUTTON_SAVE_HOVER},
69 {PP_RESOURCEIMAGE_PDF_BUTTON_SAVE_PRESSED, IDR_PDF_BUTTON_SAVE_PRESSED},
70 {PP_RESOURCEIMAGE_PDF_BUTTON_PRINT, IDR_PDF_BUTTON_PRINT},
71 {PP_RESOURCEIMAGE_PDF_BUTTON_PRINT_HOVER, IDR_PDF_BUTTON_PRINT_HOVER},
72 {PP_RESOURCEIMAGE_PDF_BUTTON_PRINT_PRESSED, IDR_PDF_BUTTON_PRINT_PRESSED},
73 {PP_RESOURCEIMAGE_PDF_BUTTON_PRINT_DISABLED, IDR_PDF_BUTTON_PRINT_DISABLED},
74 {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_0, IDR_PDF_THUMBNAIL_0},
75 {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_1, IDR_PDF_THUMBNAIL_1},
76 {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_2, IDR_PDF_THUMBNAIL_2},
77 {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_3, IDR_PDF_THUMBNAIL_3},
78 {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_4, IDR_PDF_THUMBNAIL_4},
79 {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_5, IDR_PDF_THUMBNAIL_5},
80 {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_6, IDR_PDF_THUMBNAIL_6},
81 {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_7, IDR_PDF_THUMBNAIL_7},
82 {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_8, IDR_PDF_THUMBNAIL_8},
83 {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_9, IDR_PDF_THUMBNAIL_9},
84 {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_NUM_BACKGROUND,
85 IDR_PDF_THUMBNAIL_NUM_BACKGROUND},
86 {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_0, IDR_PDF_PROGRESS_BAR_0},
87 {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_1, IDR_PDF_PROGRESS_BAR_1},
88 {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_2, IDR_PDF_PROGRESS_BAR_2},
89 {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_3, IDR_PDF_PROGRESS_BAR_3},
90 {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_4, IDR_PDF_PROGRESS_BAR_4},
91 {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_5, IDR_PDF_PROGRESS_BAR_5},
92 {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_6, IDR_PDF_PROGRESS_BAR_6},
93 {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_7, IDR_PDF_PROGRESS_BAR_7},
94 {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_8, IDR_PDF_PROGRESS_BAR_8},
95 {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_BACKGROUND,
96 IDR_PDF_PROGRESS_BAR_BACKGROUND},
97 {PP_RESOURCEIMAGE_PDF_PAGE_INDICATOR_BACKGROUND,
98 IDR_PDF_PAGE_INDICATOR_BACKGROUND},
99 {PP_RESOURCEIMAGE_PDF_PAGE_DROPSHADOW, IDR_PDF_PAGE_DROPSHADOW},
100 {PP_RESOURCEIMAGE_PDF_PAN_SCROLL_ICON, IDR_PAN_SCROLL_ICON}, };
101
102 } // namespace
103
104 namespace pdf { 37 namespace pdf {
105 38
106 PepperPDFHost::PepperPDFHost(content::RendererPpapiHost* host, 39 PepperPDFHost::PepperPDFHost(content::RendererPpapiHost* host,
107 PP_Instance instance, 40 PP_Instance instance,
108 PP_Resource resource) 41 PP_Resource resource)
109 : ppapi::host::ResourceHost(host->GetPpapiHost(), instance, resource), 42 : ppapi::host::ResourceHost(host->GetPpapiHost(), instance, resource),
110 host_(host) {} 43 host_(host) {}
111 44
112 PepperPDFHost::~PepperPDFHost() {} 45 PepperPDFHost::~PepperPDFHost() {}
113 46
(...skipping 20 matching lines...) Expand all
134 OnHostMsgSetSelectedText) 67 OnHostMsgSetSelectedText)
135 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_PDF_SetLinkUnderCursor, 68 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_PDF_SetLinkUnderCursor,
136 OnHostMsgSetLinkUnderCursor) 69 OnHostMsgSetLinkUnderCursor)
137 PPAPI_END_MESSAGE_MAP() 70 PPAPI_END_MESSAGE_MAP()
138 return PP_ERROR_FAILED; 71 return PP_ERROR_FAILED;
139 } 72 }
140 73
141 int32_t PepperPDFHost::OnHostMsgGetLocalizedString( 74 int32_t PepperPDFHost::OnHostMsgGetLocalizedString(
142 ppapi::host::HostMessageContext* context, 75 ppapi::host::HostMessageContext* context,
143 PP_ResourceString string_id) { 76 PP_ResourceString string_id) {
144 std::string rv; 77 std::string rv = GetStringResource(string_id);
145 if (string_id == PP_RESOURCESTRING_PDFGETPASSWORD) {
146 rv = base::UTF16ToUTF8(l10n_util::GetStringUTF16(IDS_PDF_NEED_PASSWORD));
147 } else if (string_id == PP_RESOURCESTRING_PDFLOADING) {
148 rv = base::UTF16ToUTF8(l10n_util::GetStringUTF16(IDS_PDF_PAGE_LOADING));
149 } else if (string_id == PP_RESOURCESTRING_PDFLOAD_FAILED) {
150 rv = base::UTF16ToUTF8(l10n_util::GetStringUTF16(IDS_PDF_PAGE_LOAD_FAILED));
151 } else if (string_id == PP_RESOURCESTRING_PDFPROGRESSLOADING) {
152 rv = base::UTF16ToUTF8(l10n_util::GetStringUTF16(IDS_PDF_PROGRESS_LOADING));
153 } else {
154 NOTREACHED();
155 return PP_ERROR_FAILED;
156 }
157
158 context->reply_msg = PpapiPluginMsg_PDF_GetLocalizedStringReply(rv); 78 context->reply_msg = PpapiPluginMsg_PDF_GetLocalizedStringReply(rv);
159 return PP_OK; 79 return PP_OK;
160 } 80 }
161 81
162 int32_t PepperPDFHost::OnHostMsgDidStartLoading( 82 int32_t PepperPDFHost::OnHostMsgDidStartLoading(
163 ppapi::host::HostMessageContext* context) { 83 ppapi::host::HostMessageContext* context) {
164 content::PepperPluginInstance* instance = 84 content::PepperPluginInstance* instance =
165 host_->GetPluginInstance(pp_instance()); 85 host_->GetPluginInstance(pp_instance());
166 if (!instance) 86 if (!instance)
167 return PP_ERROR_FAILED; 87 return PP_ERROR_FAILED;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 frame->document().referrerPolicy()); 155 frame->document().referrerPolicy());
236 render_view->Send( 156 render_view->Send(
237 new PDFHostMsg_PDFSaveURLAs(render_view->GetRoutingID(), url, referrer)); 157 new PDFHostMsg_PDFSaveURLAs(render_view->GetRoutingID(), url, referrer));
238 return PP_OK; 158 return PP_OK;
239 } 159 }
240 160
241 int32_t PepperPDFHost::OnHostMsgGetResourceImage( 161 int32_t PepperPDFHost::OnHostMsgGetResourceImage(
242 ppapi::host::HostMessageContext* context, 162 ppapi::host::HostMessageContext* context,
243 PP_ResourceImage image_id, 163 PP_ResourceImage image_id,
244 float scale) { 164 float scale) {
245 int res_id = 0; 165 gfx::ImageSkia* res_image_skia = GetImageResource(image_id);
246 for (size_t i = 0; i < arraysize(kResourceImageMap); ++i) {
247 if (kResourceImageMap[i].pp_id == image_id) {
248 res_id = kResourceImageMap[i].res_id;
249 break;
250 }
251 }
252 if (res_id == 0)
253 return PP_ERROR_FAILED;
254
255 gfx::ImageSkia* res_image_skia =
256 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(res_id);
257 166
258 if (!res_image_skia) 167 if (!res_image_skia)
259 return PP_ERROR_FAILED; 168 return PP_ERROR_FAILED;
260 169
261 gfx::ImageSkiaRep image_skia_rep = res_image_skia->GetRepresentation(scale); 170 gfx::ImageSkiaRep image_skia_rep = res_image_skia->GetRepresentation(scale);
262 171
263 if (image_skia_rep.is_null() || image_skia_rep.scale() != scale) 172 if (image_skia_rep.is_null() || image_skia_rep.scale() != scale)
264 return PP_ERROR_FAILED; 173 return PP_ERROR_FAILED;
265 174
266 PP_Size pp_size; 175 PP_Size pp_size;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 pixels_to_write.copyPixelsTo( 280 pixels_to_write.copyPixelsTo(
372 bitmap->getPixels(), bitmap->getSize(), bitmap->rowBytes()); 281 bitmap->getPixels(), bitmap->getSize(), bitmap->rowBytes());
373 282
374 if (needs_unmapping) 283 if (needs_unmapping)
375 image_data->Unmap(); 284 image_data->Unmap();
376 285
377 return true; 286 return true;
378 } 287 }
379 288
380 } // namespace pdf 289 } // namespace pdf
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698