1 | /* |
2 | * Copyright (C) 2011, 2014 Igalia S.L. |
3 | * Copyright (C) 2011 Apple Inc. |
4 | * Copyright (C) 2012 Samsung Electronics |
5 | * |
6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions |
8 | * are met: |
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. |
14 | * |
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. |
26 | */ |
27 | |
28 | #include "config.h" |
29 | #include "PluginProcessMainUnix.h" |
30 | |
31 | #if ENABLE(PLUGIN_PROCESS) |
32 | |
33 | #include "AuxiliaryProcessMain.h" |
34 | #include "Logging.h" |
35 | #include "NetscapePlugin.h" |
36 | #include "PluginProcess.h" |
37 | #include <stdlib.h> |
38 | #include <wtf/FileSystem.h> |
39 | |
40 | #if PLATFORM(GTK) |
41 | #include <gtk/gtk.h> |
42 | #endif |
43 | |
44 | #if PLATFORM(X11) |
45 | #include <WebCore/PlatformDisplayX11.h> |
46 | #include <WebCore/XErrorTrapper.h> |
47 | #include <wtf/NeverDestroyed.h> |
48 | #endif |
49 | |
50 | namespace WebKit { |
51 | |
52 | #if PLATFORM(X11) |
53 | static LazyNeverDestroyed<WebCore::XErrorTrapper> xErrorTrapper; |
54 | #endif |
55 | |
56 | class PluginProcessMain final: public AuxiliaryProcessMainBase { |
57 | public: |
58 | bool platformInitialize() override |
59 | { |
60 | #if PLATFORM(GTK) |
61 | gtk_init(nullptr, nullptr); |
62 | #endif |
63 | |
64 | return true; |
65 | } |
66 | |
67 | bool parseCommandLine(int argc, char** argv) override |
68 | { |
69 | ASSERT(argc > 2); |
70 | if (argc < 3) |
71 | return false; |
72 | |
73 | if (!strcmp(argv[1], "-scanPlugin" )) { |
74 | ASSERT(argc == 3); |
75 | #if PLUGIN_ARCHITECTURE(UNIX) |
76 | exit(NetscapePluginModule::scanPlugin(argv[2]) ? EXIT_SUCCESS : EXIT_FAILURE); |
77 | #else |
78 | exit(EXIT_FAILURE); |
79 | #endif |
80 | } |
81 | |
82 | ASSERT(argc == 4); |
83 | #if PLATFORM(X11) |
84 | if (WebCore::PlatformDisplay::sharedDisplay().type() == WebCore::PlatformDisplay::Type::X11) { |
85 | auto* display = downcast<WebCore::PlatformDisplayX11>(WebCore::PlatformDisplay::sharedDisplay()).native(); |
86 | xErrorTrapper.construct(display, WebCore::XErrorTrapper::Policy::Warn); |
87 | } |
88 | #endif |
89 | |
90 | m_parameters.extraInitializationData.add("plugin-path" , argv[3]); |
91 | return AuxiliaryProcessMainBase::parseCommandLine(argc, argv); |
92 | } |
93 | }; |
94 | |
95 | int PluginProcessMainUnix(int argc, char** argv) |
96 | { |
97 | return AuxiliaryProcessMain<PluginProcess, PluginProcessMain>(argc, argv); |
98 | } |
99 | |
100 | } // namespace WebKit |
101 | |
102 | #endif |
103 | |