Add window.gc back to Smoothness.WillNavigateToPageHook
[chromium-blink-merge.git] / content / public / common / webplugininfo.cc
blobd12dfd744ec279c7a3ea8ed4f64ec30288d92bce
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.
5 #include "content/public/common/webplugininfo.h"
7 #include <algorithm>
9 #include "base/logging.h"
10 #include "base/strings/string_split.h"
11 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "base/version.h"
15 namespace content {
17 WebPluginMimeType::WebPluginMimeType() {}
19 WebPluginMimeType::WebPluginMimeType(const std::string& m,
20 const std::string& f,
21 const std::string& d)
22 : mime_type(m),
23 file_extensions(),
24 description(base::ASCIIToUTF16(d)) {
25 file_extensions.push_back(f);
28 WebPluginMimeType::~WebPluginMimeType() {}
30 WebPluginInfo::WebPluginInfo()
31 : type(PLUGIN_TYPE_NPAPI),
32 pepper_permissions(0) {
35 WebPluginInfo::WebPluginInfo(const WebPluginInfo& rhs)
36 : name(rhs.name),
37 path(rhs.path),
38 version(rhs.version),
39 desc(rhs.desc),
40 mime_types(rhs.mime_types),
41 type(rhs.type),
42 pepper_permissions(rhs.pepper_permissions) {
45 WebPluginInfo::~WebPluginInfo() {}
47 WebPluginInfo& WebPluginInfo::operator=(const WebPluginInfo& rhs) {
48 name = rhs.name;
49 path = rhs.path;
50 version = rhs.version;
51 desc = rhs.desc;
52 mime_types = rhs.mime_types;
53 type = rhs.type;
54 pepper_permissions = rhs.pepper_permissions;
55 return *this;
58 WebPluginInfo::WebPluginInfo(const base::string16& fake_name,
59 const base::FilePath& fake_path,
60 const base::string16& fake_version,
61 const base::string16& fake_desc)
62 : name(fake_name),
63 path(fake_path),
64 version(fake_version),
65 desc(fake_desc),
66 mime_types(),
67 type(PLUGIN_TYPE_NPAPI),
68 pepper_permissions(0) {
71 void WebPluginInfo::CreateVersionFromString(
72 const base::string16& version_string,
73 base::Version* parsed_version) {
74 // Remove spaces and ')' from the version string,
75 // Replace any instances of 'r', ',' or '(' with a dot.
76 std::string version = base::UTF16ToASCII(version_string);
77 base::RemoveChars(version, ") ", &version);
78 std::replace(version.begin(), version.end(), 'd', '.');
79 std::replace(version.begin(), version.end(), 'r', '.');
80 std::replace(version.begin(), version.end(), ',', '.');
81 std::replace(version.begin(), version.end(), '(', '.');
82 std::replace(version.begin(), version.end(), '_', '.');
84 // Remove leading zeros from each of the version components.
85 std::string no_leading_zeros_version;
86 std::vector<std::string> numbers = base::SplitString(
87 version, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
88 for (size_t i = 0; i < numbers.size(); ++i) {
89 size_t n = numbers[i].size();
90 size_t j = 0;
91 while (j < n && numbers[i][j] == '0') {
92 ++j;
94 no_leading_zeros_version += (j < n) ? numbers[i].substr(j) : "0";
95 if (i != numbers.size() - 1) {
96 no_leading_zeros_version += ".";
100 *parsed_version = Version(no_leading_zeros_version);
103 } // namespace content