Roll src/third_party/WebKit 8daf7c3:9de7917 (svn 194468:194469)
[chromium-blink-merge.git] / extensions / common / manifest_handlers / externally_connectable.h
blob67756d53aaf995174b54fc3fe0e05029f62ed1e4
1 // Copyright 2014 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.
5 #ifndef EXTENSIONS_COMMON_MANIFEST_HANDLERS_EXTERNALLY_CONNECTABLE_H_
6 #define EXTENSIONS_COMMON_MANIFEST_HANDLERS_EXTERNALLY_CONNECTABLE_H_
8 #include <string>
9 #include <vector>
11 #include "base/memory/scoped_ptr.h"
12 #include "extensions/common/extension.h"
13 #include "extensions/common/install_warning.h"
14 #include "extensions/common/manifest_handler.h"
15 #include "extensions/common/url_pattern_set.h"
17 class GURL;
19 namespace base {
20 class Value;
23 namespace extensions {
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
35 // Parses the externally_connectable manifest entry.
36 class ExternallyConnectableHandler : public ManifestHandler {
37 public:
38 ExternallyConnectableHandler();
39 ~ExternallyConnectableHandler() override;
41 bool Parse(Extension* extension, base::string16* error) override;
43 private:
44 const std::vector<std::string> Keys() const override;
46 DISALLOW_COPY_AND_ASSIGN(ExternallyConnectableHandler);
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);
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 bool allow_all_urls,
61 std::vector<InstallWarning>* install_warnings,
62 base::string16* error);
64 ~ExternallyConnectableInfo() override;
66 // The URL patterns that are allowed to connect/sendMessage.
67 const URLPatternSet matches;
69 // The extension IDs that are allowed to connect/sendMessage. Sorted.
70 const std::vector<std::string> ids;
72 // True if any extension is allowed to connect. This would have corresponded
73 // to an ID of "*" in |ids|.
74 const bool all_ids;
76 // True if extension accepts the TLS channel ID, when requested by the
77 // connecting origin.
78 const bool accepts_tls_channel_id;
80 // Returns true if |ids| contains |id| or if |all_ids| is true.
82 // More convenient for callers than checking each individually, and it makes
83 // use of the sortedness of |ids|.
84 bool IdCanConnect(const std::string& id);
86 // Public only for testing. Use FromValue in production.
87 ExternallyConnectableInfo(const URLPatternSet& matches,
88 const std::vector<std::string>& ids,
89 bool all_ids,
90 bool accepts_tls_channel_id);
92 private:
93 DISALLOW_COPY_AND_ASSIGN(ExternallyConnectableInfo);
96 } // namespace extensions
98 #endif // EXTENSIONS_COMMON_MANIFEST_HANDLERS_EXTERNALLY_CONNECTABLE_H_