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 "content/public/browser/notification_observer.h" | 12 #include "content/public/browser/notification_observer.h" |
12 #include "content/public/browser/notification_registrar.h" | 13 #include "content/public/browser/notification_registrar.h" |
13 #include "extensions/browser/browser_context_keyed_api_factory.h" | 14 #include "extensions/browser/browser_context_keyed_api_factory.h" |
14 #include "extensions/browser/update_observer.h" | 15 #include "extensions/browser/update_observer.h" |
15 | 16 |
16 class Profile; | 17 class Profile; |
17 | 18 |
| 19 namespace base { |
| 20 class Version; |
| 21 } |
| 22 |
18 namespace content { | 23 namespace content { |
19 class BrowserContext; | 24 class BrowserContext; |
20 } | 25 } |
21 | 26 |
22 namespace extensions { | 27 namespace extensions { |
23 class Extension; | 28 class Extension; |
24 class ExtensionHost; | 29 class ExtensionHost; |
25 | 30 |
26 // Runtime API dispatches onStartup, onInstalled, and similar events to | 31 // Runtime API dispatches onStartup, onInstalled, and similar events to |
27 // extensions. There is one instance shared between a browser context and | 32 // extensions. There is one instance shared between a browser context and |
(...skipping 13 matching lines...) Expand all Loading... |
41 const content::NotificationDetails& details) OVERRIDE; | 46 const content::NotificationDetails& details) OVERRIDE; |
42 | 47 |
43 private: | 48 private: |
44 friend class BrowserContextKeyedAPIFactory<RuntimeAPI>; | 49 friend class BrowserContextKeyedAPIFactory<RuntimeAPI>; |
45 | 50 |
46 void OnExtensionsReady(); | 51 void OnExtensionsReady(); |
47 void OnExtensionLoaded(const Extension* extension); | 52 void OnExtensionLoaded(const Extension* extension); |
48 void OnExtensionInstalled(const Extension* extension); | 53 void OnExtensionInstalled(const Extension* extension); |
49 void OnExtensionUninstalled(const Extension* extension); | 54 void OnExtensionUninstalled(const Extension* extension); |
50 | 55 |
51 // Shows the uninstall URL in a new tab. | |
52 static void ShowUninstallURL(Profile* profile, | |
53 const std::string& extension_id); | |
54 | |
55 // BrowserContextKeyedAPI implementation: | 56 // BrowserContextKeyedAPI implementation: |
56 static const char* service_name() { return "RuntimeAPI"; } | 57 static const char* service_name() { return "RuntimeAPI"; } |
57 static const bool kServiceRedirectedInIncognito = true; | 58 static const bool kServiceRedirectedInIncognito = true; |
58 static const bool kServiceIsNULLWhileTesting = true; | 59 static const bool kServiceIsNULLWhileTesting = true; |
59 | 60 |
60 // extensions::UpdateObserver overrides: | 61 // extensions::UpdateObserver overrides: |
61 virtual void OnAppUpdateAvailable(const Extension* extension) OVERRIDE; | 62 virtual void OnAppUpdateAvailable(const Extension* extension) OVERRIDE; |
62 virtual void OnChromeUpdateAvailable() OVERRIDE; | 63 virtual void OnChromeUpdateAvailable() OVERRIDE; |
63 | 64 |
64 content::BrowserContext* browser_context_; | 65 content::BrowserContext* browser_context_; |
65 | 66 |
66 // True if we should dispatch the chrome.runtime.onInstalled event with | 67 // True if we should dispatch the chrome.runtime.onInstalled event with |
67 // reason "chrome_update" upon loading each extension. | 68 // reason "chrome_update" upon loading each extension. |
68 bool dispatch_chrome_updated_event_; | 69 bool dispatch_chrome_updated_event_; |
69 | 70 |
70 // Whether the API registered with the ExtensionService to receive | 71 // Whether the API registered with the ExtensionService to receive |
71 // update notifications. | 72 // update notifications. |
72 bool registered_for_updates_; | 73 bool registered_for_updates_; |
73 | 74 |
74 content::NotificationRegistrar registrar_; | 75 content::NotificationRegistrar registrar_; |
75 | 76 |
76 DISALLOW_COPY_AND_ASSIGN(RuntimeAPI); | 77 DISALLOW_COPY_AND_ASSIGN(RuntimeAPI); |
77 }; | 78 }; |
78 | 79 |
| 80 class RuntimeEventRouter { |
| 81 public: |
| 82 // Dispatches the onStartup event to all currently-loaded extensions. |
| 83 static void DispatchOnStartupEvent(content::BrowserContext* context, |
| 84 const std::string& extension_id); |
| 85 |
| 86 // Dispatches the onInstalled event to the given extension. |
| 87 static void DispatchOnInstalledEvent(content::BrowserContext* context, |
| 88 const std::string& extension_id, |
| 89 const base::Version& old_version, |
| 90 bool chrome_updated); |
| 91 |
| 92 // Dispatches the onUpdateAvailable event to the given extension. |
| 93 static void DispatchOnUpdateAvailableEvent( |
| 94 Profile* profile, |
| 95 const std::string& extension_id, |
| 96 const base::DictionaryValue* manifest); |
| 97 |
| 98 // Dispatches the onBrowserUpdateAvailable event to all extensions. |
| 99 static void DispatchOnBrowserUpdateAvailableEvent(Profile* profile); |
| 100 |
| 101 // Dispatches the onRestartRequired event to the given app. |
| 102 static void DispatchOnRestartRequiredEvent( |
| 103 Profile* profile, |
| 104 const std::string& app_id, |
| 105 api::runtime::OnRestartRequired::Reason reason); |
| 106 |
| 107 // Does any work needed at extension uninstall (e.g. load uninstall url). |
| 108 static void OnExtensionUninstalled(Profile* profile, |
| 109 const std::string& extension_id); |
| 110 }; |
| 111 |
79 class RuntimeGetBackgroundPageFunction : public ChromeAsyncExtensionFunction { | 112 class RuntimeGetBackgroundPageFunction : public ChromeAsyncExtensionFunction { |
80 public: | 113 public: |
81 DECLARE_EXTENSION_FUNCTION("runtime.getBackgroundPage", | 114 DECLARE_EXTENSION_FUNCTION("runtime.getBackgroundPage", |
82 RUNTIME_GETBACKGROUNDPAGE) | 115 RUNTIME_GETBACKGROUNDPAGE) |
83 | 116 |
84 protected: | 117 protected: |
85 virtual ~RuntimeGetBackgroundPageFunction() {} | 118 virtual ~RuntimeGetBackgroundPageFunction() {} |
86 virtual bool RunImpl() OVERRIDE; | 119 virtual bool RunImpl() OVERRIDE; |
87 | 120 |
88 private: | 121 private: |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 RUNTIME_GETPACKAGEDIRECTORYENTRY) | 189 RUNTIME_GETPACKAGEDIRECTORYENTRY) |
157 | 190 |
158 protected: | 191 protected: |
159 virtual ~RuntimeGetPackageDirectoryEntryFunction() {} | 192 virtual ~RuntimeGetPackageDirectoryEntryFunction() {} |
160 virtual bool RunImpl() OVERRIDE; | 193 virtual bool RunImpl() OVERRIDE; |
161 }; | 194 }; |
162 | 195 |
163 } // namespace extensions | 196 } // namespace extensions |
164 | 197 |
165 #endif // CHROME_BROWSER_EXTENSIONS_API_RUNTIME_RUNTIME_API_H_ | 198 #endif // CHROME_BROWSER_EXTENSIONS_API_RUNTIME_RUNTIME_API_H_ |
OLD | NEW |