Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / extensions / common / manifest_handlers / shared_module_info.h
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef EXTENSIONS_COMMON_MANIFEST_HANDLERS_SHARED_MODULE_INFO_H_
6 #define EXTENSIONS_COMMON_MANIFEST_HANDLERS_SHARED_MODULE_INFO_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/values.h"
12 #include "extensions/common/extension.h"
13 #include "extensions/common/manifest_handler.h"
14
15 namespace extensions {
16
17 class SharedModuleInfo : public Extension::ManifestData {
18  public:
19   SharedModuleInfo();
20   ~SharedModuleInfo() override;
21
22   bool Parse(const Extension* extension, base::string16* error);
23
24   struct ImportInfo {
25     std::string extension_id;
26     std::string minimum_version;
27   };
28
29   // Utility functions.
30   static void ParseImportedPath(const std::string& path,
31                                 std::string* import_id,
32                                 std::string* import_relative_path);
33   static bool IsImportedPath(const std::string& path);
34
35   // Functions relating to exporting resources.
36   static bool IsSharedModule(const Extension* extension);
37   // Check against the shared module's whitelist to see if |other_id| can import
38   // its resources. If no whitelist is specified, all extensions can import this
39   // extension.
40   static bool IsExportAllowedByWhitelist(const Extension* extension,
41                                          const std::string& other_id);
42
43   // Functions relating to importing resources.
44   static bool ImportsExtensionById(const Extension* extension,
45                                    const std::string& other_id);
46   static bool ImportsModules(const Extension* extension);
47   static const std::vector<ImportInfo>& GetImports(const Extension* extension);
48
49  private:
50   // Optional list of extensions from which importing is allowed.
51   std::set<std::string> export_whitelist_;
52
53   // Optional list of module imports of other extensions.
54   std::vector<ImportInfo> imports_;
55 };
56
57 // Parses all import/export keys in the manifest.
58 class SharedModuleHandler : public ManifestHandler {
59  public:
60   SharedModuleHandler();
61   ~SharedModuleHandler() override;
62
63   bool Parse(Extension* extension, base::string16* error) override;
64   bool Validate(const Extension* extension,
65                 std::string* error,
66                 std::vector<InstallWarning>* warnings) const override;
67
68  private:
69   const std::vector<std::string> Keys() const override;
70 };
71
72 }  // namespace extensions
73
74 #endif  // EXTENSIONS_COMMON_MANIFEST_HANDLERS_SHARED_MODULE_INFO_H_