2 * Copyright (C) 2011 Igalia S.L.
3 * Copyright (C) 2011 Apple Inc.
4 * Copyright (C) 2012 Samsung Electronics
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
19 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
25 * THE POSSIBILITY OF SUCH DAMAGE.
29 #include "PluginProcessProxy.h"
31 #if ENABLE(PLUGIN_PROCESS)
33 #include "PluginProcessCreationParameters.h"
34 #include "ProcessExecutablePath.h"
35 #include <WebCore/FileSystem.h>
36 #include <wtf/text/CString.h>
37 #include <wtf/text/WTFString.h>
38 #if PLATFORM(GTK) || (PLATFORM(EFL) && ENABLE(GLIB_SUPPORT))
42 using namespace WebCore;
46 void PluginProcessProxy::platformInitializePluginProcess(PluginProcessCreationParameters&)
50 bool PluginProcessProxy::scanPlugin(const String& pluginPath, RawPluginMetaData& result)
52 #if PLATFORM(GTK) || (PLATFORM(EFL) && ENABLE(GLIB_SUPPORT))
53 CString binaryPath = fileSystemRepresentation(executablePathOfPluginProcess());
54 CString pluginPathCString = fileSystemRepresentation(pluginPath);
56 argv[0] = const_cast<char*>(binaryPath.data());
57 argv[1] = const_cast<char*>("-scanPlugin");
58 argv[2] = const_cast<char*>(pluginPathCString.data());
64 if (!g_spawn_sync(0, argv, 0, G_SPAWN_STDERR_TO_DEV_NULL, 0, 0, &stdOut, 0, &status, 0))
67 if (!WIFEXITED(status) || WEXITSTATUS(status) != EXIT_SUCCESS)
70 const unsigned kNumLinesExpected = 3;
71 String lines[kNumLinesExpected];
72 unsigned lineIndex = 0;
74 const UChar* current = reinterpret_cast<const UChar*>(stdOut);
76 while (lineIndex < kNumLinesExpected) {
77 const UChar* start = current;
78 while (*current++ != UChar('\n')) { }
79 lines[lineIndex++] = String(start, current - start - 1);
85 result.name.swap(lines[0]);
86 result.description.swap(lines[1]);
87 result.mimeDescription.swap(lines[2]);
88 return !result.mimeDescription.isEmpty();
89 #else // PLATFORM(GTK) || (PLATFORM(EFL) && ENABLE(GLIB_SUPPORT))
91 #endif // PLATFORM(GTK) || (PLATFORM(EFL) && ENABLE(GLIB_SUPPORT))
96 #endif // ENABLE(PLUGIN_PROCESS)