diff options
author | asargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-07 13:04:42 +0000 |
---|---|---|
committer | asargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-07 13:04:42 +0000 |
commit | 5e5d68bfec2b38170509e50551c91f9113edb160 (patch) | |
tree | 563f5baaf75bfaf935a1dbdf72b5353c048949fb /chrome/browser/extensions/api/runtime | |
parent | 5c022f213884ec4d03cedf6a5976dd8d754e8de9 (diff) | |
download | chromium_src-5e5d68bfec2b38170509e50551c91f9113edb160.zip chromium_src-5e5d68bfec2b38170509e50551c91f9113edb160.tar.gz chromium_src-5e5d68bfec2b38170509e50551c91f9113edb160.tar.bz2 |
Implementing the chrome.runtime.getPlatformInfo API
This is part of the support for multi-crx downloads from the webstore.
BUG=180402
Review URL: https://chromiumcodereview.appspot.com/14960002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@198703 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/api/runtime')
-rw-r--r-- | chrome/browser/extensions/api/runtime/runtime_api.cc | 53 | ||||
-rw-r--r-- | chrome/browser/extensions/api/runtime/runtime_api.h | 9 | ||||
-rw-r--r-- | chrome/browser/extensions/api/runtime/runtime_apitest.cc | 21 |
3 files changed, 83 insertions, 0 deletions
diff --git a/chrome/browser/extensions/api/runtime/runtime_api.cc b/chrome/browser/extensions/api/runtime/runtime_api.cc index 75c98c0..0a6d54b 100644 --- a/chrome/browser/extensions/api/runtime/runtime_api.cc +++ b/chrome/browser/extensions/api/runtime/runtime_api.cc @@ -14,10 +14,14 @@ #include "chrome/browser/extensions/updater/extension_updater.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" +#include "chrome/common/extensions/api/runtime.h" #include "chrome/common/extensions/background_info.h" #include "chrome/common/extensions/extension.h" +#include "chrome/common/omaha_query_params/omaha_query_params.h" #include "googleurl/src/gurl.h" +namespace GetPlatformInfo = extensions::api::runtime::GetPlatformInfo; + namespace extensions { namespace { @@ -264,4 +268,53 @@ void RuntimeRequestUpdateCheckFunction::ReplyUpdateFound( SendResponse(true); } +bool RuntimeGetPlatformInfoFunction::RunImpl() { + GetPlatformInfo::Results::PlatformInfo info; + + const char* os = chrome::OmahaQueryParams::getOS(); + if (strcmp(os, "mac") == 0) { + info.os = GetPlatformInfo::Results::PlatformInfo::OS_MAC_; + } else if (strcmp(os, "win") == 0) { + info.os = GetPlatformInfo::Results::PlatformInfo::OS_WIN_; + } else if (strcmp(os, "android") == 0) { + info.os = GetPlatformInfo::Results::PlatformInfo::OS_ANDROID_; + } else if (strcmp(os, "cros") == 0) { + info.os = GetPlatformInfo::Results::PlatformInfo::OS_CROS_; + } else if (strcmp(os, "linux") == 0) { + info.os = GetPlatformInfo::Results::PlatformInfo::OS_LINUX_; + } else if (strcmp(os, "openbsd") == 0) { + info.os = GetPlatformInfo::Results::PlatformInfo::OS_OPENBSD_; + } else { + NOTREACHED(); + return false; + } + + const char* arch = chrome::OmahaQueryParams::getArch(); + if (strcmp(arch, "arm") == 0) { + info.arch = GetPlatformInfo::Results::PlatformInfo::ARCH_ARM; + } else if (strcmp(arch, "x86") == 0) { + info.arch = GetPlatformInfo::Results::PlatformInfo::ARCH_X86_32; + } else if (strcmp(arch, "x64") == 0) { + info.arch = GetPlatformInfo::Results::PlatformInfo::ARCH_X86_64; + } else { + NOTREACHED(); + return false; + } + + const char* nacl_arch = chrome::OmahaQueryParams::getNaclArch(); + if (strcmp(nacl_arch, "arm") == 0) { + info.nacl_arch = GetPlatformInfo::Results::PlatformInfo::NACL_ARCH_ARM; + } else if (strcmp(nacl_arch, "x86-32") == 0) { + info.nacl_arch = GetPlatformInfo::Results::PlatformInfo::NACL_ARCH_X86_32; + } else if (strcmp(nacl_arch, "x86-64") == 0) { + info.nacl_arch = GetPlatformInfo::Results::PlatformInfo::NACL_ARCH_X86_64; + } else { + NOTREACHED(); + return false; + } + + results_ = GetPlatformInfo::Results::Create(info); + return true; +} + } // namespace extensions diff --git a/chrome/browser/extensions/api/runtime/runtime_api.h b/chrome/browser/extensions/api/runtime/runtime_api.h index 97bc65de..f04ac65 100644 --- a/chrome/browser/extensions/api/runtime/runtime_api.h +++ b/chrome/browser/extensions/api/runtime/runtime_api.h @@ -86,6 +86,15 @@ class RuntimeRequestUpdateCheckFunction : public AsyncExtensionFunction, bool did_reply_; }; +class RuntimeGetPlatformInfoFunction : public SyncExtensionFunction { + public: + DECLARE_EXTENSION_FUNCTION("runtime.getPlatformInfo", + RUNTIME_GETPLATFORMINFO); + protected: + virtual ~RuntimeGetPlatformInfoFunction() {} + virtual bool RunImpl() OVERRIDE; +}; + } // namespace extensions #endif // CHROME_BROWSER_EXTENSIONS_API_RUNTIME_RUNTIME_API_H_ diff --git a/chrome/browser/extensions/api/runtime/runtime_apitest.cc b/chrome/browser/extensions/api/runtime/runtime_apitest.cc index 7261858..79305eb 100644 --- a/chrome/browser/extensions/api/runtime/runtime_apitest.cc +++ b/chrome/browser/extensions/api/runtime/runtime_apitest.cc @@ -2,7 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "chrome/browser/extensions/api/runtime/runtime_api.h" #include "chrome/browser/extensions/extension_apitest.h" +#include "chrome/browser/extensions/extension_function_test_utils.h" #include "chrome/test/base/ui_test_utils.h" // Tests the privileged components of chrome.runtime. @@ -22,3 +24,22 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeRuntimeUnprivileged) { test_server()->GetURL("webpage.html")); EXPECT_TRUE(catcher.GetNextResult()) << message_; } + +namespace extensions { + +IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeRuntimeGetPlatformInfo) { + scoped_ptr<base::Value> result( + extension_function_test_utils::RunFunctionAndReturnSingleResult( + new RuntimeGetPlatformInfoFunction(), + "[]", + browser())); + ASSERT_TRUE(result.get() != NULL); + base::DictionaryValue* dict = + extension_function_test_utils::ToDictionary(result.get()); + ASSERT_TRUE(dict != NULL); + EXPECT_TRUE(dict->HasKey("os")); + EXPECT_TRUE(dict->HasKey("arch")); + EXPECT_TRUE(dict->HasKey("nacl_arch")); +} + +} // namespace extensions |