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