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. 4 5 #ifndef CHROME_COMMON_EXTENSIONS_MANIFEST_HANDLERS_AUTOMATION_H_ 6 #define CHROME_COMMON_EXTENSIONS_MANIFEST_HANDLERS_AUTOMATION_H_ 7 8 #include <string> 9 10 #include "base/memory/scoped_ptr.h" 11 #include "extensions/common/extension.h" 12 #include "extensions/common/manifest_handler.h" 13 #include "extensions/common/url_pattern_set.h" 14 #include "extensions/common/user_script.h" 15 16 namespace extensions { 17 18 namespace api { 19 namespace manifest_types { 20 struct Automation; 21 } 22 } 23 24 class URLPatternSet; 25 class AutomationManifestPermission; 26 27 namespace automation_errors { 28 extern const char kErrorInvalidMatchPattern[]; 29 extern const char kErrorDesktopTrueInteractFalse[]; 30 extern const char kErrorDesktopTrueMatchesSpecified[]; 31 extern const char kErrorURLMalformed[]; 32 extern const char kErrorInvalidMatch[]; 33 extern const char kErrorNoMatchesProvided[]; 34 } 35 36 // The parsed form of the automation manifest entry. 37 struct AutomationInfo : public Extension::ManifestData { 38 public: 39 static const AutomationInfo* Get(const Extension* extension); 40 static scoped_ptr<AutomationInfo> FromValue( 41 const base::Value& value, 42 std::vector<InstallWarning>* install_warnings, 43 base::string16* error); 44 45 static scoped_ptr<base::Value> ToValue(const AutomationInfo& info); 46 virtual ~AutomationInfo(); 47 48 // true if the extension has requested 'desktop' permission. 49 const bool desktop; 50 51 // Returns the list of hosts that this extension can request an automation 52 // tree from. 53 const URLPatternSet matches; 54 55 // Whether the extension is allowed interactive access (true) or read-only 56 // access (false) to the automation tree. 57 const bool interact; 58 59 private: 60 AutomationInfo(); 61 AutomationInfo(bool desktop, URLPatternSet matches, bool interact); 62 63 static scoped_ptr<api::manifest_types::Automation> AsManifestType( 64 const AutomationInfo& info); 65 66 DISALLOW_COPY_AND_ASSIGN(AutomationInfo); 67 friend class AutomationManifestPermission; 68 friend class AutomationHandler; 69 }; 70 71 // Parses the automation manifest entry. 72 class AutomationHandler : public ManifestHandler { 73 public: 74 AutomationHandler(); 75 virtual ~AutomationHandler(); 76 77 private: 78 // ManifestHandler implementation. 79 virtual bool Parse(Extension* extensions, base::string16* error) OVERRIDE; 80 81 virtual ManifestPermission* CreatePermission() OVERRIDE; 82 virtual ManifestPermission* CreateInitialRequiredPermission( 83 const Extension* extension) OVERRIDE; 84 virtual const std::vector<std::string> Keys() const OVERRIDE; 85 86 DISALLOW_COPY_AND_ASSIGN(AutomationHandler); 87 }; 88 89 } // namespace extensions 90 91 #endif // CHROME_COMMON_EXTENSIONS_MANIFEST_HANDLERS_AUTOMATION_H_ 92