File: net_resource_provider.cc

package info (click to toggle)
chromium-browser 37.0.2062.120-1~deb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,707,260 kB
  • sloc: cpp: 8,976,677; ansic: 3,473,199; python: 586,578; asm: 449,013; xml: 184,195; java: 142,924; sh: 118,496; perl: 81,467; makefile: 27,557; yacc: 10,506; objc: 8,886; tcl: 3,186; cs: 2,252; lex: 2,213; sql: 1,198; pascal: 1,170; lisp: 790; awk: 407; ruby: 155; php: 83; sed: 52; exp: 11
file content (66 lines) | stat: -rw-r--r-- 2,478 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/common/net/net_resource_provider.h"

#include <string>

#include "base/i18n/rtl.h"
#include "base/strings/string_piece.h"
#include "base/values.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "grit/net_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/layout.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/webui/jstemplate_builder.h"

namespace {

// The net module doesn't have access to this HTML or the strings that need to
// be localized.  The Chrome locale will never change while we're running, so
// it's safe to have a static string that we always return a pointer into.
// This allows us to have the ResourceProvider return a pointer into the actual
// resource (via a StringPiece), instead of always copying resources.
struct LazyDirectoryListerCacher {
  LazyDirectoryListerCacher() {
    base::DictionaryValue value;
    value.SetString("header",
                    l10n_util::GetStringUTF16(IDS_DIRECTORY_LISTING_HEADER));
    value.SetString("parentDirText",
                    l10n_util::GetStringUTF16(IDS_DIRECTORY_LISTING_PARENT));
    value.SetString("headerName",
                    l10n_util::GetStringUTF16(IDS_DIRECTORY_LISTING_NAME));
    value.SetString("headerSize",
                    l10n_util::GetStringUTF16(IDS_DIRECTORY_LISTING_SIZE));
    value.SetString("headerDateModified",
        l10n_util::GetStringUTF16(IDS_DIRECTORY_LISTING_DATE_MODIFIED));
    value.SetString("listingParsingErrorBoxText",
        l10n_util::GetStringFUTF16(IDS_DIRECTORY_LISTING_PARSING_ERROR_BOX_TEXT,
            l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
    value.SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr");
    html_data = webui::GetI18nTemplateHtml(
        ResourceBundle::GetSharedInstance().GetRawDataResource(
            IDR_DIR_HEADER_HTML),
        &value);
  }

  std::string html_data;
};

}  // namespace

namespace chrome_common_net {

base::StringPiece NetResourceProvider(int key) {
  CR_DEFINE_STATIC_LOCAL(LazyDirectoryListerCacher, lazy_dir_lister, ());

  if (IDR_DIR_HEADER_HTML == key)
    return base::StringPiece(lazy_dir_lister.html_data);

  return ResourceBundle::GetSharedInstance().GetRawDataResource(key);
}

}  // namespace chrome_common_net