| 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> |
| 8 |
| 9 #include "base/logging.h" |
| 7 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/values.h" |
| 8 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/extensions/event_router.h" | 13 #include "chrome/browser/extensions/event_router.h" |
| 10 #include "chrome/browser/extensions/extension_host.h" | 14 #include "chrome/browser/extensions/extension_host.h" |
| 11 #include "chrome/browser/extensions/extension_process_manager.h" | 15 #include "chrome/browser/extensions/extension_process_manager.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/extensions/extension_system.h" | 17 #include "chrome/browser/extensions/extension_system.h" |
| 14 #include "chrome/browser/extensions/lazy_background_task_queue.h" | 18 #include "chrome/browser/extensions/lazy_background_task_queue.h" |
| 15 #include "chrome/browser/extensions/updater/extension_updater.h" | 19 #include "chrome/browser/extensions/updater/extension_updater.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/profiles/profile_manager.h" | 21 #include "chrome/browser/profiles/profile_manager.h" |
| 18 #include "chrome/browser/ui/browser_finder.h" | 22 #include "chrome/browser/ui/browser_finder.h" |
| 19 #include "chrome/browser/ui/browser_navigator.h" | 23 #include "chrome/browser/ui/browser_navigator.h" |
| 20 #include "chrome/browser/ui/browser_window.h" | 24 #include "chrome/browser/ui/browser_window.h" |
| 21 #include "chrome/common/chrome_notification_types.h" | 25 #include "chrome/common/chrome_notification_types.h" |
| 22 #include "chrome/common/extensions/api/runtime.h" | |
| 23 #include "chrome/common/extensions/background_info.h" | 26 #include "chrome/common/extensions/background_info.h" |
| 24 #include "chrome/common/extensions/extension.h" | 27 #include "chrome/common/extensions/extension.h" |
| 25 #include "chrome/common/omaha_query_params/omaha_query_params.h" | 28 #include "chrome/common/omaha_query_params/omaha_query_params.h" |
| 26 #include "content/public/browser/child_process_security_policy.h" | 29 #include "content/public/browser/child_process_security_policy.h" |
| 27 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
| 28 #include "content/public/browser/render_process_host.h" | 31 #include "content/public/browser/render_process_host.h" |
| 29 #include "content/public/browser/render_view_host.h" | 32 #include "content/public/browser/render_view_host.h" |
| 30 #include "extensions/common/error_utils.h" | 33 #include "extensions/common/error_utils.h" |
| 31 #include "googleurl/src/gurl.h" | 34 #include "googleurl/src/gurl.h" |
| 32 #include "webkit/browser/fileapi/isolated_context.h" | 35 #include "webkit/browser/fileapi/isolated_context.h" |
| 33 | 36 |
| 34 namespace GetPlatformInfo = extensions::api::runtime::GetPlatformInfo; | 37 namespace GetPlatformInfo = extensions::api::runtime::GetPlatformInfo; |
| 35 | 38 |
| 36 namespace extensions { | 39 namespace extensions { |
| 37 | 40 |
| 38 namespace { | 41 namespace { |
| 39 | 42 |
| 40 const char kOnStartupEvent[] = "runtime.onStartup"; | 43 const char kOnStartupEvent[] = "runtime.onStartup"; |
| 41 const char kOnInstalledEvent[] = "runtime.onInstalled"; | 44 const char kOnInstalledEvent[] = "runtime.onInstalled"; |
| 42 const char kOnUpdateAvailableEvent[] = "runtime.onUpdateAvailable"; | 45 const char kOnUpdateAvailableEvent[] = "runtime.onUpdateAvailable"; |
| 43 const char kOnBrowserUpdateAvailableEvent[] = | 46 const char kOnBrowserUpdateAvailableEvent[] = |
| 44 "runtime.onBrowserUpdateAvailable"; | 47 "runtime.onBrowserUpdateAvailable"; |
| 48 const char kOnRestartRequiredEvent[] = "runtime.onRestartRequired"; |
| 45 const char kNoBackgroundPageError[] = "You do not have a background page."; | 49 const char kNoBackgroundPageError[] = "You do not have a background page."; |
| 46 const char kPageLoadError[] = "Background page failed to load."; | 50 const char kPageLoadError[] = "Background page failed to load."; |
| 47 const char kInstallReason[] = "reason"; | 51 const char kInstallReason[] = "reason"; |
| 48 const char kInstallReasonChromeUpdate[] = "chrome_update"; | 52 const char kInstallReasonChromeUpdate[] = "chrome_update"; |
| 49 const char kInstallReasonUpdate[] = "update"; | 53 const char kInstallReasonUpdate[] = "update"; |
| 50 const char kInstallReasonInstall[] = "install"; | 54 const char kInstallReasonInstall[] = "install"; |
| 51 const char kInstallPreviousVersion[] = "previousVersion"; | 55 const char kInstallPreviousVersion[] = "previousVersion"; |
| 52 const char kInvalidUrlError[] = "Invalid URL."; | 56 const char kInvalidUrlError[] = "Invalid URL."; |
| 53 const char kUpdatesDisabledError[] = "Autoupdate is not enabled."; | 57 const char kUpdatesDisabledError[] = "Autoupdate is not enabled."; |
| 54 const char kUpdateFound[] = "update_available"; | 58 const char kUpdateFound[] = "update_available"; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 return; | 190 return; |
| 187 | 191 |
| 188 scoped_ptr<base::ListValue> args(new base::ListValue); | 192 scoped_ptr<base::ListValue> args(new base::ListValue); |
| 189 DCHECK(system->event_router()); | 193 DCHECK(system->event_router()); |
| 190 scoped_ptr<Event> event(new Event(kOnBrowserUpdateAvailableEvent, | 194 scoped_ptr<Event> event(new Event(kOnBrowserUpdateAvailableEvent, |
| 191 args.Pass())); | 195 args.Pass())); |
| 192 system->event_router()->BroadcastEvent(event.Pass()); | 196 system->event_router()->BroadcastEvent(event.Pass()); |
| 193 } | 197 } |
| 194 | 198 |
| 195 // static | 199 // static |
| 200 void RuntimeEventRouter::DispatchOnRestartRequiredEvent( |
| 201 Profile* profile, |
| 202 const std::string& app_id, |
| 203 api::runtime::OnRestartRequired::Reason reason) { |
| 204 ExtensionSystem* system = ExtensionSystem::Get(profile); |
| 205 if (!system) |
| 206 return; |
| 207 |
| 208 scoped_ptr<Event> event( |
| 209 new Event(kOnRestartRequiredEvent, |
| 210 api::runtime::OnRestartRequired::Create(reason))); |
| 211 |
| 212 DCHECK(system->event_router()); |
| 213 system->event_router()->DispatchEventToExtension(app_id, event.Pass()); |
| 214 } |
| 215 |
| 216 // static |
| 196 void RuntimeEventRouter::OnExtensionUninstalled( | 217 void RuntimeEventRouter::OnExtensionUninstalled( |
| 197 Profile *profile, | 218 Profile* profile, |
| 198 const std::string& extension_id) { | 219 const std::string& extension_id) { |
| 199 #if defined(ENABLE_EXTENSIONS) | 220 #if defined(ENABLE_EXTENSIONS) |
| 200 GURL uninstall_url(GetUninstallUrl(ExtensionPrefs::Get(profile), | 221 GURL uninstall_url(GetUninstallUrl(ExtensionPrefs::Get(profile), |
| 201 extension_id)); | 222 extension_id)); |
| 202 | 223 |
| 203 if (uninstall_url.is_empty()) | 224 if (uninstall_url.is_empty()) |
| 204 return; | 225 return; |
| 205 | 226 |
| 206 Browser* browser = chrome::FindLastActiveWithProfile(profile, | 227 Browser* browser = chrome::FindLastActiveWithProfile(profile, |
| 207 chrome::GetActiveDesktop()); | 228 chrome::GetActiveDesktop()); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 policy->GrantReadFile(renderer_id, path); | 431 policy->GrantReadFile(renderer_id, path); |
| 411 | 432 |
| 412 base::DictionaryValue* dict = new base::DictionaryValue(); | 433 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 413 SetResult(dict); | 434 SetResult(dict); |
| 414 dict->SetString("fileSystemId", filesystem_id); | 435 dict->SetString("fileSystemId", filesystem_id); |
| 415 dict->SetString("baseName", relative_path); | 436 dict->SetString("baseName", relative_path); |
| 416 return true; | 437 return true; |
| 417 } | 438 } |
| 418 | 439 |
| 419 } // namespace extensions | 440 } // namespace extensions |
| OLD | NEW |