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
3 // found in the LICENSE file.
5 #include "base/strings/string_split.h"
6 #include "base/values.h"
7 #include "base/version.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"
15 const int32 kPepperFlashPermissions
= ppapi::PERMISSION_DEV
|
16 ppapi::PERMISSION_PRIVATE
|
17 ppapi::PERMISSION_BYPASS_USER_GESTURE
|
18 ppapi::PERMISSION_FLASH
;
21 // File name of the Pepper Flash component manifest on different platforms.
22 const char kPepperFlashManifestName
[] = "Flapper";
24 // Name of the Pepper Flash OS in the component manifest.
25 const char kPepperFlashOperatingSystem
[] =
26 #if defined(OS_MACOSX)
30 #else // OS_LINUX, etc. TODO(viettrungluu): Separate out Chrome OS and Android?
34 // Name of the Pepper Flash architecture in the component manifest.
35 const char kPepperFlashArch
[] =
36 #if defined(ARCH_CPU_X86)
38 #elif defined(ARCH_CPU_X86_64)
40 #else // TODO(viettrungluu): Support an ARM check?
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
))
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);
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()))
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
;
73 // We don't *require* an interface list, apparently.
74 if (!manifest
.GetList("x-ppapi-required-interfaces", &interface_list
))
77 for (size_t i
= 0; i
< interface_list
->GetSize(); i
++) {
78 std::string interface_string
;
79 if (!interface_list
->GetString(i
, &interface_string
))
81 if (!CheckPepperFlashInterfaceString(interface_string
))
90 bool CheckPepperFlashManifest(const base::DictionaryValue
& manifest
,
91 Version
* version_out
) {
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")
100 std::string proposed_version
;
101 manifest
.GetStringASCII("version", &proposed_version
);
102 Version
version(proposed_version
.c_str());
103 if (!version
.IsValid())
106 if (!CheckPepperFlashInterfaces(manifest
))
109 // TODO(viettrungluu): See above TODO.
110 if (name
== "WinFlapper") {
111 *version_out
= version
;
116 manifest
.GetStringASCII("x-ppapi-os", &os
);
117 if (os
!= kPepperFlashOperatingSystem
)
121 manifest
.GetStringASCII("x-ppapi-arch", &arch
);
122 if (arch
!= kPepperFlashArch
)
125 *version_out
= version
;
129 } // namespace chrome