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::platformInitializeLaunchOptions(ProcessLauncher::LaunchOptions&, const PluginModuleInfo&)
50 void PluginProcessProxy::platformInitializePluginProcess(PluginProcessCreationParameters&)
54 bool PluginProcessProxy::scanPlugin(const String& pluginPath, RawPluginMetaData& result)
56 #if PLATFORM(GTK) || (PLATFORM(EFL) && ENABLE(GLIB_SUPPORT))
57 CString binaryPath = fileSystemRepresentation(executablePathOfPluginProcess());
58 CString pluginPathCString = fileSystemRepresentation(pluginPath);
60 argv[0] = const_cast<char*>(binaryPath.data());
61 argv[1] = const_cast<char*>("-scanPlugin");
62 argv[2] = const_cast<char*>(pluginPathCString.data());
68 if (!g_spawn_sync(0, argv, 0, G_SPAWN_STDERR_TO_DEV_NULL, 0, 0, &stdOut, 0, &status, 0))
71 if (!WIFEXITED(status) || WEXITSTATUS(status) != EXIT_SUCCESS) {
76 const unsigned kNumLinesExpected = 3;
77 String lines[kNumLinesExpected];
78 unsigned lineIndex = 0;
80 const UChar* current = reinterpret_cast<const UChar*>(stdOut);
82 while (lineIndex < kNumLinesExpected) {
83 const UChar* start = current;
84 while (*current++ != UChar('\n')) { }
85 lines[lineIndex++] = String(start, current - start - 1);
91 result.name.swap(lines[0]);
92 result.description.swap(lines[1]);
93 result.mimeDescription.swap(lines[2]);
94 return !result.mimeDescription.isEmpty();
95 #else // PLATFORM(GTK) || (PLATFORM(EFL) && ENABLE(GLIB_SUPPORT))
97 #endif // PLATFORM(GTK) || (PLATFORM(EFL) && ENABLE(GLIB_SUPPORT))
100 } // namespace WebKit
102 #endif // ENABLE(PLUGIN_PROCESS)