Commit 8f7d2587 authored by mtomasz's avatar mtomasz Committed by Commit bot

Improve parsing manifest for FSP API.

This CL makes the FSP section a prerequisite for the permission. It also adds
a warning if a section is used without a permission.

TEST=unit_tests: *FileSystemProviderHandlerTest*"
BUG=474146

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

Cr-Commit-Position: refs/heads/master@{#329374}
parent 0edab375
...@@ -1326,6 +1326,7 @@ ...@@ -1326,6 +1326,7 @@
'browser/ui/webui/chromeos/login/signin_userlist_unittest.cc', 'browser/ui/webui/chromeos/login/signin_userlist_unittest.cc',
'browser/ui/webui/options/chromeos/cros_language_options_handler_unittest.cc', 'browser/ui/webui/options/chromeos/cros_language_options_handler_unittest.cc',
'common/extensions/api/file_browser_handlers/file_browser_handler_manifest_unittest.cc', 'common/extensions/api/file_browser_handlers/file_browser_handler_manifest_unittest.cc',
'common/extensions/api/file_system_provider/file_system_provider_handler_unittest.cc',
], ],
'chrome_unit_tests_desktop_linux_sources': [ 'chrome_unit_tests_desktop_linux_sources': [
'browser/password_manager/native_backend_kwallet_x_unittest.cc', 'browser/password_manager/native_backend_kwallet_x_unittest.cc',
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/common/extensions/manifest_tests/chrome_manifest_test.h"
#include "extensions/common/manifest_constants.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace extensions {
class FileSystemProviderHandlerTest : public ChromeManifestTest {};
TEST_F(FileSystemProviderHandlerTest, Valid) {
RunTestcase(Testcase("filesystemprovider_valid.json"), EXPECT_TYPE_SUCCESS);
}
TEST_F(FileSystemProviderHandlerTest, Invalid_MissingCapabilities) {
RunTestcase(
Testcase("filesystemprovider_missing_capabilities.json",
manifest_errors::kInvalidFileSystemProviderMissingCapabilities),
EXPECT_TYPE_ERROR);
}
TEST_F(FileSystemProviderHandlerTest, Invalid_MissingPermission) {
RunTestcase(
Testcase("filesystemprovider_missing_permission.json",
manifest_errors::kInvalidFileSystemProviderMissingPermission),
EXPECT_TYPE_WARNING);
}
} // namespace extensions
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "chrome/common/extensions/api/manifest_types.h" #include "chrome/common/extensions/api/manifest_types.h"
#include "extensions/common/error_utils.h" #include "extensions/common/error_utils.h"
#include "extensions/common/manifest_constants.h" #include "extensions/common/manifest_constants.h"
#include "extensions/common/manifest_handlers/permissions_parser.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace extensions { namespace extensions {
...@@ -47,10 +48,30 @@ const FileSystemProviderCapabilities* FileSystemProviderCapabilities::Get( ...@@ -47,10 +48,30 @@ const FileSystemProviderCapabilities* FileSystemProviderCapabilities::Get(
bool FileSystemProviderCapabilitiesHandler::Parse(Extension* extension, bool FileSystemProviderCapabilitiesHandler::Parse(Extension* extension,
base::string16* error) { base::string16* error) {
const base::DictionaryValue* section = NULL; const bool has_permission = extensions::PermissionsParser::HasAPIPermission(
extension, extensions::APIPermission::ID::kFileSystemProvider);
const base::DictionaryValue* section = nullptr;
extension->manifest()->GetDictionary( extension->manifest()->GetDictionary(
manifest_keys::kFileSystemProviderCapabilities, &section); manifest_keys::kFileSystemProviderCapabilities, &section);
DCHECK(section);
if (has_permission && !section) {
*error = base::ASCIIToUTF16(
manifest_errors::kInvalidFileSystemProviderMissingCapabilities);
return false;
}
if (!has_permission && section) {
// If the permission is not specified, then the section has simply no
// effect, hence just a warning.
extension->AddInstallWarning(extensions::InstallWarning(
manifest_errors::kInvalidFileSystemProviderMissingPermission));
return true;
}
if (!has_permission && !section) {
// No permission and no capabilities, so ignore.
return true;
}
api::manifest_types::FileSystemProviderCapabilities idl_capabilities; api::manifest_types::FileSystemProviderCapabilities idl_capabilities;
if (!api::manifest_types::FileSystemProviderCapabilities::Populate( if (!api::manifest_types::FileSystemProviderCapabilities::Populate(
...@@ -88,4 +109,9 @@ const std::vector<std::string> FileSystemProviderCapabilitiesHandler::Keys() ...@@ -88,4 +109,9 @@ const std::vector<std::string> FileSystemProviderCapabilitiesHandler::Keys()
return SingleKey(manifest_keys::kFileSystemProviderCapabilities); return SingleKey(manifest_keys::kFileSystemProviderCapabilities);
} }
bool FileSystemProviderCapabilitiesHandler::AlwaysParseForType(
Manifest::Type type) const {
return true;
}
} // namespace extensions } // namespace extensions
...@@ -48,6 +48,7 @@ class FileSystemProviderCapabilitiesHandler : public ManifestHandler { ...@@ -48,6 +48,7 @@ class FileSystemProviderCapabilitiesHandler : public ManifestHandler {
// ManifestHandler overrides. // ManifestHandler overrides.
bool Parse(Extension* extension, base::string16* error) override; bool Parse(Extension* extension, base::string16* error) override;
bool AlwaysParseForType(Manifest::Type type) const override;
private: private:
const std::vector<std::string> Keys() const override; const std::vector<std::string> Keys() const override;
......
...@@ -13,6 +13,11 @@ ...@@ -13,6 +13,11 @@
}, },
"fileManagerPrivate" "fileManagerPrivate"
], ],
"file_system_provider_capabilities": {
"configurable": true,
"multiple_mounts": true,
"source": "device"
},
"app": { "app": {
"background": { "background": {
"scripts": [ "scripts": [
......
...@@ -13,6 +13,11 @@ ...@@ -13,6 +13,11 @@
}, },
"fileManagerPrivate" "fileManagerPrivate"
], ],
"file_system_provider_capabilities": {
"configurable": true,
"multiple_mounts": true,
"source": "device"
},
"app": { "app": {
"background": { "background": {
"scripts": [ "scripts": [
......
...@@ -13,6 +13,11 @@ ...@@ -13,6 +13,11 @@
}, },
"fileManagerPrivate" "fileManagerPrivate"
], ],
"file_system_provider_capabilities": {
"configurable": true,
"multiple_mounts": true,
"source": "device"
},
"app": { "app": {
"background": { "background": {
"scripts": [ "scripts": [
......
...@@ -13,6 +13,11 @@ ...@@ -13,6 +13,11 @@
}, },
"fileManagerPrivate" "fileManagerPrivate"
], ],
"file_system_provider_capabilities": {
"configurable": true,
"multiple_mounts": true,
"source": "device"
},
"app": { "app": {
"background": { "background": {
"scripts": [ "scripts": [
......
...@@ -13,6 +13,11 @@ ...@@ -13,6 +13,11 @@
}, },
"fileManagerPrivate" "fileManagerPrivate"
], ],
"file_system_provider_capabilities": {
"configurable": true,
"multiple_mounts": true,
"source": "device"
},
"app": { "app": {
"background": { "background": {
"scripts": [ "scripts": [
......
...@@ -13,6 +13,11 @@ ...@@ -13,6 +13,11 @@
}, },
"fileManagerPrivate" "fileManagerPrivate"
], ],
"file_system_provider_capabilities": {
"configurable": true,
"multiple_mounts": true,
"source": "device"
},
"app": { "app": {
"background": { "background": {
"scripts": [ "scripts": [
......
...@@ -13,6 +13,11 @@ ...@@ -13,6 +13,11 @@
}, },
"fileManagerPrivate" "fileManagerPrivate"
], ],
"file_system_provider_capabilities": {
"configurable": true,
"multiple_mounts": true,
"source": "device"
},
"app": { "app": {
"background": { "background": {
"scripts": [ "scripts": [
......
...@@ -6,6 +6,11 @@ ...@@ -6,6 +6,11 @@
"manifest_version": 2, "manifest_version": 2,
"description": "Test for chrome.fileSystemProvider.mount() in an extension.", "description": "Test for chrome.fileSystemProvider.mount() in an extension.",
"permissions": ["fileSystemProvider", "fileManagerPrivate"], "permissions": ["fileSystemProvider", "fileManagerPrivate"],
"file_system_provider_capabilities": {
"configurable": true,
"multiple_mounts": true,
"source": "device"
},
"background": { "background": {
"persistent": false, "persistent": false,
"scripts": [ "scripts": [
......
...@@ -12,6 +12,11 @@ ...@@ -12,6 +12,11 @@
}, },
"fileManagerPrivate" "fileManagerPrivate"
], ],
"file_system_provider_capabilities": {
"configurable": true,
"multiple_mounts": true,
"source": "device"
},
"app": { "app": {
"background": { "background": {
"scripts": [ "scripts": [
......
...@@ -13,6 +13,11 @@ ...@@ -13,6 +13,11 @@
}, },
"fileManagerPrivate" "fileManagerPrivate"
], ],
"file_system_provider_capabilities": {
"configurable": true,
"multiple_mounts": true,
"source": "device"
},
"app": { "app": {
"background": { "background": {
"scripts": [ "scripts": [
......
...@@ -18,6 +18,11 @@ ...@@ -18,6 +18,11 @@
"types": ["text/secret-testing-mime-type"] "types": ["text/secret-testing-mime-type"]
} }
}, },
"file_system_provider_capabilities": {
"configurable": true,
"multiple_mounts": true,
"source": "device"
},
"app": { "app": {
"background": { "background": {
"scripts": [ "scripts": [
......
...@@ -13,6 +13,11 @@ ...@@ -13,6 +13,11 @@
}, },
"fileManagerPrivate" "fileManagerPrivate"
], ],
"file_system_provider_capabilities": {
"configurable": true,
"multiple_mounts": true,
"source": "device"
},
"app": { "app": {
"background": { "background": {
"scripts": [ "scripts": [
......
...@@ -13,6 +13,11 @@ ...@@ -13,6 +13,11 @@
}, },
"fileManagerPrivate" "fileManagerPrivate"
], ],
"file_system_provider_capabilities": {
"configurable": true,
"multiple_mounts": true,
"source": "device"
},
"app": { "app": {
"background": { "background": {
"scripts": [ "scripts": [
......
...@@ -13,6 +13,11 @@ ...@@ -13,6 +13,11 @@
}, },
"fileManagerPrivate" "fileManagerPrivate"
], ],
"file_system_provider_capabilities": {
"configurable": true,
"multiple_mounts": true,
"source": "device"
},
"app": { "app": {
"background": { "background": {
"scripts": [ "scripts": [
......
...@@ -13,6 +13,11 @@ ...@@ -13,6 +13,11 @@
}, },
"fileManagerPrivate" "fileManagerPrivate"
], ],
"file_system_provider_capabilities": {
"configurable": true,
"multiple_mounts": true,
"source": "device"
},
"app": { "app": {
"background": { "background": {
"scripts": [ "scripts": [
......
...@@ -13,6 +13,11 @@ ...@@ -13,6 +13,11 @@
}, },
"fileManagerPrivate" "fileManagerPrivate"
], ],
"file_system_provider_capabilities": {
"configurable": true,
"multiple_mounts": true,
"source": "device"
},
"app": { "app": {
"background": { "background": {
"scripts": [ "scripts": [
......
...@@ -13,6 +13,11 @@ ...@@ -13,6 +13,11 @@
}, },
"fileManagerPrivate" "fileManagerPrivate"
], ],
"file_system_provider_capabilities": {
"configurable": true,
"multiple_mounts": true,
"source": "device"
},
"app": { "app": {
"background": { "background": {
"scripts": [ "scripts": [
......
...@@ -13,6 +13,11 @@ ...@@ -13,6 +13,11 @@
}, },
"fileManagerPrivate" "fileManagerPrivate"
], ],
"file_system_provider_capabilities": {
"configurable": true,
"multiple_mounts": true,
"source": "device"
},
"app": { "app": {
"background": { "background": {
"scripts": [ "scripts": [
......
...@@ -5,6 +5,11 @@ ...@@ -5,6 +5,11 @@
"manifest_version": 2, "manifest_version": 2,
"description": "Test for chrome.fileSystemProvider.unmount().", "description": "Test for chrome.fileSystemProvider.unmount().",
"permissions": ["fileSystemProvider", "fileManagerPrivate"], "permissions": ["fileSystemProvider", "fileManagerPrivate"],
"file_system_provider_capabilities": {
"configurable": true,
"multiple_mounts": true,
"source": "device"
},
"app": { "app": {
"background": { "background": {
"scripts": [ "scripts": [
......
...@@ -13,6 +13,11 @@ ...@@ -13,6 +13,11 @@
}, },
"fileManagerPrivate" "fileManagerPrivate"
], ],
"file_system_provider_capabilities": {
"configurable": true,
"multiple_mounts": true,
"source": "device"
},
"app": { "app": {
"background": { "background": {
"scripts": [ "scripts": [
......
{
"name": "test",
"version": "1",
"permissions": [
"fileSystemProvider"
]
}
{
"name": "test",
"version": "1",
"file_system_provider_capabilities": {
"configurable": false,
"multiple_mounts": false,
"source": "device"
}
}
{
"name": "test",
"version": "1",
"permissions": [
"fileSystemProvider"
],
"file_system_provider_capabilities": {
"configurable": false,
"multiple_mounts": false,
"source": "device"
}
}
...@@ -713,7 +713,14 @@ const char kWebRequestConflictsWithLazyBackground[] = ...@@ -713,7 +713,14 @@ const char kWebRequestConflictsWithLazyBackground[] =
"The 'webRequest' API cannot be used with event pages."; "The 'webRequest' API cannot be used with event pages.";
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
const char kIllegalPlugins[] = const char kIllegalPlugins[] =
"Extensions cannot install plugins on Chrome OS"; "Extensions cannot install plugins on Chrome OS.";
const char kInvalidFileSystemProviderMissingCapabilities[] =
"The 'fileSystemProvider' permission requires the "
"'file_system_provider_capabilities' section to be specified in the "
"manifest.";
const char kInvalidFileSystemProviderMissingPermission[] =
"The 'file_system_provider_capabilities' section requires the "
"'fileSystemProvider' permission to be specified in the manifest.";
#endif #endif
} // namespace manifest_errors } // namespace manifest_errors
......
...@@ -479,6 +479,8 @@ extern const char kUnrecognizedManifestProperty[]; ...@@ -479,6 +479,8 @@ extern const char kUnrecognizedManifestProperty[];
extern const char kWebRequestConflictsWithLazyBackground[]; extern const char kWebRequestConflictsWithLazyBackground[];
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
extern const char kIllegalPlugins[]; extern const char kIllegalPlugins[];
extern const char kInvalidFileSystemProviderMissingCapabilities[];
extern const char kInvalidFileSystemProviderMissingPermission[];
#endif #endif
} // namespace manifest_errors } // namespace manifest_errors
......
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