Commit 9fe97260 authored by sadrul@chromium.org's avatar sadrul@chromium.org

extensions: Register 'app' and 'webstore' bindings only if they are available.

When running from outside chrome (e.g. in athena), 'app' and 'webstore' api
implementations are not available. So check to see if the API is available
before registering the corresponding bindings.

BUG=391478
R=kalman@chromium.org

Review URL: https://codereview.chromium.org/443723003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287935 0039d316-1c4b-4281-b951-d872f2087c98
parent f3f1e81e
......@@ -53,9 +53,8 @@
"web_page",
"blessed_web_page"
],
"matches": [
"http://*/*", "https://*/*", "chrome-extension://*/*", "file://*/*"
]
// Any webpage can use the app API.
"matches": ["<all_urls>"]
},
"appViewInternal": {
"internal": true,
......@@ -763,12 +762,14 @@
"webstore": {
// Hosted apps can use the webstore API from within a blessed context.
"channel": "stable",
// Do not specify extension_types to prevent webstore from being filtered.
// Set extension_types to 'all' to prevent webstore from being filtered.
// Technically, webstore is not in apps or extensions, but it is currently
// displayed on /extensions/webstore and /apps/webstore.
// displayed on /extensions/webstore and /apps/webstore. The "contexts"
// restriction effectively restricts this to hosted apps and webpages.
"extension_types": "all",
"contexts": ["blessed_web_page", "web_page"],
// Any webpage can use the webstore API.
"matches": ["http://*/*", "https://*/*"]
"matches": ["<all_urls>"]
},
"webstorePrivate": {
"dependencies": ["permission:webstorePrivate"],
......
......@@ -673,9 +673,9 @@ TEST(ExtensionAPITest, URLMatching) {
EXPECT_TRUE(MatchesURL(api.get(), "app", "https://blah.net"));
EXPECT_TRUE(MatchesURL(api.get(), "app", "file://somefile.html"));
// But not internal URLs.
EXPECT_FALSE(MatchesURL(api.get(), "app", "about:flags"));
EXPECT_FALSE(MatchesURL(api.get(), "app", "chrome://flags"));
// Also to internal URLs.
EXPECT_TRUE(MatchesURL(api.get(), "app", "about:flags"));
EXPECT_TRUE(MatchesURL(api.get(), "app", "chrome://flags"));
// "app" should be available to chrome-extension URLs.
EXPECT_TRUE(MatchesURL(api.get(), "app",
......
......@@ -77,7 +77,7 @@ bool PermissionsData::IsRestrictedUrl(const GURL& document_url,
const GURL& top_frame_url,
const Extension* extension,
std::string* error) {
if (CanExecuteScriptEverywhere(extension))
if (extension && CanExecuteScriptEverywhere(extension))
return false;
// Check if the scheme is valid for extensions. If not, return.
......@@ -103,9 +103,8 @@ bool PermissionsData::IsRestrictedUrl(const GURL& document_url,
return true;
}
if (top_frame_url.SchemeIs(kExtensionScheme) &&
top_frame_url.host() != extension->id() &&
!allow_on_chrome_urls) {
if (extension && top_frame_url.SchemeIs(kExtensionScheme) &&
top_frame_url.host() != extension->id() && !allow_on_chrome_urls) {
if (error)
*error = manifest_errors::kCannotAccessExtensionUrl;
return true;
......
......@@ -1003,8 +1003,11 @@ void Dispatcher::UpdateBindingsForContext(ScriptContext* context) {
case Feature::BLESSED_WEB_PAGE_CONTEXT: {
// Web page context; it's too expensive to run the full bindings code.
// Hard-code that the app and webstore APIs are available...
RegisterBinding("app", context);
RegisterBinding("webstore", context);
if (context->GetAvailability("app").is_available())
RegisterBinding("app", context);
if (context->GetAvailability("webstore").is_available())
RegisterBinding("webstore", context);
// ... and that the runtime API might be available if any extension can
// connect to it.
......
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