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 "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/extensions/event_router.h" | 9 #include "chrome/browser/extensions/event_router.h" |
10 #include "chrome/browser/extensions/extension_host.h" | 10 #include "chrome/browser/extensions/extension_host.h" |
11 #include "chrome/browser/extensions/extension_process_manager.h" | 11 #include "chrome/browser/extensions/extension_process_manager.h" |
12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
13 #include "chrome/browser/extensions/extension_system.h" | 13 #include "chrome/browser/extensions/extension_system.h" |
14 #include "chrome/browser/extensions/lazy_background_task_queue.h" | 14 #include "chrome/browser/extensions/lazy_background_task_queue.h" |
15 #include "chrome/browser/extensions/updater/extension_updater.h" | 15 #include "chrome/browser/extensions/updater/extension_updater.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
18 #include "chrome/browser/ui/browser_finder.h" | 18 #include "chrome/browser/ui/browser_finder.h" |
19 #include "chrome/browser/ui/browser_navigator.h" | 19 #include "chrome/browser/ui/browser_navigator.h" |
20 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
21 #include "chrome/common/extensions/api/runtime.h" | 21 #include "chrome/common/extensions/api/runtime.h" |
22 #include "chrome/common/extensions/background_info.h" | 22 #include "chrome/common/extensions/background_info.h" |
23 #include "chrome/common/extensions/extension.h" | 23 #include "chrome/common/extensions/extension.h" |
24 #include "chrome/common/omaha_query_params/omaha_query_params.h" | 24 #include "chrome/common/omaha_query_params/omaha_query_params.h" |
| 25 #include "content/public/browser/child_process_security_policy.h" |
| 26 #include "content/public/browser/render_process_host.h" |
| 27 #include "content/public/browser/render_view_host.h" |
25 #include "extensions/common/error_utils.h" | 28 #include "extensions/common/error_utils.h" |
26 #include "googleurl/src/gurl.h" | 29 #include "googleurl/src/gurl.h" |
| 30 #include "webkit/browser/fileapi/isolated_context.h" |
27 | 31 |
28 namespace GetPlatformInfo = extensions::api::runtime::GetPlatformInfo; | 32 namespace GetPlatformInfo = extensions::api::runtime::GetPlatformInfo; |
29 | 33 |
30 namespace extensions { | 34 namespace extensions { |
31 | 35 |
32 namespace { | 36 namespace { |
33 | 37 |
34 const char kOnStartupEvent[] = "runtime.onStartup"; | 38 const char kOnStartupEvent[] = "runtime.onStartup"; |
35 const char kOnInstalledEvent[] = "runtime.onInstalled"; | 39 const char kOnInstalledEvent[] = "runtime.onInstalled"; |
36 const char kOnUpdateAvailableEvent[] = "runtime.onUpdateAvailable"; | 40 const char kOnUpdateAvailableEvent[] = "runtime.onUpdateAvailable"; |
37 const char kOnBrowserUpdateAvailableEvent[] = | 41 const char kOnBrowserUpdateAvailableEvent[] = |
38 "runtime.onBrowserUpdateAvailable"; | 42 "runtime.onBrowserUpdateAvailable"; |
39 const char kNoBackgroundPageError[] = "You do not have a background page."; | 43 const char kNoBackgroundPageError[] = "You do not have a background page."; |
40 const char kPageLoadError[] = "Background page failed to load."; | 44 const char kPageLoadError[] = "Background page failed to load."; |
41 const char kInstallReason[] = "reason"; | 45 const char kInstallReason[] = "reason"; |
42 const char kInstallReasonChromeUpdate[] = "chrome_update"; | 46 const char kInstallReasonChromeUpdate[] = "chrome_update"; |
43 const char kInstallReasonUpdate[] = "update"; | 47 const char kInstallReasonUpdate[] = "update"; |
44 const char kInstallReasonInstall[] = "install"; | 48 const char kInstallReasonInstall[] = "install"; |
45 const char kInstallPreviousVersion[] = "previousVersion"; | 49 const char kInstallPreviousVersion[] = "previousVersion"; |
46 const char kInvalidUrlError[] = "Invalid URL."; | 50 const char kInvalidUrlError[] = "Invalid URL."; |
47 const char kUpdatesDisabledError[] = "Autoupdate is not enabled."; | 51 const char kUpdatesDisabledError[] = "Autoupdate is not enabled."; |
48 const char kUpdateFound[] = "update_available"; | 52 const char kUpdateFound[] = "update_available"; |
49 const char kUpdateNotFound[] = "no_update"; | 53 const char kUpdateNotFound[] = "no_update"; |
50 const char kUpdateThrottled[] = "throttled"; | 54 const char kUpdateThrottled[] = "throttled"; |
51 | 55 |
52 // A preference key storing the url loaded when an extension is uninstalled. | 56 // A preference key storing the url loaded when an extension is uninstalled. |
53 const char kUninstallUrl[] = "uninstall_url"; | 57 const char kUninstallUrl[] = "uninstall_url"; |
54 | 58 |
| 59 // The name of the directory to be returned by getPackageDirectoryEntry. This |
| 60 // particular value does not matter to user code, but is chosen for consistency |
| 61 // with the equivalent Pepper API. |
| 62 const char kPackageDirectoryPath[] = "crxfs"; |
| 63 |
55 static void DispatchOnStartupEventImpl( | 64 static void DispatchOnStartupEventImpl( |
56 Profile* profile, | 65 Profile* profile, |
57 const std::string& extension_id, | 66 const std::string& extension_id, |
58 bool first_call, | 67 bool first_call, |
59 ExtensionHost* host) { | 68 ExtensionHost* host) { |
60 // A NULL host from the LazyBackgroundTaskQueue means the page failed to | 69 // A NULL host from the LazyBackgroundTaskQueue means the page failed to |
61 // load. Give up. | 70 // load. Give up. |
62 if (!host && !first_call) | 71 if (!host && !first_call) |
63 return; | 72 return; |
64 | 73 |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 info.nacl_arch = GetPlatformInfo::Results::PlatformInfo::NACL_ARCH_X86_64; | 382 info.nacl_arch = GetPlatformInfo::Results::PlatformInfo::NACL_ARCH_X86_64; |
374 } else { | 383 } else { |
375 NOTREACHED(); | 384 NOTREACHED(); |
376 return false; | 385 return false; |
377 } | 386 } |
378 | 387 |
379 results_ = GetPlatformInfo::Results::Create(info); | 388 results_ = GetPlatformInfo::Results::Create(info); |
380 return true; | 389 return true; |
381 } | 390 } |
382 | 391 |
| 392 bool RuntimeGetPackageDirectoryEntryFunction::RunImpl() { |
| 393 fileapi::IsolatedContext* isolated_context = |
| 394 fileapi::IsolatedContext::GetInstance(); |
| 395 DCHECK(isolated_context); |
| 396 |
| 397 std::string relative_path = kPackageDirectoryPath; |
| 398 base::FilePath path = extension_->path(); |
| 399 std::string filesystem_id = isolated_context->RegisterFileSystemForPath( |
| 400 fileapi::kFileSystemTypeNativeLocal, path, &relative_path); |
| 401 |
| 402 int renderer_id = render_view_host_->GetProcess()->GetID(); |
| 403 content::ChildProcessSecurityPolicy* policy = |
| 404 content::ChildProcessSecurityPolicy::GetInstance(); |
| 405 policy->GrantReadFileSystem(renderer_id, filesystem_id); |
| 406 |
| 407 if (!policy->CanReadFile(renderer_id, path)) |
| 408 policy->GrantReadFile(renderer_id, path); |
| 409 |
| 410 DictionaryValue* dict = new DictionaryValue(); |
| 411 SetResult(dict); |
| 412 dict->SetString("fileSystemId", filesystem_id); |
| 413 dict->SetString("baseName", relative_path); |
| 414 return true; |
| 415 } |
| 416 |
383 } // namespace extensions | 417 } // namespace extensions |
OLD | NEW |