summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/common')
-rw-r--r--chrome/common/extensions/docs/examples/extensions/maps_app/manifest.json13
-rw-r--r--chrome/common/extensions/extension.cc113
-rw-r--r--chrome/common/extensions/extension.h3
-rw-r--r--chrome/common/extensions/extension_constants.cc22
-rw-r--r--chrome/common/extensions/extension_constants.h12
-rw-r--r--chrome/common/extensions/extension_extent.cc19
-rw-r--r--chrome/common/extensions/extension_extent.h20
-rw-r--r--chrome/common/extensions/extension_extent_unittest.cc42
-rw-r--r--chrome/common/extensions/extension_manifests_unittest.cc50
-rw-r--r--chrome/common/extensions/url_pattern.cc19
-rw-r--r--chrome/common/extensions/url_pattern.h16
-rw-r--r--chrome/common/render_messages.h16
12 files changed, 204 insertions, 141 deletions
diff --git a/chrome/common/extensions/docs/examples/extensions/maps_app/manifest.json b/chrome/common/extensions/docs/examples/extensions/maps_app/manifest.json
index d402a74..7ac6a16 100644
--- a/chrome/common/extensions/docs/examples/extensions/maps_app/manifest.json
+++ b/chrome/common/extensions/docs/examples/extensions/maps_app/manifest.json
@@ -2,13 +2,12 @@
"name": "Google Maps",
"version": "3",
"icons": { "24": "24.png", "128": "128.png" },
- "app": {
- "urls": [
- "http://maps.google.com/"
- ],
- "launch": {
- "web_url": "http://maps.google.com/"
- }
+ "launch": {
+ "web_url": "http://maps.google.com/"
},
"permissions": ["geolocation"],
+ "web_content": {
+ "enabled": true,
+ "origin": "http://maps.google.com"
+ }
}
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc
index 97ee0201..3631af0 100644
--- a/chrome/common/extensions/extension.cc
+++ b/chrome/common/extensions/extension.cc
@@ -532,43 +532,77 @@ bool Extension::LoadIsApp(const DictionaryValue* manifest,
return true;
}
-bool Extension::LoadWebURLs(const DictionaryValue* manifest,
- std::string* error) {
+bool Extension::LoadWebOrigin(const DictionaryValue* manifest,
+ std::string* error) {
Value* temp = NULL;
- if (!manifest->Get(keys::kWebURLs, &temp))
+ if (!manifest->Get(keys::kWebOrigin, &temp))
return true;
- if (temp->GetType() != Value::TYPE_LIST) {
- *error = errors::kInvalidWebURLs;
+ // Check datatype.
+ std::string origin_string;
+ if (!temp->GetAsString(&origin_string)) {
+ *error = errors::kInvalidWebOrigin;
return false;
}
- ListValue* pattern_list = static_cast<ListValue*>(temp);
- for (size_t i = 0; i < pattern_list->GetSize(); ++i) {
- std::string pattern_string;
- if (!pattern_list->GetString(i, &pattern_string)) {
- *error = ExtensionErrorUtils::FormatErrorMessage(
- errors::kInvalidWebURL, UintToString(i));
- return false;
- }
+ // Origin must be a valid URL.
+ GURL origin_gurl(origin_string);
+ if (!origin_gurl.is_valid() || origin_gurl.is_empty()) {
+ *error = errors::kInvalidWebOrigin;
+ return false;
+ }
- URLPattern pattern;
- if (!pattern.Parse(pattern_string)) {
+ // Origins can only be http or https.
+ if (!origin_gurl.SchemeIs(chrome::kHttpScheme) &&
+ !origin_gurl.SchemeIs(chrome::kHttpsScheme)) {
+ *error = errors::kInvalidWebOrigin;
+ return false;
+ }
+
+ // Check that the origin doesn't include any extraneous information.
+ if (origin_gurl.GetOrigin() != origin_gurl) {
+ *error = errors::kInvalidWebOrigin;
+ return false;
+ }
+
+ web_extent_.set_origin(origin_gurl);
+ return true;
+}
+
+bool Extension::LoadWebPaths(const DictionaryValue* manifest,
+ std::string* error) {
+ Value* temp = NULL;
+ if (!manifest->Get(keys::kWebPaths, &temp))
+ return true;
+
+ // Check datatype.
+ if (!temp->IsType(Value::TYPE_LIST)) {
+ *error = errors::kInvalidWebPaths;
+ return false;
+ }
+
+ ListValue* web_paths = static_cast<ListValue*>(temp);
+ for (size_t i = 0; i < web_paths->GetSize(); ++i) {
+ // Get item and check datatype.
+ std::string item;
+ if (!web_paths->GetString(i, &item) || item.empty()) {
*error = ExtensionErrorUtils::FormatErrorMessage(
- errors::kInvalidWebURL, UintToString(i));
+ errors::kInvalidWebPath, IntToString(i));
return false;
}
- // We do not allow authors to put wildcards in their paths. Instead, we
- // imply one at the end.
- if (pattern.path().find('*') != std::string::npos) {
+ // Ensure the path is a valid relative URL by resolving it against the
+ // extension root.
+ // TODO(aa): This is hacky. Is there another way to know whether a string
+ // is a valid relative URL?
+ GURL resolved = extension_url_.Resolve(item);
+ if (!resolved.is_valid() || resolved.GetOrigin() != extension_url_) {
*error = ExtensionErrorUtils::FormatErrorMessage(
- errors::kInvalidWebURL, UintToString(i));
+ errors::kInvalidWebPath, IntToString(i));
return false;
}
- pattern.set_path(pattern.path() + '*');
- web_extent_.AddPattern(pattern);
+ web_extent_.add_path(item);
}
return true;
@@ -578,8 +612,8 @@ bool Extension::LoadLaunchURL(const DictionaryValue* manifest,
std::string* error) {
Value* temp = NULL;
- // launch URL can be either local (to chrome-extension:// root) or an absolute
- // web URL.
+ // launch URL can be either local (to chrome-extension:// root) or web (either
+ // relative to the origin, or an absolute URL).
if (manifest->Get(keys::kLaunchLocalPath, &temp)) {
if (manifest->Get(keys::kLaunchWebURL, NULL)) {
*error = errors::kLaunchPathAndURLAreExclusive;
@@ -607,8 +641,8 @@ bool Extension::LoadLaunchURL(const DictionaryValue* manifest,
return false;
}
- // Ensure the launch URL is a valid absolute URL.
- if (!GURL(launch_url).is_valid()) {
+ // Ensure the launch URL is a valid relative or absolute URL.
+ if (!extension_url_.Resolve(launch_url).is_valid()) {
*error = errors::kInvalidLaunchWebURL;
return false;
}
@@ -619,16 +653,6 @@ bool Extension::LoadLaunchURL(const DictionaryValue* manifest,
return false;
}
- // If there is no extent, we default the extent based on the launch URL.
- if (web_extent_.is_empty() && !launch_web_url_.empty()) {
- GURL launch_url(launch_web_url_);
- URLPattern pattern;
- pattern.set_scheme(launch_url.scheme());
- pattern.set_host(launch_url.host());
- pattern.set_path("/*");
- web_extent_.AddPattern(pattern);
- }
-
return true;
}
@@ -1455,7 +1479,8 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key,
}
if (!LoadIsApp(manifest_value_.get(), error) ||
- !LoadWebURLs(manifest_value_.get(), error) ||
+ !LoadWebOrigin(manifest_value_.get(), error) ||
+ !LoadWebPaths(manifest_value_.get(), error) ||
!LoadLaunchURL(manifest_value_.get(), error) ||
!LoadLaunchContainer(manifest_value_.get(), error) ||
!LoadLaunchFullscreen(manifest_value_.get(), error)) {
@@ -1532,10 +1557,18 @@ std::set<FilePath> Extension::GetBrowserImages() {
}
GURL Extension::GetFullLaunchURL() const {
- if (!launch_local_path_.empty())
+ if (!launch_local_path_.empty()) {
return extension_url_.Resolve(launch_local_path_);
- else
- return GURL(launch_web_url_);
+ } else if (!launch_web_url_.empty()) {
+ // If there is a web origin, we interpret the launch URL relatively to that.
+ // Otherwise, hopefully it was an absolute URL.
+ if (web_extent_.origin().is_valid())
+ return web_extent_.origin().Resolve(launch_web_url_);
+ else
+ return GURL(launch_web_url_);
+ } else {
+ return GURL();
+ }
}
bool Extension::GetBackgroundPageReady() {
diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h
index 8748deb..0d4c10a 100644
--- a/chrome/common/extensions/extension.h
+++ b/chrome/common/extensions/extension.h
@@ -397,7 +397,8 @@ class Extension {
// Helpers to load various chunks of the manifest.
bool LoadIsApp(const DictionaryValue* manifest, std::string* error);
- bool LoadWebURLs(const DictionaryValue* manifest, std::string* error);
+ bool LoadWebOrigin(const DictionaryValue* manifest, std::string* error);
+ bool LoadWebPaths(const DictionaryValue* manifest, std::string* error);
bool LoadLaunchContainer(const DictionaryValue* manifest, std::string* error);
bool LoadLaunchFullscreen(const DictionaryValue* manifest,
std::string* error);
diff --git a/chrome/common/extensions/extension_constants.cc b/chrome/common/extensions/extension_constants.cc
index e4f368a..423d491 100644
--- a/chrome/common/extensions/extension_constants.cc
+++ b/chrome/common/extensions/extension_constants.cc
@@ -17,9 +17,7 @@ const wchar_t* kCss = L"css";
const wchar_t* kCurrentLocale = L"current_locale";
const wchar_t* kDefaultLocale = L"default_locale";
const wchar_t* kDescription = L"description";
-const wchar_t* kExcludeGlobs = L"exclude_globs";
const wchar_t* kIcons = L"icons";
-const wchar_t* kIncludeGlobs = L"include_globs";
const wchar_t* kJs = L"js";
const wchar_t* kLaunch = L"app.launch";
const wchar_t* kLaunchContainer = L"app.launch.container";
@@ -30,8 +28,9 @@ const wchar_t* kLaunchWebURL = L"app.launch.web_url";
const wchar_t* kLaunchWidth = L"app.launch.width";
const wchar_t* kMatches = L"matches";
const wchar_t* kMinimumChromeVersion = L"minimum_chrome_version";
+const wchar_t* kIncludeGlobs = L"include_globs";
+const wchar_t* kExcludeGlobs = L"exclude_globs";
const wchar_t* kName = L"name";
-const wchar_t* kOmniboxKeyword = L"omnibox_keyword";
const wchar_t* kPageActionId = L"id";
const wchar_t* kPageAction = L"page_action";
const wchar_t* kPageActions = L"page_actions";
@@ -62,7 +61,10 @@ const wchar_t* kType = L"type";
const wchar_t* kVersion = L"version";
const wchar_t* kUpdateURL = L"update_url";
const wchar_t* kOptionsPage = L"options_page";
-const wchar_t* kWebURLs = L"app.urls";
+const wchar_t* kWebContent = L"app.web_content";
+const wchar_t* kWebOrigin = L"app.web_content.origin";
+const wchar_t* kWebPaths = L"app.web_content.paths";
+const wchar_t* kOmniboxKeyword = L"omnibox_keyword";
} // namespace extension_manifest_keys
namespace extension_manifest_values {
@@ -216,10 +218,14 @@ const char* kInvalidThemeTints =
"Invalid value for theme images - tints must be decimal numbers.";
const char* kInvalidUpdateURL =
"Invalid value for update url: '[*]'.";
-const char* kInvalidWebURLs =
- "Invalid value for 'app.urls'.";
-const char* kInvalidWebURL =
- "Invalid value for 'app.urls[*]'.";
+const char* kInvalidWebContentEnabled =
+ "Invalid value for 'app.web_content.enabled'.";
+const char* kInvalidWebOrigin =
+ "Invalid value for 'app.web_content.origin'.";
+const char* kInvalidWebPaths =
+ "Invalid value for 'app.web_content.paths'.";
+const char* kInvalidWebPath =
+ "Invalid value for 'app.web_contents.paths[*]'.";
const char* kInvalidDefaultLocale =
"Invalid value for default locale - locale name must be a string.";
const char* kOneUISurfaceOnly =
diff --git a/chrome/common/extensions/extension_constants.h b/chrome/common/extensions/extension_constants.h
index a2a972b..b7f9ec8 100644
--- a/chrome/common/extensions/extension_constants.h
+++ b/chrome/common/extensions/extension_constants.h
@@ -32,7 +32,6 @@ namespace extension_manifest_keys {
extern const wchar_t* kJs;
extern const wchar_t* kMatches;
extern const wchar_t* kName;
- extern const wchar_t* kOmniboxKeyword;
extern const wchar_t* kPageActionId;
extern const wchar_t* kPageAction;
extern const wchar_t* kPageActions;
@@ -63,8 +62,11 @@ namespace extension_manifest_keys {
extern const wchar_t* kVersion;
extern const wchar_t* kUpdateURL;
extern const wchar_t* kOptionsPage;
+ extern const wchar_t* kWebContent;
extern const wchar_t* kWebLaunchUrl;
- extern const wchar_t* kWebURLs;
+ extern const wchar_t* kWebOrigin;
+ extern const wchar_t* kWebPaths;
+ extern const wchar_t* kOmniboxKeyword;
} // namespace extension_manifest_keys
// Some values expected in manifests.
@@ -142,8 +144,10 @@ namespace extension_manifest_errors {
extern const char* kInvalidThemeImages;
extern const char* kInvalidThemeColors;
extern const char* kInvalidThemeTints;
- extern const char* kInvalidWebURLs;
- extern const char* kInvalidWebURL;
+ extern const char* kInvalidWebContentEnabled;
+ extern const char* kInvalidWebOrigin;
+ extern const char* kInvalidWebPaths;
+ extern const char* kInvalidWebPath;
extern const char* kOneUISurfaceOnly;
extern const char* kThemesCannotContainExtensions;
extern const char* kManifestParseError;
diff --git a/chrome/common/extensions/extension_extent.cc b/chrome/common/extensions/extension_extent.cc
index b479c5b..f716291 100644
--- a/chrome/common/extensions/extension_extent.cc
+++ b/chrome/common/extensions/extension_extent.cc
@@ -4,11 +4,24 @@
#include "chrome/common/extensions/extension_extent.h"
+#include "base/string_util.h"
+
bool ExtensionExtent::ContainsURL(const GURL& url) const {
- for (PatternList::const_iterator pattern = patterns_.begin();
- pattern != patterns_.end(); ++pattern) {
- if (pattern->MatchesUrl(url))
+ if (origin_.is_empty() || !url.is_valid())
+ return false;
+
+ if (url.GetOrigin() != origin_)
+ return false;
+
+ if (paths_.empty())
+ return true;
+
+ for (size_t i = 0; i < paths_.size(); ++i) {
+ if (StartsWithASCII(url.path(),
+ std::string("/") + paths_[i],
+ false)) { // not case sensitive
return true;
+ }
}
return false;
diff --git a/chrome/common/extensions/extension_extent.h b/chrome/common/extensions/extension_extent.h
index df8d02d..187303d 100644
--- a/chrome/common/extensions/extension_extent.h
+++ b/chrome/common/extensions/extension_extent.h
@@ -8,25 +8,27 @@
#include <string>
#include <vector>
-#include "chrome/common/extensions/url_pattern.h"
#include "googleurl/src/gurl.h"
// Represents the set of URLs an extension uses for web content.
class ExtensionExtent {
public:
- typedef std::vector<URLPattern> PatternList;
+ const std::vector<std::string>& paths() const { return paths_; }
+ void add_path(const std::string& val) { paths_.push_back(val); }
+ void clear_paths() { paths_.clear(); }
- bool is_empty() const { return patterns_.empty(); }
-
- const PatternList& patterns() const { return patterns_; }
- void AddPattern(const URLPattern& pattern) { patterns_.push_back(pattern); }
- void ClearPaths() { patterns_.clear(); }
+ const GURL& origin() const { return origin_; }
+ void set_origin(const GURL& val) { origin_ = val; }
bool ContainsURL(const GURL& url) const;
private:
- // The list of URL patterns that comprise the extent.
- PatternList patterns_;
+ // The security origin (scheme+host+port) of the extent.
+ GURL origin_;
+
+ // A set of path prefixes that further restrict the set of valid URLs below
+ // origin_. This may be empty.
+ std::vector<std::string> paths_;
};
#endif // CHROME_COMMON_EXTENSIONS_EXTENSION_EXTENT_H_
diff --git a/chrome/common/extensions/extension_extent_unittest.cc b/chrome/common/extensions/extension_extent_unittest.cc
index 41f2d15..4e308fa 100644
--- a/chrome/common/extensions/extension_extent_unittest.cc
+++ b/chrome/common/extensions/extension_extent_unittest.cc
@@ -14,22 +14,44 @@ TEST(ExtensionExtentTest, Empty) {
EXPECT_FALSE(extent.ContainsURL(GURL("invalid")));
}
-TEST(ExtensionExtentTest, One) {
+TEST(ExtensionExtentTest, OriginOnly) {
ExtensionExtent extent;
- extent.AddPattern(*URLPattern::CreateFromString("http://www.google.com/*"));
+ extent.set_origin(GURL("http://www.google.com/"));
EXPECT_TRUE(extent.ContainsURL(GURL("http://www.google.com/")));
- EXPECT_TRUE(extent.ContainsURL(GURL("http://www.google.com/monkey")));
+ EXPECT_TRUE(extent.ContainsURL(GURL("http://www.google.com/foo")));
+ EXPECT_TRUE(extent.ContainsURL(GURL("http://www.google.com/foobar")));
+ EXPECT_TRUE(extent.ContainsURL(GURL("http://www.google.com/foo/bar")));
+ EXPECT_TRUE(extent.ContainsURL(GURL("http://www.google.com/?stuff#here")));
+
EXPECT_FALSE(extent.ContainsURL(GURL("https://www.google.com/")));
- EXPECT_FALSE(extent.ContainsURL(GURL("https://www.microsoft.com/")));
+ EXPECT_FALSE(extent.ContainsURL(GURL("http://www.google.com:8080/")));
}
-TEST(ExtensionExtentTest, Two) {
+TEST(ExtensionExtentTest, OriginAndOnePath) {
ExtensionExtent extent;
- extent.AddPattern(*URLPattern::CreateFromString("http://www.google.com/*"));
- extent.AddPattern(*URLPattern::CreateFromString("http://www.yahoo.com/*"));
+ extent.set_origin(GURL("http://www.google.com/"));
+ extent.add_path("foo");
+
+ EXPECT_FALSE(extent.ContainsURL(GURL("http://www.google.com/")));
+ EXPECT_FALSE(extent.ContainsURL(GURL("http://www.google.com/fo")));
+
+ EXPECT_TRUE(extent.ContainsURL(GURL("http://www.google.com/foo")));
+ EXPECT_TRUE(extent.ContainsURL(GURL("http://www.google.com/FOO")));
+ EXPECT_TRUE(extent.ContainsURL(GURL("http://www.google.com/foobar")));
+ EXPECT_TRUE(extent.ContainsURL(GURL("http://www.google.com/foo/bar")));
+}
+
+TEST(ExtensionExtentTest, OriginAndTwoPaths) {
+ ExtensionExtent extent;
+ extent.set_origin(GURL("http://www.google.com/"));
+ extent.add_path("foo");
+ extent.add_path("hot");
+
+ EXPECT_FALSE(extent.ContainsURL(GURL("http://www.google.com/monkey")));
- EXPECT_TRUE(extent.ContainsURL(GURL("http://www.google.com/monkey")));
- EXPECT_TRUE(extent.ContainsURL(GURL("http://www.yahoo.com/monkey")));
- EXPECT_FALSE(extent.ContainsURL(GURL("https://www.apple.com/monkey")));
+ EXPECT_TRUE(extent.ContainsURL(GURL("http://www.google.com/foo")));
+ EXPECT_TRUE(extent.ContainsURL(GURL("http://www.google.com/hot")));
+ EXPECT_TRUE(extent.ContainsURL(GURL("http://www.google.com/foobar")));
+ EXPECT_TRUE(extent.ContainsURL(GURL("http://www.google.com/hotdog")));
}
diff --git a/chrome/common/extensions/extension_manifests_unittest.cc b/chrome/common/extensions/extension_manifests_unittest.cc
index f91fdef..21f38537 100644
--- a/chrome/common/extensions/extension_manifests_unittest.cc
+++ b/chrome/common/extensions/extension_manifests_unittest.cc
@@ -87,34 +87,35 @@ TEST_F(ManifestTest, AppsDisabledByDefault) {
TEST_F(ManifestTest, ValidApp) {
scoped_ptr<Extension> extension(LoadAndExpectSuccess("valid_app.json"));
- ASSERT_EQ(2u, extension->web_extent().patterns().size());
- EXPECT_EQ("http://www.google.com/mail/*",
- extension->web_extent().patterns()[0].GetAsString());
- EXPECT_EQ("http://www.google.com/foobar/*",
- extension->web_extent().patterns()[1].GetAsString());
+ EXPECT_EQ(GURL("http://www.google.com/"), extension->web_extent().origin());
+ EXPECT_EQ(2u, extension->web_extent().paths().size());
+ EXPECT_EQ("mail/", extension->web_extent().paths()[0]);
+ EXPECT_EQ("foobar/", extension->web_extent().paths()[1]);
EXPECT_EQ(Extension::LAUNCH_WINDOW, extension->launch_container());
EXPECT_EQ(false, extension->launch_fullscreen());
- EXPECT_EQ("http://www.google.com/mail/", extension->launch_web_url());
+ EXPECT_EQ("mail/", extension->launch_web_url());
}
-TEST_F(ManifestTest, AppWebUrls) {
- LoadAndExpectError("web_urls_wrong_type.json",
- errors::kInvalidWebURLs);
- LoadAndExpectError("web_urls_invalid_1.json",
- ExtensionErrorUtils::FormatErrorMessage(
- errors::kInvalidWebURL, "0"));
- LoadAndExpectError("web_urls_invalid_2.json",
+TEST_F(ManifestTest, AppWebOrigin) {
+ LoadAndExpectError("web_origin_wrong_type.json",
+ errors::kInvalidWebOrigin);
+ LoadAndExpectError("web_origin_invalid_1.json",
+ errors::kInvalidWebOrigin);
+ LoadAndExpectError("web_origin_invalid_2.json",
+ errors::kInvalidWebOrigin);
+ LoadAndExpectError("web_origin_invalid_3.json",
+ errors::kInvalidWebOrigin);
+}
+
+TEST_F(ManifestTest, AppWebPaths) {
+ LoadAndExpectError("web_paths_wrong_type.json",
+ errors::kInvalidWebPaths);
+ LoadAndExpectError("web_paths_invalid_path_1.json",
ExtensionErrorUtils::FormatErrorMessage(
- errors::kInvalidWebURL, "0"));
- LoadAndExpectError("web_urls_invalid_3.json",
+ errors::kInvalidWebPath, "0"));
+ LoadAndExpectError("web_paths_invalid_path_2.json",
ExtensionErrorUtils::FormatErrorMessage(
- errors::kInvalidWebURL, "0"));
-
- scoped_ptr<Extension> extension(
- LoadAndExpectSuccess("web_urls_default.json"));
- ASSERT_EQ(1u, extension->web_extent().patterns().size());
- EXPECT_EQ("http://www.google.com/*",
- extension->web_extent().patterns()[0].GetAsString());
+ errors::kInvalidWebPath, "0"));
}
TEST_F(ManifestTest, AppLaunchContainer) {
@@ -174,8 +175,9 @@ TEST_F(ManifestTest, AppLaunchURL) {
EXPECT_EQ(extension->url().spec() + "launch.html",
extension->GetFullLaunchURL().spec());
- LoadAndExpectError("launch_web_url_relative.json",
- errors::kInvalidLaunchWebURL);
+ extension.reset(LoadAndExpectSuccess("launch_web_url_relative.json"));
+ EXPECT_EQ(GURL("http://www.google.com/launch.html"),
+ extension->GetFullLaunchURL());
extension.reset(LoadAndExpectSuccess("launch_web_url_absolute.json"));
EXPECT_EQ(GURL("http://www.google.com/launch.html"),
diff --git a/chrome/common/extensions/url_pattern.cc b/chrome/common/extensions/url_pattern.cc
index 1aae528..e129903 100644
--- a/chrome/common/extensions/url_pattern.cc
+++ b/chrome/common/extensions/url_pattern.cc
@@ -4,7 +4,6 @@
#include "chrome/common/extensions/url_pattern.h"
-#include "base/scoped_ptr.h"
#include "base/string_piece.h"
#include "base/string_util.h"
#include "chrome/common/url_constants.h"
@@ -22,15 +21,6 @@ static const char* kValidSchemes[] = {
static const char kPathSeparator[] = "/";
// static
-URLPattern* URLPattern::CreateFromString(const std::string& pattern_string) {
- scoped_ptr<URLPattern> pattern(new URLPattern);
- if (pattern->Parse(pattern_string))
- return pattern.release();
- else
- return NULL;
-}
-
-// static
bool URLPattern::IsValidScheme(const std::string& scheme) {
for (size_t i = 0; i < arraysize(kValidSchemes); ++i) {
if (scheme == kValidSchemes[i])
@@ -88,7 +78,6 @@ bool URLPattern::Parse(const std::string& pattern) {
}
path_ = pattern.substr(path_start_pos);
-
return true;
}
@@ -105,14 +94,6 @@ bool URLPattern::MatchesUrl(const GURL &test) const {
return true;
}
-bool URLPattern::MatchesHost(const std::string& host) const {
- std::string test(chrome::kHttpScheme);
- test += chrome::kStandardSchemeSeparator;
- test += host;
- test += "/";
- return MatchesHost(GURL(test));
-}
-
bool URLPattern::MatchesHost(const GURL& test) const {
// If the hosts are exactly equal, we have a match.
if (test.host() == host_)
diff --git a/chrome/common/extensions/url_pattern.h b/chrome/common/extensions/url_pattern.h
index e25faaf..dba393a 100644
--- a/chrome/common/extensions/url_pattern.h
+++ b/chrome/common/extensions/url_pattern.h
@@ -73,9 +73,6 @@ class URLPattern {
// otherwise.
static bool IsValidScheme(const std::string& scheme);
- // Convenience to create a pattern from a string.
- static URLPattern* CreateFromString(const std::string& pattern);
-
URLPattern() : match_subdomains_(false) {}
// Initializes this instance by parsing the provided string. On failure, the
@@ -85,13 +82,6 @@ class URLPattern {
// Returns true if this instance matches the specified URL.
bool MatchesUrl(const GURL& url) const;
- // Returns true if |test| matches our host.
- bool MatchesHost(const std::string& host) const;
- bool MatchesHost(const GURL& test) const;
-
- // Returns true if |test| matches our path.
- bool MatchesPath(const GURL& test) const;
-
std::string GetAsString() const;
// Get the scheme the pattern matches. This will always return a valid scheme
@@ -117,6 +107,12 @@ class URLPattern {
}
private:
+ // Returns true if |test| matches our host.
+ bool MatchesHost(const GURL& test) const;
+
+ // Returns true if |test| matches our path.
+ bool MatchesPath(const GURL& test) const;
+
// The scheme for the pattern.
std::string scheme_;
diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h
index 061a236..2b757e9 100644
--- a/chrome/common/render_messages.h
+++ b/chrome/common/render_messages.h
@@ -2683,21 +2683,25 @@ template <>
struct ParamTraits<ExtensionExtent> {
typedef ExtensionExtent param_type;
static void Write(Message* m, const param_type& p) {
- WriteParam(m, p.patterns());
+ WriteParam(m, p.origin());
+ WriteParam(m, p.paths());
}
static bool Read(const Message* m, void** iter, param_type* p) {
- std::vector<URLPattern> patterns;
+ GURL origin;
+ std::vector<std::string> paths;
bool success =
- ReadParam(m, iter, &patterns);
+ ReadParam(m, iter, &origin) &&
+ ReadParam(m, iter, &paths);
if (!success)
return false;
- for (size_t i = 0; i < patterns.size(); ++i)
- p->AddPattern(patterns[i]);
+ p->set_origin(origin);
+ for (size_t i = 0; i < paths.size(); ++i)
+ p->add_path(paths[i]);
return true;
}
static void Log(const param_type& p, std::wstring* l) {
- LogParam(p.patterns(), l);
+ LogParam(p.origin(), l);
}
};