diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-01 16:59:31 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-01 16:59:31 +0000 |
commit | 79ee1b0eb6fa683331452ba7422b59498b739d69 (patch) | |
tree | c7d11b23e26bec65b44eb7e677f82b24d1e80d15 | |
parent | df772cbfe7a1b17dd7bb179c1e25780201d0b0ce (diff) | |
download | chromium_src-79ee1b0eb6fa683331452ba7422b59498b739d69.zip chromium_src-79ee1b0eb6fa683331452ba7422b59498b739d69.tar.gz chromium_src-79ee1b0eb6fa683331452ba7422b59498b739d69.tar.bz2 |
When running on chrome OS about:version now shows OS version.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/179063
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25045 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/chromium_strings.grd | 5 | ||||
-rw-r--r-- | chrome/app/generated_resources.grd | 6 | ||||
-rw-r--r-- | chrome/app/google_chrome_strings.grd | 5 | ||||
-rw-r--r-- | chrome/browser/browser_about_handler.cc | 115 | ||||
-rw-r--r-- | chrome/browser/chromeos/chromeos_version_loader.cc | 76 | ||||
-rw-r--r-- | chrome/browser/chromeos/chromeos_version_loader.h | 63 | ||||
-rw-r--r-- | chrome/browser/chromeos/chromeos_version_loader_unittest.cc | 24 | ||||
-rw-r--r-- | chrome/browser/gtk/options/options_window_gtk.cc | 2 | ||||
-rw-r--r-- | chrome/browser/resources/about_version.html | 3 | ||||
-rw-r--r-- | chrome/chrome.gyp | 3 | ||||
-rw-r--r-- | chrome/common/temp_scaffolding_stubs.cc | 5 |
11 files changed, 276 insertions, 31 deletions
diff --git a/chrome/app/chromium_strings.grd b/chrome/app/chromium_strings.grd index a9cbeee..df759e0 100644 --- a/chrome/app/chromium_strings.grd +++ b/chrome/app/chromium_strings.grd @@ -123,6 +123,11 @@ be available for now. --> <message name="IDS_PRODUCT_NAME" desc="The Chrome application name"> Chromium </message> + <if expr="pp_ifdef('chromeos')"> + <message name="IDS_PRODUCT_OS_NAME" desc="The Chrome OS application name"> + Chromium OS + </message> + </if> <message name="IDS_CERT_ERROR_COMMON_NAME_INVALID_EXTRA_INFO_2" desc="2nd paragraph of extra information for an unsafe common name in an X509 certificate"> In this case, the address listed in the certificate does not match the address of the website your browser tried to go to. One possible reason for this is that your communications are being intercepted by an attacker who is presenting a certificate for a different website, which would cause a mismatch. Another possible reason is that the server is set up to return the same certificate for multiple websites, including the one you are attempting to visit, even though that certificate is not valid for all of those websites. Chromium can say for sure that you reached <strong><ph name="DOMAIN2">$1<ex>paypal.com</ex></ph></strong>, but cannot verify that that is the same site as <strong><ph name="DOMAIN">$2<ex>www.paypal.com</ex></ph></strong> which you intended to reach. If you proceed, Chromium will not check for any further name mismatches. In general, it is best not to proceed past this point. </message> diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index a5bc387..8dd647c 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -4926,12 +4926,6 @@ Keep your key file in a safe place. You will need it to create new versions of y Glen </message> - <if expr="pp_ifdef('chromeos')"> - <message name="IDS_OPTIONS_SETTINGS_TAB_LABEL" desc="Title of the settings tab inthe options dialog."> - Chrome OS - </message> - </if> - <!-- Extra Mac UI Strings --> <if expr="os == 'darwin'"> <message name="IDS_PLEASE_RESTART_BROWSER" desc="Title of the alert when Chrome needs to be restart for a change/update to take effect."> diff --git a/chrome/app/google_chrome_strings.grd b/chrome/app/google_chrome_strings.grd index 9e8803f..f8806a1 100644 --- a/chrome/app/google_chrome_strings.grd +++ b/chrome/app/google_chrome_strings.grd @@ -171,6 +171,11 @@ Chrome supports. --> <message name="IDS_PRODUCT_NAME" desc="The Chrome application name"> Google Chrome </message> + <if expr="pp_ifdef('chromeos')"> + <message name="IDS_PRODUCT_OS_NAME" desc="The Chrome OS application name"> + Google Chrome OS + </message> + </if> <message name="IDS_CERT_ERROR_COMMON_NAME_INVALID_EXTRA_INFO_2" desc="2nd paragraph of extra information for an unsafe common name in an X509 certificate"> In this case, the address listed in the certificate does not match the address of the website your browser tried to go to. One possible reason for this is that your communications are being intercepted by an attacker who is presenting a certificate for a different website, which would cause a mismatch. Another possible reason is that the server is set up to return the same certificate for multiple websites, including the one you are attempting to visit, even though that certificate is not valid for all of those websites. Google Chrome can say for sure that you reached <strong><ph name="DOMAIN2">$1<ex>paypal.com</ex></ph></strong>, but cannot verify that that is the same site as <strong><ph name="DOMAIN">$2<ex>www.paypal.com</ex></ph></strong> which you intended to reach. If you proceed, Chrome will not check for any further name mismatches. In general, it is best not to proceed past this point. </message> diff --git a/chrome/browser/browser_about_handler.cc b/chrome/browser/browser_about_handler.cc index f4a5da6..d7c14fc 100644 --- a/chrome/browser/browser_about_handler.cc +++ b/chrome/browser/browser_about_handler.cc @@ -48,6 +48,8 @@ #if defined(OS_WIN) #include "chrome/browser/views/about_ipc_dialog.h" #include "chrome/browser/views/about_network_dialog.h" +#elif defined(OS_CHROMEOS) +#include "chrome/browser/chromeos/chromeos_version_loader.h" #endif #ifdef CHROME_PERSONALIZATION @@ -128,14 +130,43 @@ class AboutMemoryHandler : public MemoryDetails { void BindProcessMetrics(DictionaryValue* data, ProcessMemoryInformation* info); void AppendProcess(ListValue* child_data, ProcessMemoryInformation* info); - void FinishAboutMemory(); - AboutSource* source_; + scoped_refptr<AboutSource> source_; int request_id_; DISALLOW_COPY_AND_ASSIGN(AboutMemoryHandler); }; +#if defined(OS_CHROMEOS) +// ChromeOSAboutVersionHandler is responsible for loading the Chrome OS +// version. +// ChromeOSAboutVersionHandler handles deleting itself once the version has +// been obtained and AboutSource notified. +class ChromeOSAboutVersionHandler { + public: + ChromeOSAboutVersionHandler(AboutSource* source, int request_id); + + // Callback from ChromeOSVersionLoader giving the version. + void OnVersion(ChromeOSVersionLoader::Handle handle, + std::string version); + + private: + // Where the results are fed to. + scoped_refptr<AboutSource> source_; + + // ID identifying the request. + int request_id_; + + // Handles asynchronously loading the version. + ChromeOSVersionLoader loader_; + + // Used to request the version. + CancelableRequestConsumer consumer_; + + DISALLOW_COPY_AND_ASSIGN(ChromeOSAboutVersionHandler); +}; +#endif + // Individual about handlers --------------------------------------------------- std::string AboutCredits() { @@ -346,10 +377,8 @@ std::string AboutTerms() { return terms_html; } -std::string AboutVersion() { - // Strings used in the JsTemplate file. - DictionaryValue localized_strings; - localized_strings.SetString(L"title", +std::string AboutVersion(DictionaryValue* localized_strings) { + localized_strings->SetString(L"title", l10n_util::GetString(IDS_ABOUT_VERSION_TITLE)); scoped_ptr<FileVersionInfo> version_info( FileVersionInfo::CreateFileVersionInfoForCurrentModule()); @@ -368,33 +397,38 @@ std::string AboutVersion() { std::wstring js_engine = L"JavaScriptCore"; #endif - localized_strings.SetString(L"name", + localized_strings->SetString(L"name", l10n_util::GetString(IDS_PRODUCT_NAME)); - localized_strings.SetString(L"version", version_info->file_version()); - localized_strings.SetString(L"js_engine", js_engine); - localized_strings.SetString(L"js_version", js_version); - localized_strings.SetString(L"webkit_version", webkit_version); - localized_strings.SetString(L"company", + localized_strings->SetString(L"version", version_info->file_version()); + localized_strings->SetString(L"js_engine", js_engine); + localized_strings->SetString(L"js_version", js_version); + localized_strings->SetString(L"webkit_version", webkit_version); + localized_strings->SetString(L"company", l10n_util::GetString(IDS_ABOUT_VERSION_COMPANY_NAME)); - localized_strings.SetString(L"copyright", + localized_strings->SetString(L"copyright", l10n_util::GetString(IDS_ABOUT_VERSION_COPYRIGHT)); - localized_strings.SetString(L"cl", version_info->last_change()); + localized_strings->SetString(L"cl", version_info->last_change()); if (version_info->is_official_build()) { - localized_strings.SetString(L"official", + localized_strings->SetString(L"official", l10n_util::GetString(IDS_ABOUT_VERSION_OFFICIAL)); } else { - localized_strings.SetString(L"official", + localized_strings->SetString(L"official", l10n_util::GetString(IDS_ABOUT_VERSION_UNOFFICIAL)); } - localized_strings.SetString(L"useragent", + localized_strings->SetString(L"useragent", UTF8ToWide(webkit_glue::GetUserAgent(GURL()))); - static const StringPiece version_html( - ResourceBundle::GetSharedInstance().GetRawDataResource( + static const std::string version_html( + ResourceBundle::GetSharedInstance().GetDataResource( IDR_ABOUT_VERSION_HTML)); - return jstemplate_builder::GetI18nTemplateHtml( - version_html, &localized_strings); + std::string output = version_html; + jstemplate_builder::AppendJsonHtml(localized_strings, &output); + jstemplate_builder::AppendI18nTemplateSourceHtml(&output); + jstemplate_builder::AppendI18nTemplateProcessHtml(&output); + jstemplate_builder::AppendJsTemplateSourceHtml(&output); + jstemplate_builder::AppendJsTemplateProcessHtml("t", &output); + return output; } #ifdef CHROME_PERSONALIZATION @@ -537,7 +571,13 @@ void AboutSource::StartDataRequest(const std::string& path_raw, } else if (path == kStatsPath) { response = AboutStats(); } else if (path == kVersionPath || path.empty()) { - response = AboutVersion(); +#if defined(OS_CHROMEOS) + new ChromeOSAboutVersionHandler(this, request_id); + return; +#else + DictionaryValue value; + response = AboutVersion(&value); +#endif } else if (path == kCreditsPath) { response = AboutCredits(); } else if (path == kTermsPath) { @@ -690,10 +730,37 @@ void AboutMemoryHandler::OnDetailsAvailable() { std::string template_html = jstemplate_builder::GetTemplateHtml( memory_html, &root, "t" /* template root node id */); - AboutSource* src = static_cast<AboutSource*>(source_); - src->FinishDataRequest(template_html, request_id_); + source_->FinishDataRequest(template_html, request_id_); +} + +#if defined(OS_CHROMEOS) +// ChromeOSAboutVersionHandler ----------------------------------------------- + +ChromeOSAboutVersionHandler::ChromeOSAboutVersionHandler(AboutSource* source, + int request_id) + : source_(source), + request_id_(request_id) { + loader_.GetVersion(&consumer_, + NewCallback(this, &ChromeOSAboutVersionHandler::OnVersion)); } +void ChromeOSAboutVersionHandler::OnVersion( + ChromeOSVersionLoader::Handle handle, + std::string version) { + DictionaryValue localized_strings; + localized_strings.SetString(L"os_name", + l10n_util::GetString(IDS_PRODUCT_OS_NAME)); + localized_strings.SetString(L"os_version", UTF8ToWide(version)); + localized_strings.SetBoolean(L"is_chrome_os", true); + source_->FinishDataRequest(AboutVersion(&localized_strings), request_id_); + + // CancelableRequestProvider isn't happy when it's deleted and servicing a + // task, so we delay the deletion. + MessageLoop::current()->DeleteSoon(FROM_HERE, this); +} + +#endif + } // namespace // ----------------------------------------------------------------------------- diff --git a/chrome/browser/chromeos/chromeos_version_loader.cc b/chrome/browser/chromeos/chromeos_version_loader.cc new file mode 100644 index 0000000..1bb075e --- /dev/null +++ b/chrome/browser/chromeos/chromeos_version_loader.cc @@ -0,0 +1,76 @@ +// 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/browser/chromeos/chromeos_version_loader.h" + +#include "base/file_path.h" +#include "base/file_util.h" +#include "base/message_loop.h" +#include "base/string_util.h" +#include "base/thread.h" +#include "chrome/browser/browser_process.h" + +// Beginning of line we look for that gives version number. +static const char kPrefix[] = "GOOGLE_RELEASE="; + +// File to look for version number in. +static const char kPath[] = "/etc/lsb-release"; + +ChromeOSVersionLoader::ChromeOSVersionLoader() : backend_(new Backend()) { +} + +ChromeOSVersionLoader::Handle ChromeOSVersionLoader::GetVersion( + CancelableRequestConsumerBase* consumer, + ChromeOSVersionLoader::GetVersionCallback* callback) { + if (!g_browser_process->file_thread()) { + // This should only happen if Chrome is shutting down, so we don't do + // anything. + return 0; + } + + scoped_refptr<CancelableRequest<GetVersionCallback> > request( + new CancelableRequest<GetVersionCallback>(callback)); + AddRequest(request, consumer); + + g_browser_process->file_thread()->message_loop()->PostTask( + FROM_HERE, + NewRunnableMethod(backend_.get(), &Backend::GetVersion, request)); + return request->handle(); +} + +// static +std::string ChromeOSVersionLoader::ParseVersion(const std::string& contents) { + // The file contains lines such as: + // XXX=YYY + // AAA=ZZZ + // Split the lines and look for the one that starts with kPrefix. The version + // file is small, which is why we don't try and be tricky. + std::vector<std::string> lines; + SplitString(contents, '\n', &lines); + for (size_t i = 0; i < lines.size(); ++i) { + if (StartsWithASCII(lines[i], kPrefix, false)) { + std::string version = lines[i].substr(std::string(kPrefix).size()); + if (version.size() > 1 && version[0] == '"' && + version[version.size() - 1] == '"') { + // Trim trailing and leading quotes. + version = version.substr(1, version.size() - 2); + } + return version; + } + } + return std::string(); +} + +void ChromeOSVersionLoader::Backend::GetVersion( + scoped_refptr<GetVersionRequest> request) { + if (request->canceled()) + return; + + std::string version; + std::string contents; + if (file_util::ReadFileToString(FilePath(kPath), &contents)) + version = ParseVersion(contents); + request->ForwardResult(GetVersionCallback::TupleType(request->handle(), + version)); +} diff --git a/chrome/browser/chromeos/chromeos_version_loader.h b/chrome/browser/chromeos/chromeos_version_loader.h new file mode 100644 index 0000000..85047b0 --- /dev/null +++ b/chrome/browser/chromeos/chromeos_version_loader.h @@ -0,0 +1,63 @@ +// 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_BROWSER_CHROMEOS_CHROMEOS_VERSION_LOADER_H_ +#define CHROME_BROWSER_CHROMEOS_CHROMEOS_VERSION_LOADER_H_ + +#include "chrome/browser/cancelable_request.h" +#include "testing/gtest/include/gtest/gtest_prod.h" + +class FilePath; + +// ChromeOSVersionLoader loads the version of Chrome OS from the file system. +// Loading is done asynchronously on the file thread. Once loaded, +// ChromeOSVersionLoader callsback to a method of your choice with the version +// (or an empty string if the version couldn't be found). +// To use ChromeOSVersionLoader do the following: +// +// . In your class define a member field of type ChromeOSVersionLoader and +// CancelableRequestConsumerBase. +// . Define the callback method, something like: +// void OnGetChromeOSVersion(ChromeOSVersionLoader::Handle, +// std::string version); +// . When you want the version invoke: loader.GetVersion(&consumer, callback); +class ChromeOSVersionLoader : public CancelableRequestProvider { + public: + ChromeOSVersionLoader(); + + // Signature + typedef Callback2<Handle, std::string>::Type GetVersionCallback; + + typedef CancelableRequest<GetVersionCallback> GetVersionRequest; + + // Asynchronously requests the version. + Handle GetVersion(CancelableRequestConsumerBase* consumer, + GetVersionCallback* callback); + + private: + FRIEND_TEST(ChromeOSVersionLoaderTest, ParseVersion); + + // ChromeOSVersionLoader calls into the Backend on the file thread to load + // and extract the version. + class Backend : public base::RefCounted<Backend> { + public: + Backend() {} + + // Calls ParseVersion to get the version # and notifies request. + // This is invoked on the file thread. + void GetVersion(scoped_refptr<GetVersionRequest> request); + + private: + DISALLOW_COPY_AND_ASSIGN(Backend); + }; + + // Extracts the version from the file. + static std::string ParseVersion(const std::string& contents); + + scoped_refptr<Backend> backend_; + + DISALLOW_COPY_AND_ASSIGN(ChromeOSVersionLoader); +}; + +#endif // CHROME_BROWSER_CHROMEOS_CHROMEOS_VERSION_LOADER_H_ diff --git a/chrome/browser/chromeos/chromeos_version_loader_unittest.cc b/chrome/browser/chromeos/chromeos_version_loader_unittest.cc new file mode 100644 index 0000000..1b0bdd0 --- /dev/null +++ b/chrome/browser/chromeos/chromeos_version_loader_unittest.cc @@ -0,0 +1,24 @@ +// 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/browser/chromeos/chromeos_version_loader.h" + +#include "testing/gtest/include/gtest/gtest.h" + +typedef testing::Test ChromeOSVersionLoaderTest; + +static const char kTest1[] = "DIST_ID=1\nGOOGLE_RELEASE=0.2.3.3\nFOO=BAR"; +static const char kTest2[] = "DIST_ID=1\nGOOGLE_RELEASE=0.2.3.3"; +static const char kTest3[] = "GOOGLE_RELEASE=\"0.2.3.3\""; +static const char kTest4[] = "GOOGLE_RELEASE=\"\"\""; +static const char kTest5[] = "GOOGLE_RELEASE=\"\""; + +TEST_F(ChromeOSVersionLoaderTest, ParseVersion) { + EXPECT_EQ("0.2.3.3", ChromeOSVersionLoader::ParseVersion(kTest1)); + EXPECT_EQ("0.2.3.3", ChromeOSVersionLoader::ParseVersion(kTest2)); + EXPECT_EQ("0.2.3.3", ChromeOSVersionLoader::ParseVersion(kTest3)); + EXPECT_EQ("\"", ChromeOSVersionLoader::ParseVersion(kTest4)); + EXPECT_EQ(std::string(), ChromeOSVersionLoader::ParseVersion(kTest5)); + EXPECT_EQ(std::string(), ChromeOSVersionLoader::ParseVersion(std::string())); +} diff --git a/chrome/browser/gtk/options/options_window_gtk.cc b/chrome/browser/gtk/options/options_window_gtk.cc index 63f3306..4bc82b1 100644 --- a/chrome/browser/gtk/options/options_window_gtk.cc +++ b/chrome/browser/gtk/options/options_window_gtk.cc @@ -109,7 +109,7 @@ OptionsWindowGtk::OptionsWindowGtk(Profile* profile) GTK_NOTEBOOK(notebook_), (new SettingsPageView(profile_))->WrapInGtkWidget(), gtk_label_new( - l10n_util::GetStringUTF8(IDS_OPTIONS_SETTINGS_TAB_LABEL).c_str())); + l10n_util::GetStringUTF8(IDS_PRODUCT_OS_NAME).c_str())); #endif gtk_notebook_append_page( diff --git a/chrome/browser/resources/about_version.html b/chrome/browser/resources/about_version.html index 6a8489f..cec7b14 100644 --- a/chrome/browser/resources/about_version.html +++ b/chrome/browser/resources/about_version.html @@ -70,6 +70,9 @@ about:version template page <div id="copyright" i18n-content="copyright"></div> </div> <table id="inner" cellpadding="0" cellspacing="0" border="0"> + <tr jsdisplay="is_chrome_os"><td class="label" valign="top" id="os_name" i18n-content="os_name"></td> + <td class="version" id="os_version"><span i18n-content="os_version"></span></td> + </tr> <tr><td class="label" valign="top" id="name" i18n-content="name"></td> <td class="version" id="version"><span i18n-content="version"></span> (<span i18n-content="official"></span> <span i18n-content="cl"></span>)</td> </tr> diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index e96870d..3e23149 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -819,6 +819,8 @@ 'browser/chrome_plugin_host.h', 'browser/chrome_thread.cc', 'browser/chrome_thread.h', + 'browser/chromeos/chromeos_version_loader.cc', + 'browser/chromeos/chromeos_version_loader.h', 'browser/chromeos/compact_navigation_bar.cc', 'browser/chromeos/compact_navigation_bar.h', 'browser/chromeos/pipe_reader.cc', @@ -3939,6 +3941,7 @@ 'browser/debugger/devtools_remote_listen_socket_unittest.h', 'browser/child_process_security_policy_unittest.cc', 'browser/chrome_thread_unittest.cc', + 'browser/chromeos/chromeos_version_loader_unittest.cc', 'browser/chromeos/pipe_reader_unittest.cc', 'browser/chromeos/external_cookie_handler_unittest.cc', # It is safe to list */cocoa/* files in the "common" file list diff --git a/chrome/common/temp_scaffolding_stubs.cc b/chrome/common/temp_scaffolding_stubs.cc index 94f3260..4d8f364 100644 --- a/chrome/common/temp_scaffolding_stubs.cc +++ b/chrome/common/temp_scaffolding_stubs.cc @@ -218,6 +218,11 @@ MemoryDetails::MemoryDetails() { void MemoryDetails::StartFetch() { NOTIMPLEMENTED(); OnDetailsAvailable(); + + // When we get the real implementation this can be removed. The Release that + // ends up deleting this object is done as the result of the PostTask in + // CollectProcessData. + Release(); } #endif |