• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "components/pdf/renderer/pdf_resource_util.h"
6 
7 #include "base/strings/utf_string_conversions.h"
8 #include "components/strings/grit/components_strings.h"
9 #include "grit/components_scaled_resources.h"
10 #include "ui/base/l10n/l10n_util.h"
11 #include "ui/base/resource/resource_bundle.h"
12 
13 namespace {
14 
15 struct ResourceImageInfo {
16   PP_ResourceImage pp_id;
17   int res_id;
18 };
19 
20 static const ResourceImageInfo kResourceImageMap[] = {
21     {PP_RESOURCEIMAGE_PDF_BUTTON_FTP, IDR_PDF_BUTTON_FTP},
22     {PP_RESOURCEIMAGE_PDF_BUTTON_FTP_HOVER, IDR_PDF_BUTTON_FTP_HOVER},
23     {PP_RESOURCEIMAGE_PDF_BUTTON_FTP_PRESSED, IDR_PDF_BUTTON_FTP_PRESSED},
24     {PP_RESOURCEIMAGE_PDF_BUTTON_FTW, IDR_PDF_BUTTON_FTW},
25     {PP_RESOURCEIMAGE_PDF_BUTTON_FTW_HOVER, IDR_PDF_BUTTON_FTW_HOVER},
26     {PP_RESOURCEIMAGE_PDF_BUTTON_FTW_PRESSED, IDR_PDF_BUTTON_FTW_PRESSED},
27     {PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN_END, IDR_PDF_BUTTON_ZOOMIN_END},
28     {PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN_END_HOVER,
29      IDR_PDF_BUTTON_ZOOMIN_END_HOVER},
30     {PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN_END_PRESSED,
31      IDR_PDF_BUTTON_ZOOMIN_END_PRESSED},
32     {PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN, IDR_PDF_BUTTON_ZOOMIN},
33     {PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN_HOVER, IDR_PDF_BUTTON_ZOOMIN_HOVER},
34     {PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN_PRESSED, IDR_PDF_BUTTON_ZOOMIN_PRESSED},
35     {PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMOUT, IDR_PDF_BUTTON_ZOOMOUT},
36     {PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMOUT_HOVER, IDR_PDF_BUTTON_ZOOMOUT_HOVER},
37     {PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMOUT_PRESSED,
38      IDR_PDF_BUTTON_ZOOMOUT_PRESSED},
39     {PP_RESOURCEIMAGE_PDF_BUTTON_SAVE, IDR_PDF_BUTTON_SAVE},
40     {PP_RESOURCEIMAGE_PDF_BUTTON_SAVE_HOVER, IDR_PDF_BUTTON_SAVE_HOVER},
41     {PP_RESOURCEIMAGE_PDF_BUTTON_SAVE_PRESSED, IDR_PDF_BUTTON_SAVE_PRESSED},
42     {PP_RESOURCEIMAGE_PDF_BUTTON_PRINT, IDR_PDF_BUTTON_PRINT},
43     {PP_RESOURCEIMAGE_PDF_BUTTON_PRINT_HOVER, IDR_PDF_BUTTON_PRINT_HOVER},
44     {PP_RESOURCEIMAGE_PDF_BUTTON_PRINT_PRESSED, IDR_PDF_BUTTON_PRINT_PRESSED},
45     {PP_RESOURCEIMAGE_PDF_BUTTON_PRINT_DISABLED, IDR_PDF_BUTTON_PRINT_DISABLED},
46     {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_0, IDR_PDF_THUMBNAIL_0},
47     {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_1, IDR_PDF_THUMBNAIL_1},
48     {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_2, IDR_PDF_THUMBNAIL_2},
49     {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_3, IDR_PDF_THUMBNAIL_3},
50     {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_4, IDR_PDF_THUMBNAIL_4},
51     {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_5, IDR_PDF_THUMBNAIL_5},
52     {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_6, IDR_PDF_THUMBNAIL_6},
53     {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_7, IDR_PDF_THUMBNAIL_7},
54     {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_8, IDR_PDF_THUMBNAIL_8},
55     {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_9, IDR_PDF_THUMBNAIL_9},
56     {PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_NUM_BACKGROUND,
57      IDR_PDF_THUMBNAIL_NUM_BACKGROUND},
58     {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_0, IDR_PDF_PROGRESS_BAR_0},
59     {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_1, IDR_PDF_PROGRESS_BAR_1},
60     {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_2, IDR_PDF_PROGRESS_BAR_2},
61     {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_3, IDR_PDF_PROGRESS_BAR_3},
62     {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_4, IDR_PDF_PROGRESS_BAR_4},
63     {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_5, IDR_PDF_PROGRESS_BAR_5},
64     {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_6, IDR_PDF_PROGRESS_BAR_6},
65     {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_7, IDR_PDF_PROGRESS_BAR_7},
66     {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_8, IDR_PDF_PROGRESS_BAR_8},
67     {PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_BACKGROUND,
68      IDR_PDF_PROGRESS_BAR_BACKGROUND},
69     {PP_RESOURCEIMAGE_PDF_PAGE_INDICATOR_BACKGROUND,
70      IDR_PDF_PAGE_INDICATOR_BACKGROUND},
71     {PP_RESOURCEIMAGE_PDF_PAGE_DROPSHADOW, IDR_PDF_PAGE_DROPSHADOW},
72     {PP_RESOURCEIMAGE_PDF_PAN_SCROLL_ICON, IDR_PDF_PAN_SCROLL_ICON},
73 };
74 
75 }  // namespace
76 
77 namespace pdf {
78 
GetImageResource(PP_ResourceImage image_id)79 gfx::ImageSkia* GetImageResource(PP_ResourceImage image_id) {
80   int resource_id = 0;
81   for (size_t i = 0; i < arraysize(kResourceImageMap); ++i) {
82     if (kResourceImageMap[i].pp_id == image_id) {
83       resource_id = kResourceImageMap[i].res_id;
84       break;
85     }
86   }
87 
88   return resource_id ? ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
89                            resource_id)
90                      : NULL;
91 }
92 
GetStringResource(PP_ResourceString string_id)93 std::string GetStringResource(PP_ResourceString string_id) {
94   int resource_id = 0;
95   switch (string_id) {
96     case PP_RESOURCESTRING_PDFGETPASSWORD:
97       resource_id = IDS_PDF_NEED_PASSWORD;
98       break;
99     case PP_RESOURCESTRING_PDFLOADING:
100       resource_id = IDS_PDF_PAGE_LOADING;
101       break;
102     case PP_RESOURCESTRING_PDFLOAD_FAILED:
103       resource_id = IDS_PDF_PAGE_LOAD_FAILED;
104       break;
105     case PP_RESOURCESTRING_PDFPROGRESSLOADING:
106       resource_id = IDS_PDF_PROGRESS_LOADING;
107       break;
108   }
109 
110   return base::UTF16ToUTF8(l10n_util::GetStringUTF16(resource_id));
111 }
112 
113 }  // namespace pdf
114