summaryrefslogtreecommitdiffstats
path: root/chrome/common/net
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-22 21:05:47 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-22 21:05:47 +0000
commit64d50ed649d61c5b84b09369b091018f70547bf8 (patch)
tree32f25e3f4d6721d68f6ce553bc51172a218bb071 /chrome/common/net
parentdbf5e6c9053bf8e4c5fb08a1ca3005636380b5bb (diff)
downloadchromium_src-64d50ed649d61c5b84b09369b091018f70547bf8.zip
chromium_src-64d50ed649d61c5b84b09369b091018f70547bf8.tar.gz
chromium_src-64d50ed649d61c5b84b09369b091018f70547bf8.tar.bz2
Move FTP LIST parsing code to the renderer process.
TEST=none BUG=none Review URL: http://codereview.chromium.org/210027 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26860 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/net')
-rw-r--r--chrome/common/net/net_resource_provider.cc59
-rw-r--r--chrome/common/net/net_resource_provider.h19
2 files changed, 78 insertions, 0 deletions
diff --git a/chrome/common/net/net_resource_provider.cc b/chrome/common/net/net_resource_provider.cc
new file mode 100644
index 0000000..ef86ac3
--- /dev/null
+++ b/chrome/common/net/net_resource_provider.cc
@@ -0,0 +1,59 @@
+// Copyright (c) 2009 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 "app/l10n_util.h"
+#include "app/resource_bundle.h"
+#include "base/string_piece.h"
+#include "base/values.h"
+#include "chrome/common/jstemplate_builder.h"
+#include "grit/generated_resources.h"
+#include "grit/net_resources.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() {
+ DictionaryValue value;
+ value.SetString(L"header",
+ l10n_util::GetString(IDS_DIRECTORY_LISTING_HEADER));
+ value.SetString(L"parentDirText",
+ l10n_util::GetString(IDS_DIRECTORY_LISTING_PARENT));
+ value.SetString(L"headerName",
+ l10n_util::GetString(IDS_DIRECTORY_LISTING_NAME));
+ value.SetString(L"headerSize",
+ l10n_util::GetString(IDS_DIRECTORY_LISTING_SIZE));
+ value.SetString(L"headerDateModified",
+ l10n_util::GetString(IDS_DIRECTORY_LISTING_DATE_MODIFIED));
+ html_data = jstemplate_builder::GetI18nTemplateHtml(
+ ResourceBundle::GetSharedInstance().GetRawDataResource(
+ IDR_DIR_HEADER_HTML),
+ &value);
+ }
+
+ std::string html_data;
+};
+
+} // namespace
+
+namespace chrome_common_net {
+
+base::StringPiece NetResourceProvider(int key) {
+ static 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
diff --git a/chrome/common/net/net_resource_provider.h b/chrome/common/net/net_resource_provider.h
new file mode 100644
index 0000000..4965adf
--- /dev/null
+++ b/chrome/common/net/net_resource_provider.h
@@ -0,0 +1,19 @@
+// Copyright (c) 2009 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.
+
+#ifndef CHROME_COMMON_NET_NET_RESOURCE_PROVIDER_H_
+#define CHROME_COMMON_NET_NET_RESOURCE_PROVIDER_H_
+
+namespace base {
+class StringPiece;
+}
+
+namespace chrome_common_net {
+
+// This is called indirectly by the network layer to access resources.
+base::StringPiece NetResourceProvider(int key);
+
+} // namespace chrome_common_net
+
+#endif // CHROME_COMMON_NET_NET_RESOURCE_PROVIDER_H_