1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
|
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#import "config.h"
#import "PluginProcessProxy.h"
#if ENABLE(PLUGIN_PROCESS)
#import "DynamicLinkerEnvironmentExtractor.h"
#import "EnvironmentVariables.h"
#import "PluginProcessCreationParameters.h"
#import "PluginProcessMessages.h"
#import "WebKitSystemInterface.h"
#import <WebCore/FileSystem.h>
#import <WebCore/KURL.h>
#import <WebCore/RuntimeApplicationChecks.h>
#import <crt_externs.h>
#import <mach-o/dyld.h>
#import <spawn.h>
#import <wtf/text/CString.h>
#import <QuartzCore/CARemoteLayerServer.h>
@interface WKPlaceholderModalWindow : NSWindow
@end
@implementation WKPlaceholderModalWindow
// Prevent NSApp from calling requestUserAttention: when the window is shown
// modally, even if the app is inactive. See 6823049.
- (BOOL)_wantsUserAttention
{
return NO;
}
@end
using namespace WebCore;
namespace WebKit {
bool PluginProcessProxy::pluginNeedsExecutableHeap(const PluginModuleInfo& pluginInfo)
{
static bool forceNonexecutableHeapForPlugins = [[NSUserDefaults standardUserDefaults] boolForKey:@"ForceNonexecutableHeapForPlugins"];
if (forceNonexecutableHeapForPlugins)
return false;
if (pluginInfo.bundleIdentifier == "com.apple.QuickTime Plugin.plugin")
return false;
return true;
}
bool PluginProcessProxy::createPropertyListFile(const PluginModuleInfo& plugin)
{
NSBundle *webKit2Bundle = [NSBundle bundleWithIdentifier:@"com.apple.WebKit2"];
NSString *frameworksPath = [[webKit2Bundle bundlePath] stringByDeletingLastPathComponent];
const char* frameworkExecutablePath = [[webKit2Bundle executablePath] fileSystemRepresentation];
NSString *processPath = [webKit2Bundle pathForAuxiliaryExecutable:@"PluginProcess.app"];
NSString *processAppExecutablePath = [[NSBundle bundleWithPath:processPath] executablePath];
CString pluginPathString = fileSystemRepresentation(plugin.path);
posix_spawnattr_t attr;
posix_spawnattr_init(&attr);
cpu_type_t cpuTypes[] = { plugin.pluginArchitecture };
size_t outCount = 0;
posix_spawnattr_setbinpref_np(&attr, 1, cpuTypes, &outCount);
EnvironmentVariables environmentVariables;
DynamicLinkerEnvironmentExtractor environmentExtractor([[NSBundle mainBundle] executablePath], _NSGetMachExecuteHeader()->cputype);
environmentExtractor.getExtractedEnvironmentVariables(environmentVariables);
// To make engineering builds work, if the path is outside of /System set up
// DYLD_FRAMEWORK_PATH to pick up other frameworks, but don't do it for the
// production configuration because it involves extra file system access.
if (![frameworksPath hasPrefix:@"/System/"])
environmentVariables.appendValue("DYLD_FRAMEWORK_PATH", [frameworksPath fileSystemRepresentation], ':');
const char* args[] = { [processAppExecutablePath fileSystemRepresentation], frameworkExecutablePath, "-type", "pluginprocess", "-createPluginMIMETypesPreferences", pluginPathString.data(), 0 };
pid_t pid;
int result = posix_spawn(&pid, args[0], 0, &attr, const_cast<char* const*>(args), environmentVariables.environmentPointer());
posix_spawnattr_destroy(&attr);
if (result)
return false;
int status;
if (waitpid(pid, &status, 0) < 0)
return false;
if (!WIFEXITED(status))
return false;
if (WEXITSTATUS(status) != EXIT_SUCCESS)
return false;
return true;
}
#if HAVE(XPC)
static bool shouldUseXPC()
{
if (id value = [[NSUserDefaults standardUserDefaults] objectForKey:@"WebKit2UseXPCServiceForWebProcess"])
return [value boolValue];
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
// FIXME: Temporary workaround for <rdar://problem/13236883>
if (applicationIsSafari())
return false;
return true;
#else
return false;
#endif
}
#endif
void PluginProcessProxy::platformGetLaunchOptions(ProcessLauncher::LaunchOptions& launchOptions, const PluginProcessAttributes& pluginProcessAttributes)
{
launchOptions.architecture = pluginProcessAttributes.moduleInfo.pluginArchitecture;
launchOptions.executableHeap = PluginProcessProxy::pluginNeedsExecutableHeap(pluginProcessAttributes.moduleInfo);
launchOptions.extraInitializationData.add("plugin-path", pluginProcessAttributes.moduleInfo.path);
// FIXME: Don't allow this if the UI process is sandboxed.
if (pluginProcessAttributes.sandboxPolicy == PluginProcessSandboxPolicyUnsandboxed)
launchOptions.extraInitializationData.add("disable-sandbox", "1");
#if HAVE(XPC)
launchOptions.useXPC = shouldUseXPC();
#endif
}
void PluginProcessProxy::platformInitializePluginProcess(PluginProcessCreationParameters& parameters)
{
// For now only Flash is known to behave with asynchronous plug-in initialization.
parameters.supportsAsynchronousPluginInitialization = m_pluginProcessAttributes.moduleInfo.bundleIdentifier == "com.macromedia.Flash Player.plugin";
#if USE(ACCELERATED_COMPOSITING) && HAVE(HOSTED_CORE_ANIMATION)
mach_port_t renderServerPort = [[CARemoteLayerServer sharedServer] serverPort];
if (renderServerPort != MACH_PORT_NULL)
parameters.acceleratedCompositingPort = CoreIPC::MachPort(renderServerPort, MACH_MSG_TYPE_COPY_SEND);
#endif
}
bool PluginProcessProxy::getPluginProcessSerialNumber(ProcessSerialNumber& pluginProcessSerialNumber)
{
pid_t pluginProcessPID = processIdentifier();
#if COMPILER(CLANG)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
return GetProcessForPID(pluginProcessPID, &pluginProcessSerialNumber) == noErr;
#if COMPILER(CLANG)
#pragma clang diagnostic pop
#endif
}
void PluginProcessProxy::makePluginProcessTheFrontProcess()
{
ProcessSerialNumber pluginProcessSerialNumber;
if (!getPluginProcessSerialNumber(pluginProcessSerialNumber))
return;
#if COMPILER(CLANG)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
SetFrontProcess(&pluginProcessSerialNumber);
#if COMPILER(CLANG)
#pragma clang diagnostic pop
#endif
}
void PluginProcessProxy::makeUIProcessTheFrontProcess()
{
ProcessSerialNumber processSerialNumber;
#if COMPILER(CLANG)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
GetCurrentProcess(&processSerialNumber);
SetFrontProcess(&processSerialNumber);
#if COMPILER(CLANG)
#pragma clang diagnostic pop
#endif
}
void PluginProcessProxy::setFullscreenWindowIsShowing(bool fullscreenWindowIsShowing)
{
if (m_fullscreenWindowIsShowing == fullscreenWindowIsShowing)
return;
m_fullscreenWindowIsShowing = fullscreenWindowIsShowing;
if (m_fullscreenWindowIsShowing)
enterFullscreen();
else
exitFullscreen();
}
void PluginProcessProxy::enterFullscreen()
{
// Get the current presentation options.
m_preFullscreenAppPresentationOptions = [NSApp presentationOptions];
// Figure out which presentation options to use.
unsigned presentationOptions = m_preFullscreenAppPresentationOptions & ~(NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar);
presentationOptions |= NSApplicationPresentationHideDock | NSApplicationPresentationHideMenuBar;
[NSApp setPresentationOptions:presentationOptions];
makePluginProcessTheFrontProcess();
}
void PluginProcessProxy::exitFullscreen()
{
// If the plug-in host is the current application then we should bring ourselves to the front when it exits full-screen mode.
ProcessSerialNumber frontProcessSerialNumber;
#if COMPILER(CLANG)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
GetFrontProcess(&frontProcessSerialNumber);
#if COMPILER(CLANG)
#pragma clang diagnostic pop
#endif
// The UI process must be the front process in order to change the presentation mode.
makeUIProcessTheFrontProcess();
[NSApp setPresentationOptions:m_preFullscreenAppPresentationOptions];
ProcessSerialNumber pluginProcessSerialNumber;
if (!getPluginProcessSerialNumber(pluginProcessSerialNumber))
return;
// If the plug-in process was not the front process, switch back to the previous front process.
// (Otherwise we'll keep the UI process as the front process).
Boolean isPluginProcessFrontProcess;
#if COMPILER(CLANG)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
SameProcess(&frontProcessSerialNumber, &pluginProcessSerialNumber, &isPluginProcessFrontProcess);
#if COMPILER(CLANG)
#pragma clang diagnostic pop
#endif
if (!isPluginProcessFrontProcess) {
#if COMPILER(CLANG)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
SetFrontProcess(&frontProcessSerialNumber);
#if COMPILER(CLANG)
#pragma clang diagnostic pop
#endif
}
}
void PluginProcessProxy::setModalWindowIsShowing(bool modalWindowIsShowing)
{
if (modalWindowIsShowing == m_modalWindowIsShowing)
return;
m_modalWindowIsShowing = modalWindowIsShowing;
if (m_modalWindowIsShowing)
beginModal();
else
endModal();
}
void PluginProcessProxy::beginModal()
{
ASSERT(!m_placeholderWindow);
ASSERT(!m_activationObserver);
m_placeholderWindow = adoptNS([[WKPlaceholderModalWindow alloc] initWithContentRect:NSMakeRect(0, 0, 1, 1) styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES]);
[m_placeholderWindow.get() setReleasedWhenClosed:NO];
m_activationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:NSApplicationWillBecomeActiveNotification object:NSApp queue:nil
usingBlock:^(NSNotification *){ applicationDidBecomeActive(); }];
// The call to -[NSApp runModalForWindow:] below will run a nested run loop, and if the plug-in process
// crashes the PluginProcessProxy object can be destroyed. Protect against this here.
RefPtr<PluginProcessProxy> protect(this);
[NSApp runModalForWindow:m_placeholderWindow.get()];
[m_placeholderWindow.get() orderOut:nil];
m_placeholderWindow = nullptr;
}
void PluginProcessProxy::endModal()
{
ASSERT(m_placeholderWindow);
ASSERT(m_activationObserver);
[[NSNotificationCenter defaultCenter] removeObserver:m_activationObserver.get()];
m_activationObserver = nullptr;
[NSApp stopModal];
makeUIProcessTheFrontProcess();
}
void PluginProcessProxy::applicationDidBecomeActive()
{
makePluginProcessTheFrontProcess();
}
void PluginProcessProxy::setProcessSuppressionEnabled(bool processSuppressionEnabled)
{
if (!isValid())
return;
m_connection->send(Messages::PluginProcess::SetProcessSuppressionEnabled(processSuppressionEnabled), 0);
}
void PluginProcessProxy::openPluginPreferencePane()
{
if (!m_pluginProcessAttributes.moduleInfo.preferencePanePath)
return;
NSURL *preferenceURL = [NSURL fileURLWithPath:m_pluginProcessAttributes.moduleInfo.preferencePanePath];
if (!preferenceURL) {
LOG_ERROR("Creating URL for preference pane path \"%@\" failed.", (NSString *)m_pluginProcessAttributes.moduleInfo.preferencePanePath);
return;
}
NSArray *preferenceURLs = [NSArray arrayWithObject:preferenceURL];
LSLaunchURLSpec prefSpec;
prefSpec.appURL = 0;
prefSpec.itemURLs = reinterpret_cast<CFArrayRef>(preferenceURLs);
prefSpec.passThruParams = 0;
prefSpec.launchFlags = kLSLaunchAsync | kLSLaunchDontAddToRecents;
prefSpec.asyncRefCon = 0;
OSStatus error = LSOpenFromURLSpec(&prefSpec, 0);
if (error != noErr)
LOG_ERROR("LSOpenFromURLSpec to open \"%@\" failed with error %d.", (NSString *)m_pluginProcessAttributes.moduleInfo.preferencePanePath, error);
}
static bool isFlashUpdater(const String& launchPath, const Vector<String>& arguments)
{
if (launchPath != "/Applications/Utilities/Adobe Flash Player Install Manager.app/Contents/MacOS/Adobe Flash Player Install Manager")
return false;
if (arguments.size() != 1)
return false;
if (arguments[0] != "-update")
return false;
return true;
}
static bool shouldLaunchProcess(const PluginProcessAttributes& pluginProcessAttributes, const String& launchPath, const Vector<String>& arguments)
{
if (pluginProcessAttributes.moduleInfo.bundleIdentifier == "com.macromedia.Flash Player.plugin")
return isFlashUpdater(launchPath, arguments);
return false;
}
void PluginProcessProxy::launchProcess(const String& launchPath, const Vector<String>& arguments, bool& result)
{
if (!shouldLaunchProcess(m_pluginProcessAttributes, launchPath, arguments)) {
result = false;
return;
}
result = true;
RetainPtr<NSMutableArray> argumentsArray = adoptNS([[NSMutableArray alloc] initWithCapacity:arguments.size()]);
for (size_t i = 0; i < arguments.size(); ++i)
[argumentsArray addObject:(NSString *)arguments[i]];
[NSTask launchedTaskWithLaunchPath:launchPath arguments:argumentsArray.get()];
}
static bool isJavaUpdaterURL(const PluginProcessAttributes& pluginProcessAttributes, const String& urlString)
{
NSURL *url = [NSURL URLWithString:urlString];
if (![url isFileURL])
return false;
NSString *javaUpdaterPath = [NSString pathWithComponents:[NSArray arrayWithObjects:(NSString *)pluginProcessAttributes.moduleInfo.path, @"Contents/Resources/Java Updater.app", nil]];
return [url.path isEqualToString:javaUpdaterPath];
}
static bool shouldLaunchApplicationAtURL(const PluginProcessAttributes& pluginProcessAttributes, const String& urlString)
{
if (pluginProcessAttributes.moduleInfo.bundleIdentifier == "com.oracle.java.JavaAppletPlugin")
return isJavaUpdaterURL(pluginProcessAttributes, urlString);
return false;
}
void PluginProcessProxy::launchApplicationAtURL(const String& urlString, const Vector<String>& arguments, bool& result)
{
if (!shouldLaunchApplicationAtURL(m_pluginProcessAttributes, urlString)) {
result = false;
return;
}
result = true;
RetainPtr<NSMutableArray> argumentsArray = adoptNS([[NSMutableArray alloc] initWithCapacity:arguments.size()]);
for (size_t i = 0; i < arguments.size(); ++i)
[argumentsArray addObject:(NSString *)arguments[i]];
NSDictionary *configuration = [NSDictionary dictionaryWithObject:argumentsArray.get() forKey:NSWorkspaceLaunchConfigurationArguments];
[[NSWorkspace sharedWorkspace] launchApplicationAtURL:[NSURL URLWithString:urlString] options:NSWorkspaceLaunchAsync configuration:configuration error:nullptr];
}
static bool isSilverlightPreferencesURL(const PluginProcessAttributes& pluginProcessAttributes, const String& urlString)
{
NSURL *silverlightPreferencesURL = [NSURL fileURLWithPathComponents:[NSArray arrayWithObjects:(NSString *)pluginProcessAttributes.moduleInfo.path, @"Contents/Resources/Silverlight Preferences.app", nil]];
return [[NSURL URLWithString:urlString] isEqual:silverlightPreferencesURL];
}
static bool shouldOpenURL(const PluginProcessAttributes& pluginProcessAttributes, const String& urlString)
{
if (pluginProcessAttributes.moduleInfo.bundleIdentifier == "com.microsoft.SilverlightPlugin")
return isSilverlightPreferencesURL(pluginProcessAttributes, urlString);
return false;
}
void PluginProcessProxy::openURL(const String& urlString, bool& result, int32_t& status, String& launchedURLString)
{
if (!shouldOpenURL(m_pluginProcessAttributes, urlString)) {
result = false;
return;
}
result = true;
CFURLRef launchedURL;
status = LSOpenCFURLRef(KURL(ParsedURLString, urlString).createCFURL().get(), &launchedURL);
if (launchedURL) {
launchedURLString = KURL(launchedURL).string();
CFRelease(launchedURL);
}
result = false;
}
} // namespace WebKit
#endif // ENABLE(PLUGIN_PROCESS)
|