1 // Copyright (c) 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_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGING_HOST_MANIFEST_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGING_HOST_MANIFEST_H_
7 
8 #include <memory>
9 #include <string>
10 
11 #include "base/files/file_path.h"
12 #include "base/macros.h"
13 #include "extensions/common/url_pattern_set.h"
14 
15 namespace base {
16 class DictionaryValue;
17 }
18 
19 namespace extensions {
20 
21 class NativeMessagingHostManifest {
22  public:
23   enum HostInterface {
24     HOST_INTERFACE_STDIO,
25   };
26 
27   ~NativeMessagingHostManifest();
28 
29   // Verifies that the name is valid. Valid names must match regular expression
30   // "([a-z0-9_]+.)*[a-z0-9_]+".
31   static bool IsValidName(const std::string& name);
32 
33   // Load manifest file from |file_path|.
34   static std::unique_ptr<NativeMessagingHostManifest> Load(
35       const base::FilePath& file_path,
36       std::string* error_message);
37 
name()38   const std::string& name() const { return name_; }
description()39   const std::string& description() const { return description_; }
host_interface()40   HostInterface host_interface() const { return interface_; }
path()41   const base::FilePath& path() const { return path_; }
allowed_origins()42   const URLPatternSet& allowed_origins() const { return allowed_origins_; }
supports_native_initiated_connections()43   bool supports_native_initiated_connections() const {
44     return supports_native_initiated_connections_;
45   }
46 
47  private:
48   NativeMessagingHostManifest();
49 
50   // Parses manifest |dictionary|. In case of an error sets |error_message| and
51   // returns false.
52   bool Parse(base::DictionaryValue* dictionary, std::string* error_message);
53 
54   std::string name_;
55   std::string description_;
56   HostInterface interface_;
57   base::FilePath path_;
58   URLPatternSet allowed_origins_;
59   bool supports_native_initiated_connections_ = false;
60 
61   DISALLOW_COPY_AND_ASSIGN(NativeMessagingHostManifest);
62 };
63 
64 }  // namespace extensions
65 
66 #endif  // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGING_HOST_MANIFEST_H_
67