Web Automation: elements larger than the viewport have incorrect in-view center point
[WebKit-https.git] / Source / WebCore / platform / RuntimeApplicationChecks.cpp
index 48b4f65..4711010 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Apple Inc. All rights reserved.
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #include "RuntimeApplicationChecks.h"
 
 #include <wtf/NeverDestroyed.h>
+#include <wtf/Optional.h>
+#include <wtf/ProcessID.h>
 #include <wtf/RunLoop.h>
-#include <wtf/text/WTFString.h>
-
-#if USE(CF)
-#include <CoreFoundation/CoreFoundation.h>
-#include <wtf/RetainPtr.h>
-#endif
 
 namespace WebCore {
 
-#if USE(CF)
-static CFStringRef mainBundleIdentifier()
-{
-    CFBundleRef mainBundle = CFBundleGetMainBundle();
-    if (!mainBundle)
-        return nullptr;
-
-    return CFBundleGetIdentifier(mainBundle);
-}
-#endif
-
-// The application bundle identifier gets set to the UIProcess bundle identifier by the WebProcess and
-// the networking process upon initialization.
-// If not explicitly set, this will return the main bundle identifier which is accurate for WK1 or
-// the WK2 UIProcess.
-static String& applicationBundleIdentifier()
-{
-    ASSERT(RunLoop::isMain());
-
-#if USE(CF)
-    static NeverDestroyed<String> identifier(mainBundleIdentifier());
-#else
-    static NeverDestroyed<String> identifier;
+#if !ASSERT_MSG_DISABLED
+static bool presentingApplicationPIDOverrideWasQueried;
 #endif
 
-    return identifier;
-}
-
-// FIXME: This should probably be renamed to applicationBundleIsEqualTo() and use applicationBundleIdentifier()
-// instead of mainBundleIdentifier() internally. This would have the benefit of working for both WebKit1 and
-// WebKit2.
-static bool mainBundleIsEqualTo(const String& bundleIdentifierString)
+static Optional<int>& presentingApplicationPIDOverride()
 {
-    // FIXME: We should consider merging this file with RuntimeApplicationChecksIOS.mm.
-    // Then we can remove the PLATFORM(IOS)-guard.
-#if USE(CF) && !PLATFORM(IOS)
-    CFStringRef bundleIdentifier = mainBundleIdentifier();
-    if (!bundleIdentifier)
-        return false;
-
-    return CFStringCompare(bundleIdentifier, bundleIdentifierString.createCFString().get(), 0) == kCFCompareEqualTo;
-#else
-    UNUSED_PARAM(bundleIdentifierString);
-    return false;
+    static NeverDestroyed<Optional<int>> pid;
+#if !ASSERT_MSG_DISABLED
+    presentingApplicationPIDOverrideWasQueried = true;
 #endif
+    return pid;
 }
 
-bool applicationIsSafari()
-{
-    static bool isSafari = mainBundleIsEqualTo("com.apple.Safari");
-    return isSafari;
-}
-
-bool applicationIsAppleMail()
-{
-    static bool isAppleMail = mainBundleIsEqualTo("com.apple.mail");
-    return isAppleMail;
-}
-
-bool applicationIsIBooks()
-{
-    static bool isIBooks = mainBundleIsEqualTo("com.apple.iBooksX");
-    return isIBooks;
-}
-
-bool applicationIsITunes()
-{
-    static bool isITunes = mainBundleIsEqualTo("com.apple.iTunes");
-    return isITunes;
-}
-
-bool applicationIsMicrosoftMessenger()
-{
-    static bool isMicrosoftMessenger = mainBundleIsEqualTo("com.microsoft.Messenger");
-    return isMicrosoftMessenger;
-}
-
-bool applicationIsAdobeInstaller()
+int presentingApplicationPID()
 {
-    static bool isAdobeInstaller = mainBundleIsEqualTo("com.adobe.Installers.Setup");
-    return isAdobeInstaller;
+    const auto& pid = presentingApplicationPIDOverride();
+    ASSERT(!pid || RunLoop::isMain());
+    return pid ? pid.value() : getCurrentProcessID();
 }
 
-bool applicationIsAOLInstantMessenger()
+void setPresentingApplicationPID(int pid)
 {
-    static bool isAOLInstantMessenger = mainBundleIsEqualTo("com.aol.aim.desktop");
-    return isAOLInstantMessenger;
-}
-
-bool applicationIsMicrosoftMyDay()
-{
-    static bool isMicrosoftMyDay = mainBundleIsEqualTo("com.microsoft.myday");
-    return isMicrosoftMyDay;
-}
-
-bool applicationIsMicrosoftOutlook()
-{
-    static bool isMicrosoftOutlook = mainBundleIsEqualTo("com.microsoft.Outlook");
-    return isMicrosoftOutlook;
-}
-
-bool applicationIsQuickenEssentials()
-{
-    static bool isQuickenEssentials = mainBundleIsEqualTo("com.intuit.QuickenEssentials");
-    return isQuickenEssentials;
-}
-
-bool applicationIsAperture()
-{
-    static bool isAperture = mainBundleIsEqualTo("com.apple.Aperture");
-    return isAperture;
-}
-
-bool applicationIsVersions()
-{
-    static bool isVersions = mainBundleIsEqualTo("com.blackpixel.versions");
-    return isVersions;
-}
-
-bool applicationIsHRBlock()
-{
-    static bool isHRBlock = mainBundleIsEqualTo("com.hrblock.tax.2010");
-    return isHRBlock;
-}
-
-bool applicationIsSolidStateNetworksDownloader()
-{
-    static bool isSolidStateNetworksDownloader = mainBundleIsEqualTo("com.solidstatenetworks.awkhost");
-    return isSolidStateNetworksDownloader;
-}
-
-bool applicationIsHipChat()
-{
-    static bool isHipChat = applicationBundleIdentifier() == "com.hipchat.HipChat";
-    ASSERT_WITH_MESSAGE(isHipChat == (applicationBundleIdentifier() == "com.hipchat.HipChat"), "Should not be called before setApplicationBundleIdentifier()");
-    return isHipChat;
-}
-
-void setApplicationBundleIdentifier(const String& bundleIdentifier)
-{
-    applicationBundleIdentifier() = bundleIdentifier;
+    ASSERT(RunLoop::isMain());
+    ASSERT_WITH_MESSAGE(!presentingApplicationPIDOverrideWasQueried, "presentingApplicationPID() should not be called before setPresentingApplicationPID()");
+    presentingApplicationPIDOverride() = pid;
 }
 
 } // namespace WebCore