• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2009 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 "chrome/common/net/net_resource_provider.h"
6 
7 #include <string>
8 
9 #include "base/string_piece.h"
10 #include "base/values.h"
11 #include "chrome/common/jstemplate_builder.h"
12 #include "grit/chromium_strings.h"
13 #include "grit/generated_resources.h"
14 #include "grit/net_resources.h"
15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/base/resource/resource_bundle.h"
17 
18 namespace {
19 
20 // The net module doesn't have access to this HTML or the strings that need to
21 // be localized.  The Chrome locale will never change while we're running, so
22 // it's safe to have a static string that we always return a pointer into.
23 // This allows us to have the ResourceProvider return a pointer into the actual
24 // resource (via a StringPiece), instead of always copying resources.
25 struct LazyDirectoryListerCacher {
LazyDirectoryListerCacher__anon146e94550111::LazyDirectoryListerCacher26   LazyDirectoryListerCacher() {
27     DictionaryValue value;
28     value.SetString("header",
29                     l10n_util::GetStringUTF16(IDS_DIRECTORY_LISTING_HEADER));
30     value.SetString("parentDirText",
31                     l10n_util::GetStringUTF16(IDS_DIRECTORY_LISTING_PARENT));
32     value.SetString("headerName",
33                     l10n_util::GetStringUTF16(IDS_DIRECTORY_LISTING_NAME));
34     value.SetString("headerSize",
35                     l10n_util::GetStringUTF16(IDS_DIRECTORY_LISTING_SIZE));
36     value.SetString("headerDateModified",
37         l10n_util::GetStringUTF16(IDS_DIRECTORY_LISTING_DATE_MODIFIED));
38     value.SetString("listingParsingErrorBoxText",
39         l10n_util::GetStringFUTF16(IDS_DIRECTORY_LISTING_PARSING_ERROR_BOX_TEXT,
40             l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
41     html_data = jstemplate_builder::GetI18nTemplateHtml(
42         ResourceBundle::GetSharedInstance().GetRawDataResource(
43             IDR_DIR_HEADER_HTML),
44         &value);
45   }
46 
47   std::string html_data;
48 };
49 
50 }  // namespace
51 
52 namespace chrome_common_net {
53 
NetResourceProvider(int key)54 base::StringPiece NetResourceProvider(int key) {
55   static LazyDirectoryListerCacher lazy_dir_lister;
56 
57   if (IDR_DIR_HEADER_HTML == key)
58     return base::StringPiece(lazy_dir_lister.html_data);
59 
60   return ResourceBundle::GetSharedInstance().GetRawDataResource(key);
61 }
62 
63 }  // namespace chrome_common_net
64