OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_API_RUNTIME_RUNTIME_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_RUNTIME_RUNTIME_API_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_RUNTIME_RUNTIME_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_RUNTIME_RUNTIME_API_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "chrome/browser/extensions/chrome_extension_function.h" | 10 #include "chrome/browser/extensions/chrome_extension_function.h" |
11 #include "chrome/common/extensions/api/runtime.h" | 11 #include "chrome/common/extensions/api/runtime.h" |
| 12 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" |
12 #include "content/public/browser/notification_observer.h" | 13 #include "content/public/browser/notification_observer.h" |
13 #include "content/public/browser/notification_registrar.h" | 14 #include "content/public/browser/notification_registrar.h" |
14 | 15 |
15 class Profile; | 16 class Profile; |
16 | 17 |
17 namespace base { | 18 namespace base { |
18 class Version; | 19 class Version; |
19 } | 20 } |
20 | 21 |
21 namespace content { | 22 namespace content { |
22 class BrowserContext; | 23 class BrowserContext; |
23 } | 24 } |
24 | 25 |
25 namespace extensions { | 26 namespace extensions { |
26 class Extension; | 27 class Extension; |
27 class ExtensionHost; | 28 class ExtensionHost; |
28 | 29 |
| 30 // Runtime API dispatches onStartup, onInstalled, and similar events to |
| 31 // extensions. There is one instance shared between a browser context and |
| 32 // its related incognito instance. |
| 33 class RuntimeAPI : public BrowserContextKeyedService, |
| 34 public content::NotificationObserver { |
| 35 public: |
| 36 explicit RuntimeAPI(content::BrowserContext* context); |
| 37 virtual ~RuntimeAPI(); |
| 38 |
| 39 // content::NotificationObserver overrides: |
| 40 virtual void Observe(int type, |
| 41 const content::NotificationSource& source, |
| 42 const content::NotificationDetails& details) OVERRIDE; |
| 43 |
| 44 private: |
| 45 void OnExtensionsReady(); |
| 46 void OnExtensionLoaded(const Extension* extension); |
| 47 void OnExtensionInstalled(const Extension* extension); |
| 48 |
| 49 content::BrowserContext* browser_context_; |
| 50 |
| 51 // True if we should dispatch the chrome.runtime.onInstalled event with |
| 52 // reason "chrome_update" upon loading each extension. |
| 53 bool dispatch_chrome_updated_event_; |
| 54 |
| 55 content::NotificationRegistrar registrar_; |
| 56 |
| 57 DISALLOW_COPY_AND_ASSIGN(RuntimeAPI); |
| 58 }; |
| 59 |
29 class RuntimeEventRouter { | 60 class RuntimeEventRouter { |
30 public: | 61 public: |
31 // Dispatches the onStartup event to all currently-loaded extensions. | 62 // Dispatches the onStartup event to all currently-loaded extensions. |
32 static void DispatchOnStartupEvent(content::BrowserContext* context, | 63 static void DispatchOnStartupEvent(content::BrowserContext* context, |
33 const std::string& extension_id); | 64 const std::string& extension_id); |
34 | 65 |
35 // Dispatches the onInstalled event to the given extension. | 66 // Dispatches the onInstalled event to the given extension. |
36 static void DispatchOnInstalledEvent(content::BrowserContext* context, | 67 static void DispatchOnInstalledEvent(content::BrowserContext* context, |
37 const std::string& extension_id, | 68 const std::string& extension_id, |
38 const base::Version& old_version, | 69 const base::Version& old_version, |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 RUNTIME_GETPACKAGEDIRECTORYENTRY) | 169 RUNTIME_GETPACKAGEDIRECTORYENTRY) |
139 | 170 |
140 protected: | 171 protected: |
141 virtual ~RuntimeGetPackageDirectoryEntryFunction() {} | 172 virtual ~RuntimeGetPackageDirectoryEntryFunction() {} |
142 virtual bool RunImpl() OVERRIDE; | 173 virtual bool RunImpl() OVERRIDE; |
143 }; | 174 }; |
144 | 175 |
145 } // namespace extensions | 176 } // namespace extensions |
146 | 177 |
147 #endif // CHROME_BROWSER_EXTENSIONS_API_RUNTIME_RUNTIME_API_H_ | 178 #endif // CHROME_BROWSER_EXTENSIONS_API_RUNTIME_RUNTIME_API_H_ |
OLD | NEW |