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 CHROME_COMMON_EXTENSIONS_MANIFEST_HANDLERS_EXTERNALLY_CONNECTABLE_H_ 6 #define CHROME_COMMON_EXTENSIONS_MANIFEST_HANDLERS_EXTERNALLY_CONNECTABLE_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "base/memory/scoped_ptr.h" 12 #include "chrome/common/extensions/extension.h" 13 #include "chrome/common/extensions/manifest_handler.h" 14 #include "extensions/common/install_warning.h" 15 #include "extensions/common/url_pattern_set.h" 16 17 class GURL; 18 19 namespace base { 20 class Value; 21 } 22 23 namespace extensions { 24 25 // Error constants used when parsing the externally_connectable manifest entry. 26 namespace externally_connectable_errors { 27 extern const char kErrorInvalid[]; 28 extern const char kErrorInvalidMatchPattern[]; 29 extern const char kErrorInvalidId[]; 30 extern const char kErrorNothingSpecified[]; 31 extern const char kErrorTopLevelDomainsNotAllowed[]; 32 extern const char kErrorWildcardHostsNotAllowed[]; 33 } // namespace externally_connectable_errors 34 35 // Parses the externally_connectable manifest entry. 36 class ExternallyConnectableHandler : public ManifestHandler { 37 public: 38 ExternallyConnectableHandler(); 39 virtual ~ExternallyConnectableHandler(); 40 41 virtual bool Parse(Extension* extension, string16* error) OVERRIDE; 42 43 private: 44 virtual const std::vector<std::string> Keys() const OVERRIDE; 45 46 DISALLOW_COPY_AND_ASSIGN(ExternallyConnectableHandler); 47 }; 48 49 // The parsed form of the externally_connectable manifest entry. 50 struct ExternallyConnectableInfo : public Extension::ManifestData { 51 public: 52 // Gets the ExternallyConnectableInfo for |extension|, or NULL if none was 53 // specified. 54 static ExternallyConnectableInfo* Get(const Extension* extension); 55 56 // Tries to construct the info based on |value|, as it would have appeared in 57 // the manifest. Sets |error| and returns an empty scoped_ptr on failure. 58 static scoped_ptr<ExternallyConnectableInfo> FromValue( 59 const base::Value& value, 60 std::vector<InstallWarning>* install_warnings, 61 string16* error); 62 63 virtual ~ExternallyConnectableInfo(); 64 65 // The URL patterns that are allowed to connect/sendMessage. 66 const URLPatternSet matches; 67 68 // The extension IDs that are allowed to connect/sendMessage. Sorted. 69 const std::vector<std::string> ids; 70 71 // True if any extension is allowed to connect. This would have corresponded 72 // to an ID of "*" in |ids|. 73 const bool all_ids; 74 75 // Returns true if |ids| contains |id| or if |all_ids| is true. 76 // 77 // More convenient for callers than checking each individually, and it makes 78 // use of the sortedness of |ids|. 79 bool IdCanConnect(const std::string& id); 80 81 // Public only for testing. Use FromValue in production. 82 ExternallyConnectableInfo(const URLPatternSet& matches, 83 const std::vector<std::string>& ids, 84 bool all_ids); 85 86 private: 87 DISALLOW_COPY_AND_ASSIGN(ExternallyConnectableInfo); 88 }; 89 90 } // namespace extensions 91 92 #endif // CHROME_COMMON_EXTENSIONS_MANIFEST_HANDLERS_EXTERNALLY_CONNECTABLE_H_ 93