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 "base/strings/string_split.h" |
| 6 #include "base/values.h" |
| 7 #include "base/version.h" |
5 #include "chrome/common/pepper_flash.h" | 8 #include "chrome/common/pepper_flash.h" |
| 9 #include "chrome/common/ppapi_utils.h" |
| 10 #include "ppapi/c/private/ppb_pdf.h" |
| 11 #include "ppapi/shared_impl/ppapi_permissions.h" |
6 | 12 |
7 #include "ppapi/shared_impl/ppapi_permissions.h" | 13 namespace chrome { |
8 | 14 |
9 const int32 kPepperFlashPermissions = ppapi::PERMISSION_DEV | | 15 const int32 kPepperFlashPermissions = ppapi::PERMISSION_DEV | |
10 ppapi::PERMISSION_PRIVATE | | 16 ppapi::PERMISSION_PRIVATE | |
11 ppapi::PERMISSION_BYPASS_USER_GESTURE | | 17 ppapi::PERMISSION_BYPASS_USER_GESTURE | |
12 ppapi::PERMISSION_FLASH; | 18 ppapi::PERMISSION_FLASH; |
| 19 namespace { |
13 | 20 |
| 21 // File name of the Pepper Flash component manifest on different platforms. |
| 22 const char kPepperFlashManifestName[] = "Flapper"; |
| 23 |
| 24 // Name of the Pepper Flash OS in the component manifest. |
| 25 const char kPepperFlashOperatingSystem[] = |
| 26 #if defined(OS_MACOSX) |
| 27 "mac"; |
| 28 #elif defined(OS_WIN) |
| 29 "win"; |
| 30 #else // OS_LINUX, etc. TODO(viettrungluu): Separate out Chrome OS and Android? |
| 31 "linux"; |
| 32 #endif |
| 33 |
| 34 // Name of the Pepper Flash architecture in the component manifest. |
| 35 const char kPepperFlashArch[] = |
| 36 #if defined(ARCH_CPU_X86) |
| 37 "ia32"; |
| 38 #elif defined(ARCH_CPU_X86_64) |
| 39 "x64"; |
| 40 #else // TODO(viettrungluu): Support an ARM check? |
| 41 "???"; |
| 42 #endif |
| 43 |
| 44 // Returns true if the Pepper |interface_name| is implemented by this browser. |
| 45 // It does not check if the interface is proxied. |
| 46 bool SupportsPepperInterface(const char* interface_name) { |
| 47 if (IsSupportedPepperInterface(interface_name)) |
| 48 return true; |
| 49 // The PDF interface is invisible to SupportsInterface() on the browser |
| 50 // process because it is provided using PpapiInterfaceFactoryManager. We need |
| 51 // to check for that as well. |
| 52 // TODO(cpu): make this more sane. |
| 53 return (strcmp(interface_name, PPB_PDF_INTERFACE) == 0); |
| 54 } |
| 55 |
| 56 // Returns true if this browser implements one of the interfaces given in |
| 57 // |interface_string|, which is a '|'-separated string of interface names. |
| 58 bool CheckPepperFlashInterfaceString(const std::string& interface_string) { |
| 59 std::vector<std::string> interface_names; |
| 60 base::SplitString(interface_string, '|', &interface_names); |
| 61 for (size_t i = 0; i < interface_names.size(); i++) { |
| 62 if (SupportsPepperInterface(interface_names[i].c_str())) |
| 63 return true; |
| 64 } |
| 65 return false; |
| 66 } |
| 67 |
| 68 // Returns true if this browser implements all the interfaces that Flash |
| 69 // specifies in its component installer manifest. |
| 70 bool CheckPepperFlashInterfaces(const base::DictionaryValue& manifest) { |
| 71 const base::ListValue* interface_list = NULL; |
| 72 |
| 73 // We don't *require* an interface list, apparently. |
| 74 if (!manifest.GetList("x-ppapi-required-interfaces", &interface_list)) |
| 75 return true; |
| 76 |
| 77 for (size_t i = 0; i < interface_list->GetSize(); i++) { |
| 78 std::string interface_string; |
| 79 if (!interface_list->GetString(i, &interface_string)) |
| 80 return false; |
| 81 if (!CheckPepperFlashInterfaceString(interface_string)) |
| 82 return false; |
| 83 } |
| 84 |
| 85 return true; |
| 86 } |
| 87 |
| 88 } // namespace |
| 89 |
| 90 bool CheckPepperFlashManifest(const base::DictionaryValue& manifest, |
| 91 Version* version_out) { |
| 92 std::string name; |
| 93 manifest.GetStringASCII("name", &name); |
| 94 // TODO(viettrungluu): Support WinFlapper for now, while we change the format |
| 95 // of the manifest. (Should be safe to remove checks for "WinFlapper" in, say, |
| 96 // Nov. 2011.) crbug.com/98458 |
| 97 if (name != kPepperFlashManifestName && name != "WinFlapper") |
| 98 return false; |
| 99 |
| 100 std::string proposed_version; |
| 101 manifest.GetStringASCII("version", &proposed_version); |
| 102 Version version(proposed_version.c_str()); |
| 103 if (!version.IsValid()) |
| 104 return false; |
| 105 |
| 106 if (!CheckPepperFlashInterfaces(manifest)) |
| 107 return false; |
| 108 |
| 109 // TODO(viettrungluu): See above TODO. |
| 110 if (name == "WinFlapper") { |
| 111 *version_out = version; |
| 112 return true; |
| 113 } |
| 114 |
| 115 std::string os; |
| 116 manifest.GetStringASCII("x-ppapi-os", &os); |
| 117 if (os != kPepperFlashOperatingSystem) |
| 118 return false; |
| 119 |
| 120 std::string arch; |
| 121 manifest.GetStringASCII("x-ppapi-arch", &arch); |
| 122 if (arch != kPepperFlashArch) |
| 123 return false; |
| 124 |
| 125 *version_out = version; |
| 126 return true; |
| 127 } |
| 128 |
| 129 } // namespace chrome |
OLD | NEW |