summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions
diff options
context:
space:
mode:
authorbattre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-10 01:01:07 +0000
committerbattre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-10 01:01:07 +0000
commitbb12d853e4af985379bd56ba3025ec0d2b087148 (patch)
tree720c648e4a2c15e1c4e565989f395491c1bb7b7b /chrome/common/extensions
parent71229fa8616c36c326dab127564922b14e443fa9 (diff)
downloadchromium_src-bb12d853e4af985379bd56ba3025ec0d2b087148.zip
chromium_src-bb12d853e4af985379bd56ba3025ec0d2b087148.tar.gz
chromium_src-bb12d853e4af985379bd56ba3025ec0d2b087148.tar.bz2
Support chrome-extension:// scheme in URLPattern.
This CL is mostly motivated to allow users of the web request API to filter network traffic to the extension. The URLParser was configured to broadly before in that is allowed parsing URLPattern::SCHEME_ALL. BUG=105656 TEST=no Review URL: http://codereview.chromium.org/8800006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113907 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions')
-rw-r--r--chrome/common/extensions/docs/match_patterns.html24
-rw-r--r--chrome/common/extensions/docs/static/match_patterns.html24
-rw-r--r--chrome/common/extensions/docs/static/webRequest.html3
-rw-r--r--chrome/common/extensions/docs/webRequest.html3
-rw-r--r--chrome/common/extensions/url_pattern.cc5
-rw-r--r--chrome/common/extensions/url_pattern.h14
-rw-r--r--chrome/common/extensions/url_pattern_unittest.cc25
7 files changed, 83 insertions, 15 deletions
diff --git a/chrome/common/extensions/docs/match_patterns.html b/chrome/common/extensions/docs/match_patterns.html
index ef9ee74..1492913 100644
--- a/chrome/common/extensions/docs/match_patterns.html
+++ b/chrome/common/extensions/docs/match_patterns.html
@@ -344,7 +344,8 @@ which URLs your content script affects.
<p>
A match pattern is essentially a URL
that begins with a permitted scheme (<code>http</code>,
-<code>https</code>, <code>file</code>, or <code>ftp</code>),
+<code>https</code>, <code>file</code>, <code>ftp</code>, or
+<code>chrome-extension</code>),
and that can contain '<code>*</code>' characters.
The special pattern
<code>&lt;all_urls&gt;</code> matches any URL
@@ -379,7 +380,7 @@ Each match pattern has 3 parts:</p>
<p>Here's the basic syntax:</p>
<pre><em>&lt;url-pattern&gt;</em> := <em>&lt;scheme&gt;</em>://<em>&lt;host&gt;</em><em>&lt;path&gt;</em>
-<em>&lt;scheme&gt;</em> := '*' | 'http' | 'https' | 'file' | 'ftp'
+<em>&lt;scheme&gt;</em> := '*' | 'http' | 'https' | 'file' | 'ftp' | 'chrome-extension'
<em>&lt;host&gt;</em> := '*' | '*.' <em>&lt;any char except '/' and '*'&gt;</em>+
<em>&lt;path&gt;</em> := '/' <em>&lt;any chars&gt;</em>
</pre>
@@ -514,6 +515,21 @@ The following table shows some valid patterns.
<tr>
<td>
+ <code>chrome-extension://*/* </code>
+ </td>
+
+ <td>
+ Matches any URL pointing to an extension (the first <code>*</code>
+ represents a filter for extension IDs, the second for paths).
+ </td>
+
+ <td>
+ chrome-extension://askla...asdf/options.html
+ </td>
+</tr>
+
+<tr>
+ <td>
<code>&lt;all_urls&gt;</code>
</td>
@@ -567,6 +583,10 @@ Here are some examples of <em>invalid</em> pattern matches:
</tr>
</tbody>
</table>
+
+<p>
+Some schemes are not supported in all contexts.
+</p>
</div>
<!-- API PAGE -->
diff --git a/chrome/common/extensions/docs/static/match_patterns.html b/chrome/common/extensions/docs/static/match_patterns.html
index 871fcfa..5f493a7 100644
--- a/chrome/common/extensions/docs/static/match_patterns.html
+++ b/chrome/common/extensions/docs/static/match_patterns.html
@@ -15,7 +15,8 @@ which URLs your content script affects.
<p>
A match pattern is essentially a URL
that begins with a permitted scheme (<code>http</code>,
-<code>https</code>, <code>file</code>, or <code>ftp</code>),
+<code>https</code>, <code>file</code>, <code>ftp</code>, or
+<code>chrome-extension</code>),
and that can contain '<code>*</code>' characters.
The special pattern
<code>&lt;all_urls&gt;</code> matches any URL
@@ -51,7 +52,7 @@ Each match pattern has 3 parts:</p>
<pre>
<em>&lt;url-pattern&gt;</em> := <em>&lt;scheme&gt;</em>://<em>&lt;host&gt;</em><em>&lt;path&gt;</em>
-<em>&lt;scheme&gt;</em> := '*' | 'http' | 'https' | 'file' | 'ftp'
+<em>&lt;scheme&gt;</em> := '*' | 'http' | 'https' | 'file' | 'ftp' | 'chrome-extension'
<em>&lt;host&gt;</em> := '*' | '*.' <em>&lt;any char except '/' and '*'&gt;</em>+
<em>&lt;path&gt;</em> := '/' <em>&lt;any chars&gt;</em>
</pre>
@@ -186,6 +187,21 @@ The following table shows some valid patterns.
<tr>
<td>
+ <code>chrome-extension://*/* </code>
+ </td>
+
+ <td>
+ Matches any URL pointing to an extension (the first <code>*</code>
+ represents a filter for extension IDs, the second for paths).
+ </td>
+
+ <td>
+ chrome-extension://askla...asdf/options.html
+ </td>
+</tr>
+
+<tr>
+ <td>
<code>&lt;all_urls&gt;</code>
</td>
@@ -239,3 +255,7 @@ Here are some examples of <em>invalid</em> pattern matches:
</tr>
</tbody>
</table>
+
+<p>
+Some schemes are not supported in all contexts.
+</p>
diff --git a/chrome/common/extensions/docs/static/webRequest.html b/chrome/common/extensions/docs/static/webRequest.html
index 9d2b44d..08e6784 100644
--- a/chrome/common/extensions/docs/static/webRequest.html
+++ b/chrome/common/extensions/docs/static/webRequest.html
@@ -195,7 +195,8 @@ explicitly requested.</p>
triggered in various dimensions:
<dl>
<dt>URLs</dt>
- <dd>URL patterns like <code>*://www.google.com/foo*bar</code>.</dd>
+ <dd><a href="match_patterns.html">URL patterns</a> like
+ <code>*://www.google.com/foo*bar</code>.</dd>
<dt>Types</dt>
<dd>Request types like <code>main_frame</code> (a document that is loaded for
a top-level frame), <code>sub_frame</code> (a document that is loaded for an
diff --git a/chrome/common/extensions/docs/webRequest.html b/chrome/common/extensions/docs/webRequest.html
index cb3f7a2..efd337e 100644
--- a/chrome/common/extensions/docs/webRequest.html
+++ b/chrome/common/extensions/docs/webRequest.html
@@ -668,7 +668,8 @@ explicitly requested.</p>
triggered in various dimensions:
</p><dl>
<dt>URLs</dt>
- <dd>URL patterns like <code>*://www.google.com/foo*bar</code>.</dd>
+ <dd><a href="match_patterns.html">URL patterns</a> like
+ <code>*://www.google.com/foo*bar</code>.</dd>
<dt>Types</dt>
<dd>Request types like <code>main_frame</code> (a document that is loaded for
a top-level frame), <code>sub_frame</code> (a document that is loaded for an
diff --git a/chrome/common/extensions/url_pattern.cc b/chrome/common/extensions/url_pattern.cc
index 8e831a4..907678c 100644
--- a/chrome/common/extensions/url_pattern.cc
+++ b/chrome/common/extensions/url_pattern.cc
@@ -16,8 +16,7 @@ const char URLPattern::kAllUrlsPattern[] = "<all_urls>";
namespace {
-// TODO(aa): Consider adding chrome-extension? What about more obscure ones
-// like data: and javascript: ?
+// TODO(aa): What about more obscure schemes like data: and javascript: ?
// Note: keep this array in sync with kValidSchemeMasks.
const char* kValidSchemes[] = {
chrome::kHttpScheme,
@@ -25,6 +24,7 @@ const char* kValidSchemes[] = {
chrome::kFileScheme,
chrome::kFtpScheme,
chrome::kChromeUIScheme,
+ chrome::kExtensionScheme,
chrome::kFileSystemScheme,
};
@@ -34,6 +34,7 @@ const int kValidSchemeMasks[] = {
URLPattern::SCHEME_FILE,
URLPattern::SCHEME_FTP,
URLPattern::SCHEME_CHROMEUI,
+ URLPattern::SCHEME_EXTENSION,
URLPattern::SCHEME_FILESYSTEM,
};
diff --git a/chrome/common/extensions/url_pattern.h b/chrome/common/extensions/url_pattern.h
index ef01c1b..094c472c 100644
--- a/chrome/common/extensions/url_pattern.h
+++ b/chrome/common/extensions/url_pattern.h
@@ -15,7 +15,8 @@ class GURL;
// subset of URL syntax:
//
// <url-pattern> := <scheme>://<host><port><path> | '<all_urls>'
-// <scheme> := '*' | 'http' | 'https' | 'file' | 'ftp' | 'chrome'
+// <scheme> := '*' | 'http' | 'https' | 'file' | 'ftp' | 'chrome' |
+// 'chrome-extension' | 'filesystem'
// <host> := '*' | '*.' <anychar except '/' and '*'>+
// <port> := [':' ('*' | <port number between 0 and 65535>)]
// <path> := '/' <any chars>
@@ -90,12 +91,15 @@ class URLPattern {
SCHEME_FILE = 1 << 2,
SCHEME_FTP = 1 << 3,
SCHEME_CHROMEUI = 1 << 4,
- SCHEME_FILESYSTEM = 1 << 5,
+ SCHEME_EXTENSION = 1 << 5,
+ SCHEME_FILESYSTEM = 1 << 6,
+
+ // IMPORTANT!
// SCHEME_ALL will match every scheme, including chrome://, chrome-
// extension://, about:, etc. Because this has lots of security
- // implications, third-party extensions should never be able to get access
- // to URL patterns initialized this way. It should only be used for internal
- // Chrome code.
+ // implications, third-party extensions should usually not be able to get
+ // access to URL patterns initialized this way. If there is a reason
+ // for violating this general rule, document why this it safe.
SCHEME_ALL = -1,
};
diff --git a/chrome/common/extensions/url_pattern_unittest.cc b/chrome/common/extensions/url_pattern_unittest.cc
index 578fd0a..1695582 100644
--- a/chrome/common/extensions/url_pattern_unittest.cc
+++ b/chrome/common/extensions/url_pattern_unittest.cc
@@ -14,7 +14,9 @@ static const int kAllSchemes =
URLPattern::SCHEME_HTTPS |
URLPattern::SCHEME_FILE |
URLPattern::SCHEME_FTP |
- URLPattern::SCHEME_CHROMEUI;
+ URLPattern::SCHEME_CHROMEUI |
+ URLPattern::SCHEME_EXTENSION |
+ URLPattern::SCHEME_FILESYSTEM;
TEST(ExtensionURLPatternTest, ParseInvalid) {
const struct {
@@ -276,6 +278,7 @@ TEST(ExtensionURLPatternTest, Match11) {
EXPECT_TRUE(pattern.MatchesScheme("http"));
EXPECT_TRUE(pattern.MatchesScheme("https"));
EXPECT_TRUE(pattern.MatchesScheme("file"));
+ EXPECT_TRUE(pattern.MatchesScheme("chrome-extension"));
EXPECT_TRUE(pattern.match_subdomains());
EXPECT_TRUE(pattern.match_all_urls());
EXPECT_EQ("/*", pattern.path());
@@ -435,6 +438,24 @@ TEST(ExtensionURLPatternTest, Match18) {
EXPECT_TRUE(pattern.MatchesURL(GURL("http://www.example.com:8080/foo")));
}
+// chrome-extension://
+TEST(ExtensionURLPatternTest, Match19) {
+ URLPattern pattern(URLPattern::ERROR_ON_PORTS, URLPattern::SCHEME_EXTENSION);
+ EXPECT_EQ(URLPattern::PARSE_SUCCESS,
+ pattern.Parse("chrome-extension://ftw/*"));
+ EXPECT_EQ("chrome-extension", pattern.scheme());
+ EXPECT_EQ("ftw", pattern.host());
+ EXPECT_FALSE(pattern.match_subdomains());
+ EXPECT_FALSE(pattern.match_all_urls());
+ EXPECT_EQ("/*", pattern.path());
+ EXPECT_TRUE(pattern.MatchesURL(GURL("chrome-extension://ftw")));
+ EXPECT_TRUE(pattern.MatchesURL(
+ GURL("chrome-extension://ftw/http://google.com")));
+ EXPECT_TRUE(pattern.MatchesURL(
+ GURL("chrome-extension://ftw/https://google.com")));
+ EXPECT_FALSE(pattern.MatchesURL(GURL("chrome-extension://foobar")));
+};
+
static const struct GetAsStringPatterns {
const char* pattern;
} kGetAsStringTestCases[] = {
@@ -539,7 +560,7 @@ TEST(ExtensionURLPatternTest, ConvertToExplicitSchemes) {
URLPattern::SCHEME_FTP,
"http://google.com/monkey").ConvertToExplicitSchemes());
- ASSERT_EQ(5u, all_urls.size());
+ ASSERT_EQ(7u, all_urls.size());
ASSERT_EQ(2u, all_schemes.size());
ASSERT_EQ(1u, monkey.size());