Extensions: Store disable reasons in Sync
[chromium-blink-merge.git] / chrome / common / pepper_flash.cc
blobda1c00de65519dee1f77c0f9d5d7011c836b91ac
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"
13 namespace chrome {
15 const int32 kPepperFlashPermissions = ppapi::PERMISSION_DEV |
16 ppapi::PERMISSION_PRIVATE |
17 ppapi::PERMISSION_BYPASS_USER_GESTURE |
18 ppapi::PERMISSION_FLASH;
19 namespace {
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)
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
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
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);
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;
65 return false;
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))
75 return true;
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;
85 return true;
88 } // namespace
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;
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;
106 if (!CheckPepperFlashInterfaces(manifest))
107 return false;
109 // TODO(viettrungluu): See above TODO.
110 if (name == "WinFlapper") {
111 *version_out = version;
112 return true;
115 std::string os;
116 manifest.GetStringASCII("x-ppapi-os", &os);
117 if (os != kPepperFlashOperatingSystem)
118 return false;
120 std::string arch;
121 manifest.GetStringASCII("x-ppapi-arch", &arch);
122 if (arch != kPepperFlashArch)
123 return false;
125 *version_out = version;
126 return true;
129 } // namespace chrome