summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/extensions/convert_user_script.cc8
-rw-r--r--chrome/browser/extensions/convert_user_script_unittest.cc2
-rw-r--r--chrome/browser/extensions/user_script_master.cc6
-rw-r--r--chrome/common/extensions/user_script.h9
-rw-r--r--chrome/test/data/extensions/user_script_basic.user.js1
5 files changed, 24 insertions, 2 deletions
diff --git a/chrome/browser/extensions/convert_user_script.cc b/chrome/browser/extensions/convert_user_script.cc
index 404f2af..95dab21 100644
--- a/chrome/browser/extensions/convert_user_script.cc
+++ b/chrome/browser/extensions/convert_user_script.cc
@@ -71,8 +71,14 @@ Extension* ConvertUserScriptToExtension(const FilePath& user_script_path,
else
root->SetString(keys::kName, original_url.ExtractFileName());
+ // Not all scripts have a version, but we need one. Default to 1.0 if it is
+ // missing.
+ if (!script.version().empty())
+ root->SetString(keys::kVersion, script.version());
+ else
+ root->SetString(keys::kVersion, "1.0");
+
root->SetString(keys::kDescription, script.description());
- root->SetString(keys::kVersion, "1.0");
root->SetString(keys::kPublicKey, key);
root->SetBoolean(keys::kConvertedFromUserScript, true);
diff --git a/chrome/browser/extensions/convert_user_script_unittest.cc b/chrome/browser/extensions/convert_user_script_unittest.cc
index 2c9ddab..de1743a 100644
--- a/chrome/browser/extensions/convert_user_script_unittest.cc
+++ b/chrome/browser/extensions/convert_user_script_unittest.cc
@@ -29,7 +29,7 @@ TEST(ExtensionFromUserScript, Basic) {
// Validate generated extension metadata.
EXPECT_EQ("My user script", extension->name());
- EXPECT_EQ("1.0", extension->VersionString());
+ EXPECT_EQ("2.2.2", extension->VersionString());
EXPECT_EQ("Does totally awesome stuff.", extension->description());
EXPECT_EQ("IhCFCg9PMQTAcJdc9ytUP99WME+4yh6aMnM1uupkovo=",
extension->public_key());
diff --git a/chrome/browser/extensions/user_script_master.cc b/chrome/browser/extensions/user_script_master.cc
index 960bc49..608f9db 100644
--- a/chrome/browser/extensions/user_script_master.cc
+++ b/chrome/browser/extensions/user_script_master.cc
@@ -14,6 +14,7 @@
#include "base/stl_util-inl.h"
#include "base/string_util.h"
#include "base/thread.h"
+#include "base/version.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/browser/profile.h"
@@ -60,6 +61,7 @@ bool UserScriptMaster::ScriptReloader::ParseMetadataHeader(
static const base::StringPiece kUserScriptEng("// ==/UserScript==");
static const base::StringPiece kNamespaceDeclaration("// @namespace");
static const base::StringPiece kNameDeclaration("// @name");
+ static const base::StringPiece kVersionDeclaration("// @version");
static const base::StringPiece kDescriptionDeclaration("// @description");
static const base::StringPiece kIncludeDeclaration("// @include");
static const base::StringPiece kExcludeDeclaration("// @exclude");
@@ -98,6 +100,10 @@ bool UserScriptMaster::ScriptReloader::ParseMetadataHeader(
script->set_name_space(value);
} else if (GetDeclarationValue(line, kNameDeclaration, &value)) {
script->set_name(value);
+ } else if (GetDeclarationValue(line, kVersionDeclaration, &value)) {
+ scoped_ptr<Version> version(Version::GetVersionFromString(value));
+ if (version.get())
+ script->set_version(version->GetString());
} else if (GetDeclarationValue(line, kDescriptionDeclaration, &value)) {
script->set_description(value);
} else if (GetDeclarationValue(line, kMatchDeclaration, &value)) {
diff --git a/chrome/common/extensions/user_script.h b/chrome/common/extensions/user_script.h
index ed84009..6bf30ee 100644
--- a/chrome/common/extensions/user_script.h
+++ b/chrome/common/extensions/user_script.h
@@ -113,6 +113,11 @@ class UserScript {
const std::string& name() const { return name_; }
void set_name(const std::string& name) { name_ = name; }
+ const std::string& version() const { return version_; }
+ void set_version(const std::string& version) {
+ version_ = version;
+ }
+
const std::string& description() const { return description_; }
void set_description(const std::string& description) {
description_ = description;
@@ -194,6 +199,10 @@ class UserScript {
// A longer description. Only used when parsing Greasemonkey-style scripts.
std::string description_;
+ // A version number of the script. Only used when parsing Greasemonkey-style
+ // scripts.
+ std::string version_;
+
// Greasemonkey-style globs that determine pages to inject the script into.
// These are only used with standalone scripts.
std::vector<std::string> globs_;
diff --git a/chrome/test/data/extensions/user_script_basic.user.js b/chrome/test/data/extensions/user_script_basic.user.js
index 015681a..65ca67b 100644
--- a/chrome/test/data/extensions/user_script_basic.user.js
+++ b/chrome/test/data/extensions/user_script_basic.user.js
@@ -1,5 +1,6 @@
// ==UserScript==
// @name My user script
+// @version 2.2.2
// @namespace http://www.google.com
// @description Does totally awesome stuff.
// @include http://www.google.com/*