Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(262)

Side by Side Diff: chrome/browser/extensions/component_loader.h

Issue 8477005: Add policies to specify an enterprise web store. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebasse. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_COMPONENT_LOADER_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_COMPONENT_LOADER_H_
6 #define CHROME_BROWSER_EXTENSIONS_COMPONENT_LOADER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_COMPONENT_LOADER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/values.h"
13 #include "chrome/browser/prefs/pref_change_registrar.h"
14 #include "content/public/browser/notification_observer.h"
15 #include "testing/gtest/include/gtest/gtest_prod.h"
12 16
13 class Extension; 17 class Extension;
14 class ExtensionService; 18 class ExtensionServiceInterface;
19 class PrefService;
15 20
16 namespace extensions { 21 namespace extensions {
17 22
18 // For registering, loading, and unloading component extensions. 23 // For registering, loading, and unloading component extensions.
19 class ComponentLoader { 24 class ComponentLoader : public content::NotificationObserver {
20 public: 25 public:
21 explicit ComponentLoader(ExtensionService* extension_service); 26 ComponentLoader(ExtensionServiceInterface* extension_service,
27 PrefService* prefs,
28 PrefService* local_state);
22 virtual ~ComponentLoader(); 29 virtual ~ComponentLoader();
23 30
24 // Loads any registered component extensions. 31 // Loads any registered component extensions.
25 void LoadAll(); 32 void LoadAll();
26 33
27 // Loads and registers a component extension. If ExtensionService has been 34 // Registers and possibly loads a component extension. If ExtensionService
28 // initialized, the extension is loaded; otherwise, the load is deferred 35 // has been initialized, the extension is loaded; otherwise, the load is
29 // until LoadAll is called. 36 // deferred until LoadAll is called.
30 const Extension* Add(const std::string& manifest, 37 const Extension* Add(std::string& manifest_contents,
38 const FilePath& root_directory);
39
40 // Convenience method for registering a component extension by resource id.
41 const Extension* Add(int manifest_resource_id,
31 const FilePath& root_directory); 42 const FilePath& root_directory);
32 43
33 // Unloads a component extension and removes it from the list of component 44 // Unloads a component extension and removes it from the list of component
34 // extensions to be loaded. 45 // extensions to be loaded.
35 void Remove(const std::string& manifest_str); 46 void Remove(const FilePath& root_directory);
36 47
37 // Adds the default component extensions. 48 // Adds the default component extensions.
38 // 49 //
39 // Component extension manifests must contain a 'key' property with a unique 50 // Component extension manifests must contain a 'key' property with a unique
40 // public key, serialized in base64. You can create a suitable value with the 51 // public key, serialized in base64. You can create a suitable value with the
41 // following commands on a unixy system: 52 // following commands on a unixy system:
42 // 53 //
43 // ssh-keygen -t rsa -b 1024 -N '' -f /tmp/key.pem 54 // ssh-keygen -t rsa -b 1024 -N '' -f /tmp/key.pem
44 // openssl rsa -pubout -outform DER < /tmp/key.pem 2>/dev/null | base64 -w 0 55 // openssl rsa -pubout -outform DER < /tmp/key.pem 2>/dev/null | base64 -w 0
45 void AddDefaultComponentExtensions(); 56 void AddDefaultComponentExtensions();
46 57
58 // content::NotificationObserver implementation
59 virtual void Observe(int type,
60 const content::NotificationSource& source,
61 const content::NotificationDetails& details) OVERRIDE;
62
63 static void RegisterUserPrefs(PrefService* prefs);
64
65 // Parse the given JSON manifest. Returns NULL if it cannot be parsed, or if
66 // if the result is not a DictionaryValue.
67 DictionaryValue* ParseManifest(const std::string& manifest_contents) const;
68
69 // Clear the list of registered extensions.
70 void ClearAllRegistered() {
71 component_extensions_.clear();
72 }
73
47 private: 74 private:
48 // Information about a registered component extension. 75 // Information about a registered component extension.
49 struct ComponentExtensionInfo { 76 struct ComponentExtensionInfo {
50 ComponentExtensionInfo(const std::string& manifest, 77 ComponentExtensionInfo(const DictionaryValue* manifest,
51 const FilePath& root_directory) 78 const FilePath& root_directory)
52 : manifest(manifest), 79 : manifest(manifest),
53 root_directory(root_directory) { 80 root_directory(root_directory) {
54 } 81 }
55 82
56 bool Equals(const ComponentExtensionInfo& other) const; 83 // The parsed contents of the extensions's manifest file.
57 84 const DictionaryValue* manifest;
58 // The extension's manifest. This is required for component extensions so
59 // that ExtensionService doesn't need to go to disk to load them.
60 std::string manifest;
61 85
62 // Directory where the extension is stored. 86 // Directory where the extension is stored.
63 FilePath root_directory; 87 FilePath root_directory;
64 }; 88 };
65 89
90 const Extension* Add(const DictionaryValue* parsed_manifest,
91 const FilePath& root_directory);
92
66 // Loads a registered component extension. 93 // Loads a registered component extension.
67 const Extension* Load(const ComponentExtensionInfo& info); 94 const Extension* Load(const ComponentExtensionInfo& info);
68 95
69 // Registers an extension to be loaded as a component extension. 96 void AddFileManagerExtension();
70 void Register(const ComponentExtensionInfo& info) { 97
71 component_extensions_.push_back(info); 98 // Add the enterprise webstore extension, or reload it if already loaded.
72 } 99 void AddOrReloadEnterpriseWebStore();
100
101 PrefService* prefs_;
102 PrefService* local_state_;
103
104 ExtensionServiceInterface* extension_service_;
73 105
74 // List of registered component extensions (see Extension::Location). 106 // List of registered component extensions (see Extension::Location).
75 typedef std::vector<ComponentExtensionInfo> RegisteredComponentExtensions; 107 typedef std::vector<ComponentExtensionInfo> RegisteredComponentExtensions;
76 RegisteredComponentExtensions component_extensions_; 108 RegisteredComponentExtensions component_extensions_;
77 109
78 ExtensionService* extension_service_; 110 PrefChangeRegistrar pref_change_registrar_;
79 }; 111 };
80 112
81 } // namespace extensions 113 } // namespace extensions
82 114
83 #endif // CHROME_BROWSER_EXTENSIONS_COMPONENT_LOADER_H_ 115 #endif // CHROME_BROWSER_EXTENSIONS_COMPONENT_LOADER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698