summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorstevet@chromium.org <stevet@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-30 04:09:56 +0000
committerstevet@chromium.org <stevet@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-30 04:09:56 +0000
commit884873f1c3d29c08c1db33aaf18baf0bf43b73c3 (patch)
treed680f4eefe6ac5c04228aa938458349913e3c72f
parent937cf9d09ab1814bd61bf2256d778ac85c58aa3d (diff)
downloadchromium_src-884873f1c3d29c08c1db33aaf18baf0bf43b73c3.zip
chromium_src-884873f1c3d29c08c1db33aaf18baf0bf43b73c3.tar.gz
chromium_src-884873f1c3d29c08c1db33aaf18baf0bf43b73c3.tar.bz2
Expose the list of selected variations in the about:versions page in debug mode.
BUG=144713 TEST=In a Debug build, go to about:version. There should be a list of Variations in the page. In a Release build, ensure that the same page does not contain such text. Review URL: https://chromiumcodereview.appspot.com/10868082 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@154067 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/app/generated_resources.grd3
-rw-r--r--chrome/browser/resources/about_version.html6
-rw-r--r--chrome/browser/resources/about_version.js17
-rw-r--r--chrome/browser/ui/webui/about_ui.cc68
4 files changed, 92 insertions, 2 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index 0fb35bc..5e10328 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -6413,6 +6413,9 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_ABOUT_VERSION_PATH_NOTFOUND" desc="label for the non-existent path on the about:version page">
No such file or directory
</message>
+ <message name="IDS_ABOUT_VERSION_VARIATIONS" desc="label for the variations list on the about:version page">
+ Variations
+ </message>
<!-- JavaScript Dialog Box strings -->
<message name="IDS_JAVASCRIPT_ALERT_DEFAULT_TITLE" desc="Title for JavaScript alert originating from a webpage if there is no hostname to display">
diff --git a/chrome/browser/resources/about_version.html b/chrome/browser/resources/about_version.html
index 1b71053..45ab5b2 100644
--- a/chrome/browser/resources/about_version.html
+++ b/chrome/browser/resources/about_version.html
@@ -14,6 +14,8 @@ about:version template page
<if expr="pp_ifdef('android')">
<link rel="stylesheet" href="about_version_android.css">
</if>
+ <script src="chrome://resources/js/parse_html_subset.js"></script>
+ <script src="chrome://resources/js/util.js"></script>
<script src="chrome://version/version.js"></script>
<script src="chrome://version/strings.js"></script>
</head>
@@ -66,6 +68,10 @@ about:version template page
<tr><td class="label" valign="top" i18n-content="profile_path_name"></td>
<td class="version" id="profile_path" i18n-content="profile_path"></td>
</tr>
+ <tr id="variations-section">
+ <td class="label" valign="top" i18n-content="variations_name"></td>
+ <td class="version" id="variations-list"></td>
+ </tr>
</table>
</div>
<script src="chrome://resources/js/i18n_template.js"></script>
diff --git a/chrome/browser/resources/about_version.js b/chrome/browser/resources/about_version.js
index 30ad114..88417fe 100644
--- a/chrome/browser/resources/about_version.js
+++ b/chrome/browser/resources/about_version.js
@@ -2,13 +2,26 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+/**
+ * Callback from the backend with the list of variations to display.
+ * This call will build the variations section of the version page, or hide that
+ * section if there are none to display.
+ * @param {!Array.<string>} variationsList The list of variations.
+ */
+function returnVariationsList(variationsList) {
+ $('variations-section').hidden = !variationsList.length;
+ $('variations-list').appendChild(
+ parseHtmlSubset(variationsList.join('<br>'), ['BR']));
+}
+
/* All the work we do onload. */
function onLoadWork() {
// This is the javascript code that processes the template:
var input = new JsEvalContext(templateData);
- var output = document.getElementById('t');
+ var output = $('t');
jstProcess(input, output);
+
+ chrome.send('requestVariationsList');
}
document.addEventListener('DOMContentLoaded', onLoadWork);
-
diff --git a/chrome/browser/ui/webui/about_ui.cc b/chrome/browser/ui/webui/about_ui.cc
index 73460ad..15d0e03 100644
--- a/chrome/browser/ui/webui/about_ui.cc
+++ b/chrome/browser/ui/webui/about_ui.cc
@@ -18,11 +18,13 @@
#include "base/json/json_writer.h"
#include "base/memory/ref_counted_memory.h"
#include "base/memory/singleton.h"
+#include "base/metrics/field_trial.h"
#include "base/metrics/statistics_recorder.h"
#include "base/metrics/stats_table.h"
#include "base/path_service.h"
#include "base/string_number_conversions.h"
#include "base/string_piece.h"
+#include "base/string_split.h"
#include "base/string_util.h"
#include "base/stringprintf.h"
#include "base/threading/thread.h"
@@ -53,6 +55,7 @@
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
+#include "content/public/browser/web_ui_message_handler.h"
#include "content/public/common/content_client.h"
#include "content/public/common/process_type.h"
#include "googleurl/src/gurl.h"
@@ -1110,6 +1113,11 @@ std::string AboutVersionStrings(DictionaryValue* localized_strings,
}
ChromeWebUIDataSource::SetFontAndTextDirection(localized_strings);
+#if !defined(NDEBUG)
+ localized_strings->SetString("variations_name",
+ l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_VARIATIONS));
+#endif
+
std::string data;
jstemplate_builder::AppendJsonJS(localized_strings, &data);
return data;
@@ -1289,6 +1297,64 @@ void ChromeOSAboutVersionHandler::OnVersion(
#endif
+class VersionDOMHandler : public content::WebUIMessageHandler {
+ public:
+ VersionDOMHandler();
+ virtual ~VersionDOMHandler();
+
+ // content::WebUIMessageHandler implementation.
+ virtual void RegisterMessages() OVERRIDE;
+
+ // Callback for the "requestVariationsList" message. This requests the list of
+ // variations from the client and sends it to the frontend.
+ void HandleRequestVariationsList(const ListValue* args);
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(VersionDOMHandler);
+};
+
+VersionDOMHandler::VersionDOMHandler() {
+}
+
+VersionDOMHandler::~VersionDOMHandler() {
+}
+
+void VersionDOMHandler::RegisterMessages() {
+ web_ui()->RegisterMessageCallback(
+ "requestVariationsList",
+ base::Bind(&VersionDOMHandler::HandleRequestVariationsList,
+ base::Unretained(this)));
+}
+
+void VersionDOMHandler::HandleRequestVariationsList(const ListValue* args) {
+ scoped_ptr<ListValue> variations_list(new ListValue());
+#if !defined(NDEBUG)
+ std::vector<std::string> variations;
+ std::string variation_state;
+ base::FieldTrialList::StatesToString(&variation_state);
+
+ std::vector<std::string> tokens;
+ base::SplitString(variation_state,
+ base::FieldTrialList::kPersistentStringSeparator,
+ &tokens);
+ // Since StatesToString appends a separator at the end, SplitString will
+ // append an extra empty string in the vector. Drop it. There should
+ // always be an even number of tokens left.
+ tokens.pop_back();
+ DCHECK_EQ(0U, tokens.size() % 2);
+ for (size_t i = 0; i < tokens.size(); i += 2)
+ variations.push_back(tokens[i] + ":" + tokens[i + 1]);
+
+ for (std::vector<std::string>::const_iterator it = variations.begin();
+ it != variations.end(); ++it) {
+ variations_list->Append(Value::CreateStringValue(*it));
+ }
+#endif
+ // In release mode, this will return an empty list to clear the section.
+ web_ui()->CallJavascriptFunction("returnVariationsList",
+ *variations_list.release());
+}
+
} // namespace
// AboutUIHTMLSource ----------------------------------------------------------
@@ -1397,6 +1463,8 @@ AboutUI::AboutUI(content::WebUI* web_ui, const std::string& name)
ChromeURLDataManager::AddDataSource(profile, theme);
#endif
+ web_ui->AddMessageHandler(new VersionDOMHandler());
+
ChromeURLDataManager::DataSource* source =
new AboutUIHTMLSource(name, profile);
if (source) {