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 #include "chrome/browser/extensions/api/runtime/runtime_api.h" | 5 #include "chrome/browser/extensions/api/runtime/runtime_api.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
14 #include "chrome/browser/extensions/extension_host.h" | 14 #include "chrome/browser/extensions/extension_host.h" |
15 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
16 #include "chrome/browser/extensions/extension_system.h" | |
17 #include "chrome/browser/extensions/updater/extension_updater.h" | 16 #include "chrome/browser/extensions/updater/extension_updater.h" |
18 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
20 #include "chrome/browser/ui/browser_finder.h" | 19 #include "chrome/browser/ui/browser_finder.h" |
21 #include "chrome/browser/ui/browser_navigator.h" | 20 #include "chrome/browser/ui/browser_navigator.h" |
22 #include "chrome/browser/ui/browser_window.h" | 21 #include "chrome/browser/ui/browser_window.h" |
23 #include "chrome/common/extensions/api/runtime.h" | 22 #include "chrome/common/extensions/api/runtime.h" |
24 #include "chrome/common/omaha_query_params/omaha_query_params.h" | 23 #include "chrome/common/omaha_query_params/omaha_query_params.h" |
25 #include "content/public/browser/child_process_security_policy.h" | 24 #include "content/public/browser/child_process_security_policy.h" |
26 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
27 #include "content/public/browser/render_process_host.h" | 26 #include "content/public/browser/render_process_host.h" |
28 #include "content/public/browser/render_view_host.h" | 27 #include "content/public/browser/render_view_host.h" |
29 #include "extensions/browser/event_router.h" | 28 #include "extensions/browser/event_router.h" |
30 #include "extensions/browser/extension_registry.h" | 29 #include "extensions/browser/extension_registry.h" |
| 30 #include "extensions/browser/extension_system.h" |
31 #include "extensions/browser/extensions_browser_client.h" | 31 #include "extensions/browser/extensions_browser_client.h" |
32 #include "extensions/browser/lazy_background_task_queue.h" | 32 #include "extensions/browser/lazy_background_task_queue.h" |
33 #include "extensions/browser/process_manager.h" | 33 #include "extensions/browser/process_manager.h" |
34 #include "extensions/common/error_utils.h" | 34 #include "extensions/common/error_utils.h" |
35 #include "extensions/common/extension.h" | 35 #include "extensions/common/extension.h" |
36 #include "extensions/common/manifest_handlers/background_info.h" | 36 #include "extensions/common/manifest_handlers/background_info.h" |
37 #include "url/gurl.h" | 37 #include "url/gurl.h" |
38 #include "webkit/browser/fileapi/isolated_context.h" | 38 #include "webkit/browser/fileapi/isolated_context.h" |
39 | 39 |
40 #if defined(OS_CHROMEOS) | 40 #if defined(OS_CHROMEOS) |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 if (!host && !first_call) | 83 if (!host && !first_call) |
84 return; | 84 return; |
85 | 85 |
86 // Don't send onStartup events to incognito browser contexts. | 86 // Don't send onStartup events to incognito browser contexts. |
87 if (browser_context->IsOffTheRecord()) | 87 if (browser_context->IsOffTheRecord()) |
88 return; | 88 return; |
89 | 89 |
90 if (ExtensionsBrowserClient::Get()->IsShuttingDown() || | 90 if (ExtensionsBrowserClient::Get()->IsShuttingDown() || |
91 !ExtensionsBrowserClient::Get()->IsValidContext(browser_context)) | 91 !ExtensionsBrowserClient::Get()->IsValidContext(browser_context)) |
92 return; | 92 return; |
93 ExtensionSystem* system = | 93 ExtensionSystem* system = ExtensionSystem::Get(browser_context); |
94 ExtensionSystem::GetForBrowserContext(browser_context); | |
95 if (!system) | 94 if (!system) |
96 return; | 95 return; |
97 | 96 |
98 // If this is a persistent background page, we want to wait for it to load | 97 // If this is a persistent background page, we want to wait for it to load |
99 // (it might not be ready, since this is startup). But only enqueue once. | 98 // (it might not be ready, since this is startup). But only enqueue once. |
100 // If it fails to load the first time, don't bother trying again. | 99 // If it fails to load the first time, don't bother trying again. |
101 const Extension* extension = | 100 const Extension* extension = |
102 ExtensionRegistry::Get(browser_context)->enabled_extensions().GetByID( | 101 ExtensionRegistry::Get(browser_context)->enabled_extensions().GetByID( |
103 extension_id); | 102 extension_id); |
104 if (extension && BackgroundInfo::HasPersistentBackgroundPage(extension) && | 103 if (extension && BackgroundInfo::HasPersistentBackgroundPage(extension) && |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 content::Source<BrowserContext>(context)); | 152 content::Source<BrowserContext>(context)); |
154 | 153 |
155 // Check if registered events are up-to-date. We can only do this once | 154 // Check if registered events are up-to-date. We can only do this once |
156 // per browser context, since it updates internal state when called. | 155 // per browser context, since it updates internal state when called. |
157 dispatch_chrome_updated_event_ = | 156 dispatch_chrome_updated_event_ = |
158 ExtensionsBrowserClient::Get()->DidVersionUpdate(browser_context_); | 157 ExtensionsBrowserClient::Get()->DidVersionUpdate(browser_context_); |
159 } | 158 } |
160 | 159 |
161 RuntimeAPI::~RuntimeAPI() { | 160 RuntimeAPI::~RuntimeAPI() { |
162 if (registered_for_updates_) { | 161 if (registered_for_updates_) { |
163 ExtensionSystem::GetForBrowserContext(browser_context_)-> | 162 ExtensionSystem::Get(browser_context_)-> |
164 extension_service()->RemoveUpdateObserver(this); | 163 extension_service()->RemoveUpdateObserver(this); |
165 } | 164 } |
166 } | 165 } |
167 | 166 |
168 void RuntimeAPI::Observe(int type, | 167 void RuntimeAPI::Observe(int type, |
169 const content::NotificationSource& source, | 168 const content::NotificationSource& source, |
170 const content::NotificationDetails& details) { | 169 const content::NotificationDetails& details) { |
171 switch (type) { | 170 switch (type) { |
172 case chrome::NOTIFICATION_EXTENSIONS_READY: { | 171 case chrome::NOTIFICATION_EXTENSIONS_READY: { |
173 OnExtensionsReady(); | 172 OnExtensionsReady(); |
(...skipping 22 matching lines...) Expand all Loading... |
196 break; | 195 break; |
197 } | 196 } |
198 } | 197 } |
199 | 198 |
200 void RuntimeAPI::OnExtensionsReady() { | 199 void RuntimeAPI::OnExtensionsReady() { |
201 // We're done restarting Chrome after an update. | 200 // We're done restarting Chrome after an update. |
202 dispatch_chrome_updated_event_ = false; | 201 dispatch_chrome_updated_event_ = false; |
203 | 202 |
204 registered_for_updates_ = true; | 203 registered_for_updates_ = true; |
205 | 204 |
206 ExtensionSystem::GetForBrowserContext(browser_context_)->extension_service()-> | 205 ExtensionSystem::Get(browser_context_)->extension_service()-> |
207 AddUpdateObserver(this); | 206 AddUpdateObserver(this); |
208 } | 207 } |
209 | 208 |
210 void RuntimeAPI::OnExtensionLoaded(const Extension* extension) { | 209 void RuntimeAPI::OnExtensionLoaded(const Extension* extension) { |
211 if (!dispatch_chrome_updated_event_) | 210 if (!dispatch_chrome_updated_event_) |
212 return; | 211 return; |
213 | 212 |
214 // Dispatch the onInstalled event with reason "chrome_update". | 213 // Dispatch the onInstalled event with reason "chrome_update". |
215 base::MessageLoop::current()->PostTask( | 214 base::MessageLoop::current()->PostTask( |
216 FROM_HERE, | 215 FROM_HERE, |
217 base::Bind(&RuntimeEventRouter::DispatchOnInstalledEvent, | 216 base::Bind(&RuntimeEventRouter::DispatchOnInstalledEvent, |
218 browser_context_, | 217 browser_context_, |
219 extension->id(), | 218 extension->id(), |
220 Version(), | 219 Version(), |
221 true)); | 220 true)); |
222 } | 221 } |
223 | 222 |
224 void RuntimeAPI::OnExtensionInstalled(const Extension* extension) { | 223 void RuntimeAPI::OnExtensionInstalled(const Extension* extension) { |
225 // Ephemeral apps are not considered to be installed and do not receive | 224 // Ephemeral apps are not considered to be installed and do not receive |
226 // the onInstalled() event. | 225 // the onInstalled() event. |
227 if (extension->is_ephemeral()) | 226 if (extension->is_ephemeral()) |
228 return; | 227 return; |
229 | 228 |
230 // Get the previous version to check if this is an upgrade. | 229 // Get the previous version to check if this is an upgrade. |
231 ExtensionService* service = ExtensionSystem::GetForBrowserContext( | 230 ExtensionService* service = ExtensionSystem::Get( |
232 browser_context_)->extension_service(); | 231 browser_context_)->extension_service(); |
233 const Extension* old = service->GetExtensionById(extension->id(), true); | 232 const Extension* old = service->GetExtensionById(extension->id(), true); |
234 Version old_version; | 233 Version old_version; |
235 if (old) | 234 if (old) |
236 old_version = *old->version(); | 235 old_version = *old->version(); |
237 | 236 |
238 // Dispatch the onInstalled event. | 237 // Dispatch the onInstalled event. |
239 base::MessageLoop::current()->PostTask( | 238 base::MessageLoop::current()->PostTask( |
240 FROM_HERE, | 239 FROM_HERE, |
241 base::Bind(&RuntimeEventRouter::DispatchOnInstalledEvent, | 240 base::Bind(&RuntimeEventRouter::DispatchOnInstalledEvent, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 } | 275 } |
277 | 276 |
278 // static | 277 // static |
279 void RuntimeEventRouter::DispatchOnInstalledEvent( | 278 void RuntimeEventRouter::DispatchOnInstalledEvent( |
280 content::BrowserContext* context, | 279 content::BrowserContext* context, |
281 const std::string& extension_id, | 280 const std::string& extension_id, |
282 const Version& old_version, | 281 const Version& old_version, |
283 bool chrome_updated) { | 282 bool chrome_updated) { |
284 if (!ExtensionsBrowserClient::Get()->IsValidContext(context)) | 283 if (!ExtensionsBrowserClient::Get()->IsValidContext(context)) |
285 return; | 284 return; |
286 ExtensionSystem* system = ExtensionSystem::GetForBrowserContext(context); | 285 ExtensionSystem* system = ExtensionSystem::Get(context); |
287 if (!system) | 286 if (!system) |
288 return; | 287 return; |
289 | 288 |
290 scoped_ptr<base::ListValue> event_args(new base::ListValue()); | 289 scoped_ptr<base::ListValue> event_args(new base::ListValue()); |
291 base::DictionaryValue* info = new base::DictionaryValue(); | 290 base::DictionaryValue* info = new base::DictionaryValue(); |
292 event_args->Append(info); | 291 event_args->Append(info); |
293 if (old_version.IsValid()) { | 292 if (old_version.IsValid()) { |
294 info->SetString(kInstallReason, kInstallReasonUpdate); | 293 info->SetString(kInstallReason, kInstallReasonUpdate); |
295 info->SetString(kInstallPreviousVersion, old_version.GetString()); | 294 info->SetString(kInstallPreviousVersion, old_version.GetString()); |
296 } else if (chrome_updated) { | 295 } else if (chrome_updated) { |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 content::ChildProcessSecurityPolicy::GetInstance(); | 582 content::ChildProcessSecurityPolicy::GetInstance(); |
584 policy->GrantReadFileSystem(renderer_id, filesystem_id); | 583 policy->GrantReadFileSystem(renderer_id, filesystem_id); |
585 base::DictionaryValue* dict = new base::DictionaryValue(); | 584 base::DictionaryValue* dict = new base::DictionaryValue(); |
586 SetResult(dict); | 585 SetResult(dict); |
587 dict->SetString("fileSystemId", filesystem_id); | 586 dict->SetString("fileSystemId", filesystem_id); |
588 dict->SetString("baseName", relative_path); | 587 dict->SetString("baseName", relative_path); |
589 return true; | 588 return true; |
590 } | 589 } |
591 | 590 |
592 } // namespace extensions | 591 } // namespace extensions |
OLD | NEW |