[email protected] | 61fcb16 | 2012-09-04 23:08:54 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "webkit/plugins/npapi/plugin_utils.h" |
| 6 | |
| 7 | #include <algorithm> |
| 8 | |
| 9 | #include "base/string_split.h" |
| 10 | #include "base/string_util.h" |
| 11 | #include "base/version.h" |
| 12 | |
| 13 | namespace webkit { |
| 14 | namespace npapi { |
| 15 | |
| 16 | void CreateVersionFromString(const string16& version_string, |
| 17 | Version* parsed_version) { |
| 18 | // Remove spaces and ')' from the version string, |
| 19 | // Replace any instances of 'r', ',' or '(' with a dot. |
| 20 | std::string version = UTF16ToASCII(version_string); |
| 21 | RemoveChars(version, ") ", &version); |
| 22 | std::replace(version.begin(), version.end(), 'd', '.'); |
| 23 | std::replace(version.begin(), version.end(), 'r', '.'); |
| 24 | std::replace(version.begin(), version.end(), ',', '.'); |
| 25 | std::replace(version.begin(), version.end(), '(', '.'); |
| 26 | std::replace(version.begin(), version.end(), '_', '.'); |
| 27 | |
| 28 | // Remove leading zeros from each of the version components. |
| 29 | std::string no_leading_zeros_version; |
| 30 | std::vector<std::string> numbers; |
| 31 | base::SplitString(version, '.', &numbers); |
| 32 | for (size_t i = 0; i < numbers.size(); ++i) { |
| 33 | size_t n = numbers[i].size(); |
| 34 | size_t j = 0; |
| 35 | while (j < n && numbers[i][j] == '0') { |
| 36 | ++j; |
| 37 | } |
| 38 | no_leading_zeros_version += (j < n) ? numbers[i].substr(j) : "0"; |
| 39 | if (i != numbers.size() - 1) { |
| 40 | no_leading_zeros_version += "."; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | *parsed_version = Version(no_leading_zeros_version); |
| 45 | } |
| 46 | |
[email protected] | 1b51720a | 2012-12-19 17:16:10 | [diff] [blame] | 47 | bool NPAPIPluginsSupported() { |
| 48 | #if defined(OS_WIN) || defined(OS_MACOSX) || (defined(OS_LINUX) && !defined(USE_AURA)) |
| 49 | return true; |
| 50 | #else |
| 51 | return false; |
| 52 | #endif |
| 53 | } |
| 54 | |
[email protected] | 61fcb16 | 2012-09-04 23:08:54 | [diff] [blame] | 55 | } // namespace npapi |
| 56 | } // namespace webkit |