OLD | NEW |
---|---|
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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_EXTENSIONS_UI_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSIONS_UI_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSIONS_UI_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSIONS_UI_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" | 11 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" |
12 #include "chrome/browser/dom_ui/dom_ui.h" | 12 #include "chrome/browser/dom_ui/dom_ui.h" |
13 #include "chrome/browser/extensions/pack_extension_job.h" | 13 #include "chrome/browser/extensions/pack_extension_job.h" |
14 #include "chrome/browser/shell_dialogs.h" | 14 #include "chrome/browser/shell_dialogs.h" |
15 #include "chrome/common/extensions/extension_resource.h" | |
15 #include "chrome/common/notification_observer.h" | 16 #include "chrome/common/notification_observer.h" |
16 #include "chrome/common/notification_registrar.h" | 17 #include "chrome/common/notification_registrar.h" |
17 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
18 | 19 |
19 class DictionaryValue; | 20 class DictionaryValue; |
20 class Extension; | 21 class Extension; |
21 class ExtensionsService; | 22 class ExtensionsService; |
22 class FilePath; | 23 class FilePath; |
23 class PrefService; | 24 class PrefService; |
24 class UserScript; | 25 class UserScript; |
(...skipping 25 matching lines...) Expand all Loading... | |
50 DISALLOW_COPY_AND_ASSIGN(ExtensionsUIHTMLSource); | 51 DISALLOW_COPY_AND_ASSIGN(ExtensionsUIHTMLSource); |
51 }; | 52 }; |
52 | 53 |
53 // The handler for Javascript messages related to the "extensions" view. | 54 // The handler for Javascript messages related to the "extensions" view. |
54 class ExtensionsDOMHandler | 55 class ExtensionsDOMHandler |
55 : public DOMMessageHandler, | 56 : public DOMMessageHandler, |
56 public NotificationObserver, | 57 public NotificationObserver, |
57 public PackExtensionJob::Client, | 58 public PackExtensionJob::Client, |
58 public SelectFileDialog::Listener { | 59 public SelectFileDialog::Listener { |
59 public: | 60 public: |
61 | |
62 // Helper class that loads the icons for the extensions in the management UI. | |
63 // We do this with native code instead of just using chrome-extension:// URLs | |
64 // for two reasons: | |
65 // | |
66 // 1. We need to support the disabled extensions, too, and using URLs won't | |
67 // work for them. | |
68 // 2. We want to desaturate the icons of the disabled extensions to make them | |
69 // look more disabled. | |
70 class IconLoader : public base::RefCountedThreadSafe<IconLoader> { | |
71 public: | |
72 IconLoader(ExtensionsDOMHandler* handler); | |
73 | |
74 // Load |icons|. Will call handler->OnIconsLoaded when complete. IconLoader | |
75 // takes ownership of both arguments. | |
76 void LoadIcons(std::vector<ExtensionResource>* icons, | |
77 DictionaryValue* json); | |
78 | |
79 // Cancel the load. IconLoader won't try to call back to the handler after | |
80 // this. | |
81 void Cancel(); | |
82 | |
83 private: | |
84 // Load the icons and call ReportResultOnUIThread when done. This method | |
85 // takes ownership of both arguments. | |
86 void LoadIconsOnFileThread(std::vector<ExtensionResource>* icons, | |
87 DictionaryValue* json); | |
88 | |
89 // Report back to the handler. This method takes ownership of |json|. | |
90 void ReportResultOnUIThread(DictionaryValue* json); | |
91 | |
92 // The handler we will report back to. | |
93 ExtensionsDOMHandler* handler_; | |
94 }; | |
95 | |
60 explicit ExtensionsDOMHandler(ExtensionsService* extension_service); | 96 explicit ExtensionsDOMHandler(ExtensionsService* extension_service); |
61 virtual ~ExtensionsDOMHandler(); | 97 virtual ~ExtensionsDOMHandler(); |
62 | 98 |
63 // DOMMessageHandler implementation. | 99 // DOMMessageHandler implementation. |
64 virtual void RegisterMessages(); | 100 virtual void RegisterMessages(); |
65 | 101 |
66 // Extension Detail JSON Struct for page. (static for ease of testing). | 102 // Extension Detail JSON Struct for page. (static for ease of testing). |
67 static DictionaryValue* CreateExtensionDetailValue( | 103 static DictionaryValue* CreateExtensionDetailValue( |
68 const Extension *extension, | 104 const Extension *extension, |
69 const std::vector<ExtensionPage>&, | 105 const std::vector<ExtensionPage>&, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 | 164 |
129 // NotificationObserver | 165 // NotificationObserver |
130 virtual void Observe(NotificationType type, | 166 virtual void Observe(NotificationType type, |
131 const NotificationSource& source, | 167 const NotificationSource& source, |
132 const NotificationDetails& details); | 168 const NotificationDetails& details); |
133 | 169 |
134 // Helper that lists the current active html pages for an extension. | 170 // Helper that lists the current active html pages for an extension. |
135 std::vector<ExtensionPage> GetActivePagesForExtension( | 171 std::vector<ExtensionPage> GetActivePagesForExtension( |
136 const std::string& extension_id); | 172 const std::string& extension_id); |
137 | 173 |
174 // Returns the best icon to display in the UI for an extension, or NULL if no | |
175 // good icon exists. | |
176 ExtensionResource PickExtensionIcon(Extension* extension); | |
177 | |
178 // Loads the extension resources into the json data, then calls OnIconsLoaded. | |
179 // Takes ownership of |icons|. | |
180 // Called on the file thread. | |
181 void LoadExtensionIcons(std::vector<ExtensionResource>* icons, | |
182 DictionaryValue* json_data); | |
183 | |
184 // Tells the HTML about |json_data|. | |
185 // Takes ownership of |json_data|. | |
186 // Called on the UI thread. | |
187 void OnIconsLoaded(DictionaryValue* json_data); | |
188 | |
138 // Our model. | 189 // Our model. |
139 scoped_refptr<ExtensionsService> extensions_service_; | 190 scoped_refptr<ExtensionsService> extensions_service_; |
140 | 191 |
141 // Used to pick the directory when loading an extension. | 192 // Used to pick the directory when loading an extension. |
142 scoped_refptr<SelectFileDialog> load_extension_dialog_; | 193 scoped_refptr<SelectFileDialog> load_extension_dialog_; |
143 | 194 |
144 // Used to package the extension. | 195 // Used to package the extension. |
145 scoped_refptr<PackExtensionJob> pack_job_; | 196 scoped_refptr<PackExtensionJob> pack_job_; |
146 | 197 |
198 // Used to load icons. | |
Finnur
2009/11/05 03:55:08
nit: This comment is a bit scarce. Can you add: "a
| |
199 scoped_refptr<IconLoader> icon_loader_; | |
200 | |
147 // We monitor changes to the extension system so that we can reload when | 201 // We monitor changes to the extension system so that we can reload when |
148 // necessary. | 202 // necessary. |
149 NotificationRegistrar registrar_; | 203 NotificationRegistrar registrar_; |
150 | 204 |
151 DISALLOW_COPY_AND_ASSIGN(ExtensionsDOMHandler); | 205 DISALLOW_COPY_AND_ASSIGN(ExtensionsDOMHandler); |
152 }; | 206 }; |
153 | 207 |
154 class ExtensionsUI : public DOMUI { | 208 class ExtensionsUI : public DOMUI { |
155 public: | 209 public: |
156 explicit ExtensionsUI(TabContents* contents); | 210 explicit ExtensionsUI(TabContents* contents); |
157 | 211 |
158 static RefCountedMemory* GetFaviconResourceBytes(); | 212 static RefCountedMemory* GetFaviconResourceBytes(); |
159 | 213 |
160 static void RegisterUserPrefs(PrefService* prefs); | 214 static void RegisterUserPrefs(PrefService* prefs); |
161 | 215 |
162 private: | 216 private: |
163 DISALLOW_COPY_AND_ASSIGN(ExtensionsUI); | 217 DISALLOW_COPY_AND_ASSIGN(ExtensionsUI); |
164 }; | 218 }; |
165 | 219 |
166 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSIONS_UI_H_ | 220 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSIONS_UI_H_ |
OLD | NEW |