Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: webkit/port/bridge/PluginsWin.cpp

Issue 7419: Move many files that were suffixed Win.cpp to Chromium.cpp, and place them in... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/port/bridge/PageWin.cpp ('k') | webkit/port/bridge/chromium/PluginsChromium.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2008, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 // These functions are used by the javascript access to the
31 // netscape.plugins object. See PluginInfoStore.h.
32 // They are also used by WebViewImpl to check if a plugin exists for a given
33 // MIME type.
34 //
35
36 #include "config.h"
37
38 #pragma warning(push, 0)
39 #include "PluginInfoStore.h"
40 #pragma warning(pop)
41 #undef LOG
42
43 #include "base/file_util.h"
44 #include "base/string_util.h"
45 #include "base/sys_string_conversions.h"
46 #include "webkit/glue/plugins/plugin_list.h"
47 #include "glue/glue_util.h"
48 #include "glue/webkit_glue.h"
49 #include "net/base/mime_util.h"
50
51 namespace WebCore {
52
53 // We cache the plugins ourselves, since if we're getting them from the another
54 // process GetPlugins() will be expensive.
55 static bool g_loaded_plugins = false;
56 static std::vector<WebPluginInfo> g_plugins;
57
58 void LoadPlugins(bool refresh)
59 {
60 if (g_loaded_plugins && !refresh)
61 return;
62
63 g_loaded_plugins = true;
64 webkit_glue::GetPlugins(refresh, &g_plugins);
65 }
66
67 // Returns a PluginInfo pointer. Caller is responsible for
68 // deleting contents of the PluginInfo.
69 PluginInfo* PluginInfoStore::createPluginInfoForPluginAtIndex(unsigned int index )
70 {
71 WebCore::PluginInfo* rv = new WebCore::PluginInfo();
72 const WebPluginInfo& plugin = g_plugins[index];
73 rv->name = webkit_glue::StdWStringToString(plugin.name);
74 rv->desc = webkit_glue::StdWStringToString(plugin.desc);
75 rv->file = webkit_glue::StdWStringToString(
76 file_util::GetFilenameFromPath(plugin.file));
77 for (size_t j = 0; j < plugin.mime_types.size(); ++ j) {
78 WebCore::MimeClassInfo* new_mime = new WebCore::MimeClassInfo();
79 const WebPluginMimeType& mime_type = plugin.mime_types[j];
80 new_mime->desc = webkit_glue::StdWStringToString(mime_type.description);
81
82 for (size_t k = 0; k < mime_type.file_extensions.size(); ++k) {
83 if (new_mime->suffixes.length())
84 new_mime->suffixes.append(",");
85
86 new_mime->suffixes.append(webkit_glue::StdStringToString(
87 mime_type.file_extensions[k]));
88 }
89
90 new_mime->type = webkit_glue::StdStringToString(mime_type.mime_type);
91 new_mime->plugin = rv;
92 rv->mimes.append(new_mime);
93 }
94
95 return rv;
96 }
97
98 unsigned PluginInfoStore::pluginCount() const
99 {
100 LoadPlugins(false);
101
102 return g_plugins.size();
103 }
104
105 bool PluginInfoStore::supportsMIMEType(const WebCore::String &mime_type)
106 {
107 LoadPlugins(false);
108
109 std::wstring converted_mime_type = webkit_glue::StringToStdWString(mime_type );
110
111 for (size_t i = 0; i < g_plugins.size(); ++i) {
112 for (size_t j = 0; j < g_plugins[i].mime_types.size(); ++j) {
113 if (net::MatchesMimeType(
114 g_plugins[i].mime_types[j].mime_type,
115 base::SysWideToNativeMB(converted_mime_type))) {
116 // Don't allow wildcard matches here as this will result in
117 // plugins being instantiated in cases where they should not.
118 // For e.g. clicking on a link which causes a file to be
119 // downloaded, special mime types like text/xml, etc. In any
120 // case the webkit codepaths which invoke this function don't
121 // expect wildcard plugin matches.
122 if (g_plugins[i].mime_types[j].mime_type == "*") {
123 continue;
124 }
125 return true;
126 }
127 }
128 }
129
130 return false;
131 }
132
133 void refreshPlugins(bool)
134 {
135 LoadPlugins(true);
136 }
137
138 String GetPluginMimeTypeFromExtension(const String& extension) {
139 LoadPlugins(false);
140
141 std::string mime_type;
142 std::string extension_std = WideToUTF8(
143 webkit_glue::StringToStdWString(extension));
144 for (size_t i = 0; i < g_plugins.size(); ++i) {
145 if (NPAPI::PluginList::SupportsExtension(
146 g_plugins[i], extension_std, &mime_type))
147 break;
148 }
149
150 return webkit_glue::StdStringToString(mime_type);
151 }
152
153 } // namespace WebCore
OLDNEW
« no previous file with comments | « webkit/port/bridge/PageWin.cpp ('k') | webkit/port/bridge/chromium/PluginsChromium.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698