From 7359238b124bc0a5ff08fb128c052115fc431d96 Mon Sep 17 00:00:00 2001 From: "jam@chromium.org" Date: Fri, 18 Jan 2013 19:22:37 +0000 Subject: Move jstemplate_builder.* to ui\webui so it can be reused by webui implementations outside of chrome. BUG=169170 TBR=estade Review URL: https://codereview.chromium.org/11929016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@177729 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/common/common_resources.grd | 4 - chrome/common/descriptors_android.h | 1 + chrome/common/jstemplate_builder.cc | 156 ----------------------------- chrome/common/jstemplate_builder.h | 86 ---------------- chrome/common/net/net_resource_provider.cc | 2 +- 5 files changed, 2 insertions(+), 247 deletions(-) delete mode 100644 chrome/common/jstemplate_builder.cc delete mode 100644 chrome/common/jstemplate_builder.h (limited to 'chrome/common') diff --git a/chrome/common/common_resources.grd b/chrome/common/common_resources.grd index 845bd77..bc7c186 100644 --- a/chrome/common/common_resources.grd +++ b/chrome/common/common_resources.grd @@ -11,10 +11,6 @@ - - - - diff --git a/chrome/common/descriptors_android.h b/chrome/common/descriptors_android.h index 09d9a9b..16886e9 100644 --- a/chrome/common/descriptors_android.h +++ b/chrome/common/descriptors_android.h @@ -11,6 +11,7 @@ enum { #if defined(OS_ANDROID) kAndroidChromePakDescriptor = kContentIPCDescriptorMax + 1, kAndroidLocalePakDescriptor, + kAndroidChrome100PercentPakDescriptor, kAndroidUIResourcesPakDescriptor, kAndroidMinidumpDescriptor, #endif diff --git a/chrome/common/jstemplate_builder.cc b/chrome/common/jstemplate_builder.cc deleted file mode 100644 index e8da8bd..0000000 --- a/chrome/common/jstemplate_builder.cc +++ /dev/null @@ -1,156 +0,0 @@ -// 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. - -// A helper function for using JsTemplate. See jstemplate_builder.h for more -// info. - -#include "chrome/common/jstemplate_builder.h" - -#include "base/json/json_file_value_serializer.h" -#include "base/json/json_string_value_serializer.h" -#include "base/logging.h" -#include "base/string_util.h" -#include "grit/common_resources.h" -#include "ui/base/layout.h" -#include "ui/base/resource/resource_bundle.h" - -namespace { - -// Non-zero when building version 2 templates. See UseVersion2 class. -int g_version2 = 0; - -} // namespace - -namespace jstemplate_builder { - -UseVersion2::UseVersion2() { - g_version2++; -} - -UseVersion2::~UseVersion2() { - g_version2--; -} - -std::string GetTemplateHtml(const base::StringPiece& html_template, - const DictionaryValue* json, - const base::StringPiece& template_id) { - std::string output(html_template.data(), html_template.size()); - AppendJsonHtml(json, &output); - AppendJsTemplateSourceHtml(&output); - AppendJsTemplateProcessHtml(template_id, &output); - return output; -} - -std::string GetI18nTemplateHtml(const base::StringPiece& html_template, - const DictionaryValue* json) { - std::string output(html_template.data(), html_template.size()); - AppendJsonHtml(json, &output); - AppendI18nTemplateSourceHtml(&output); - AppendI18nTemplateProcessHtml(&output); - return output; -} - -std::string GetTemplatesHtml(const base::StringPiece& html_template, - const DictionaryValue* json, - const base::StringPiece& template_id) { - std::string output(html_template.data(), html_template.size()); - AppendI18nTemplateSourceHtml(&output); - AppendJsTemplateSourceHtml(&output); - AppendJsonHtml(json, &output); - AppendI18nTemplateProcessHtml(&output); - AppendJsTemplateProcessHtml(template_id, &output); - return output; -} - -void AppendJsonHtml(const DictionaryValue* json, std::string* output) { - std::string javascript_string; - jstemplate_builder::AppendJsonJS(json, &javascript_string); - - // tag. So we - // replace append(""); -} - -void AppendJsonJS(const DictionaryValue* json, std::string* output) { - // Convert the template data to a json string. - DCHECK(json) << "must include json data structure"; - - std::string jstext; - JSONStringValueSerializer serializer(&jstext); - serializer.Serialize(*json); - output->append(g_version2 ? "loadTimeData.data = " : "var templateData = "); - output->append(jstext); - output->append(";"); -} - -void AppendJsTemplateSourceHtml(std::string* output) { - // fetch and cache the pointer of the jstemplate resource source text. - static const base::StringPiece jstemplate_src( - ResourceBundle::GetSharedInstance().GetRawDataResource( - IDR_JSTEMPLATE_JS)); - - if (jstemplate_src.empty()) { - NOTREACHED() << "Unable to get jstemplate src"; - return; - } - - output->append(""); -} - -void AppendJsTemplateProcessHtml(const base::StringPiece& template_id, - std::string* output) { - output->append(""); -} - -void AppendI18nTemplateSourceHtml(std::string* output) { - // fetch and cache the pointer of the jstemplate resource source text. - static const base::StringPiece i18n_template_src( - ResourceBundle::GetSharedInstance().GetRawDataResource( - IDR_I18N_TEMPLATE_JS)); - static const base::StringPiece i18n_template2_src( - ResourceBundle::GetSharedInstance().GetRawDataResource( - IDR_I18N_TEMPLATE2_JS)); - const base::StringPiece* template_src = g_version2 ? - &i18n_template2_src : &i18n_template_src; - - if (template_src->empty()) { - NOTREACHED() << "Unable to get i18n template src"; - return; - } - - output->append(""); -} - -void AppendI18nTemplateProcessHtml(std::string* output) { - if (g_version2) - return; - - static const base::StringPiece i18n_process_src( - ResourceBundle::GetSharedInstance().GetRawDataResource( - IDR_I18N_PROCESS_JS)); - - if (i18n_process_src.empty()) { - NOTREACHED() << "Unable to get i18n process src"; - return; - } - - output->append(""); -} - -} // namespace jstemplate_builder diff --git a/chrome/common/jstemplate_builder.h b/chrome/common/jstemplate_builder.h deleted file mode 100644 index c867e73..0000000 --- a/chrome/common/jstemplate_builder.h +++ /dev/null @@ -1,86 +0,0 @@ -// 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. - -// This provides some helper methods for building and rendering an -// internal html page. The flow is as follows: -// - instantiate a builder given a webframe that we're going to render content -// into -// - load the template html and load the jstemplate javascript into the frame -// - given a json data object, run the jstemplate javascript which fills in -// template values - -#ifndef CHROME_COMMON_JSTEMPLATE_BUILDER_H_ -#define CHROME_COMMON_JSTEMPLATE_BUILDER_H_ - -#include - -#include "base/string_piece.h" - -namespace base { -class DictionaryValue; -} - -namespace jstemplate_builder { - -// While an object of this class is in scope, the template builder will output -// version 2 html. Version 2 uses load_time_data.js and i18n_template2.js, and -// should soon become the default. -class UseVersion2 { - public: - UseVersion2(); - ~UseVersion2(); - - private: - DISALLOW_COPY_AND_ASSIGN(UseVersion2); -}; - -// A helper function that generates a string of HTML to be loaded. The -// string includes the HTML and the javascript code necessary to generate the -// full page with support for JsTemplates. -std::string GetTemplateHtml(const base::StringPiece& html_template, - const base::DictionaryValue* json, - const base::StringPiece& template_id); - -// A helper function that generates a string of HTML to be loaded. The -// string includes the HTML and the javascript code necessary to generate the -// full page with support for i18n Templates. -std::string GetI18nTemplateHtml(const base::StringPiece& html_template, - const base::DictionaryValue* json); - -// A helper function that generates a string of HTML to be loaded. The -// string includes the HTML and the javascript code necessary to generate the -// full page with support for both i18n Templates and JsTemplates. -std::string GetTemplatesHtml(const base::StringPiece& html_template, - const base::DictionaryValue* json, - const base::StringPiece& template_id); - -// The following functions build up the different parts that the above -// templates use. - -// Appends a script tag with a variable name |templateData| that has the JSON -// assigned to it. -void AppendJsonHtml(const base::DictionaryValue* json, std::string* output); - -// Same as AppendJsonHtml(), except does not include the -// tag wrappers. -void AppendJsonJS(const base::DictionaryValue* json, std::string* output); - -// Appends the source for JsTemplates in a script tag. -void AppendJsTemplateSourceHtml(std::string* output); - -// Appends the code that processes the JsTemplate with the JSON. You should -// call AppendJsTemplateSourceHtml and AppendJsonHtml before calling this. -void AppendJsTemplateProcessHtml(const base::StringPiece& template_id, - std::string* output); - -// Appends the source for i18n Templates in a script tag. -void AppendI18nTemplateSourceHtml(std::string* output); - -// Appends the code that processes the i18n Template with the JSON. You -// should call AppendJsTemplateSourceHtml and AppendJsonHtml before calling -// this. -void AppendI18nTemplateProcessHtml(std::string* output); - -} // namespace jstemplate_builder -#endif // CHROME_COMMON_JSTEMPLATE_BUILDER_H_ diff --git a/chrome/common/net/net_resource_provider.cc b/chrome/common/net/net_resource_provider.cc index d83c9d6..1469d11 100644 --- a/chrome/common/net/net_resource_provider.cc +++ b/chrome/common/net/net_resource_provider.cc @@ -8,13 +8,13 @@ #include "base/string_piece.h" #include "base/values.h" -#include "chrome/common/jstemplate_builder.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/webui/jstemplate_builder.h" namespace { -- cgit v1.1