Commit 33ad2488 authored by battre@chromium.org's avatar battre@chromium.org

WebRequest API should warn when a developer attempts to filter URLs without proper permissions

Warn user if he attempts to register a web request filter without having any
host permissions for the extension. We don't try a full subsumption test (you
may register for a broader set of URLs than you have host permissions). This is
just a simple check that you have any host permissions at all, which should
help a careless developer to see his problem.

BUG=104435
TEST=no


Review URL: http://codereview.chromium.org/8931006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114289 0039d316-1c4b-4281-b951-d872f2087c98
parent c92b8612
......@@ -1535,6 +1535,17 @@ bool WebRequestAddEventListener::RunImpl() {
return false;
}
// We allow to subscribe to patterns that are broader than the host
// permissions. E.g., we could subscribe to http://www.example.com/*
// while having host permissions for http://www.example.com/foo/* and
// http://www.example.com/bar/*.
// For this reason we do only a coarse check here to warn the extension
// developer if he does something obviously wrong.
if (extension->GetEffectiveHostPermissions().is_empty()) {
error_ = keys::kHostPermissionsRequired;
return false;
}
ExtensionWebRequestEventRouter::GetInstance()->AddEventListener(
profile_id(), extension_id(), extension_name,
event_name, sub_event_name, filter,
......
......@@ -51,8 +51,11 @@ const char kInvalidBlockingResponse[] =
"cancel cannot be true in the presence of other keys.";
const char kInvalidRequestFilterUrl[] = "'*' is not a valid URL pattern.";
const char kBlockingPermissionRequired[] =
"You do not have permission to use blocking webRequest listeners. "
"Be sure to declare the webRequestBlocking permission in your "
"manifest.";
"You do not have permission to use blocking webRequest listeners. "
"Be sure to declare the webRequestBlocking permission in your "
"manifest.";
const char kHostPermissionsRequired[] =
"You need to request host permissions in the manifest file in order to "
"be notified about requests from the webRequest API.";
} // namespace extension_webrequest_api_constants
......@@ -57,6 +57,7 @@ extern const char kInvalidRedirectUrl[];
extern const char kInvalidBlockingResponse[];
extern const char kInvalidRequestFilterUrl[];
extern const char kBlockingPermissionRequired[];
extern const char kHostPermissionsRequired[];
} // namespace extension_webrequest_api_constants
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment