Web Automation: elements larger than the viewport have incorrect in-view center point
[WebKit-https.git] / Source / WebCore / platform / RuntimeApplicationChecks.cpp
index 730edc1..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 "config.h"
 #include "RuntimeApplicationChecks.h"
 
-#if USE(CF)
-#include <CoreFoundation/CoreFoundation.h>
-#include <wtf/RetainPtr.h>
-#endif
-
-#include <wtf/text/WTFString.h>
+#include <wtf/NeverDestroyed.h>
+#include <wtf/Optional.h>
+#include <wtf/ProcessID.h>
+#include <wtf/RunLoop.h>
 
 namespace WebCore {
-    
-static bool mainBundleIsEqualTo(const String& bundleIdentifierString)
-{
-#if USE(CF)
-    CFBundleRef mainBundle = CFBundleGetMainBundle();
-    if (!mainBundle)
-        return false;
 
-    CFStringRef bundleIdentifier = CFBundleGetIdentifier(mainBundle);
-    if (!bundleIdentifier)
-        return false;
-
-    return CFStringCompare(bundleIdentifier, bundleIdentifierString.createCFString().get(), 0) == kCFCompareEqualTo;
-#else
-    UNUSED_PARAM(bundleIdentifierString);
-    return false;
+#if !ASSERT_MSG_DISABLED
+static bool presentingApplicationPIDOverrideWasQueried;
 #endif
-}
-
-bool applicationIsSafari()
-{
-    // FIXME: For the WebProcess case, ensure that this is Safari's WebProcess.
-    static bool isSafari = mainBundleIsEqualTo("com.apple.Safari") || mainBundleIsEqualTo("com.apple.WebProcess");
-    return isSafari;
-}
-
-bool applicationIsAppleMail()
-{
-    static bool isAppleMail = mainBundleIsEqualTo("com.apple.mail");
-    return isAppleMail;
-}
 
-bool applicationIsMicrosoftMessenger()
+static Optional<int>& presentingApplicationPIDOverride()
 {
-    static bool isMicrosoftMessenger = mainBundleIsEqualTo("com.microsoft.Messenger");
-    return isMicrosoftMessenger;
-}
-
-bool applicationIsAdobeInstaller()
-{
-    static bool isAdobeInstaller = mainBundleIsEqualTo("com.adobe.Installers.Setup");
-    return isAdobeInstaller;
-}
-
-bool applicationIsAOLInstantMessenger()
-{
-    static bool isAOLInstantMessenger = mainBundleIsEqualTo("com.aol.aim.desktop");
-    return isAOLInstantMessenger;
-}
-
-bool applicationIsMicrosoftMyDay()
-{
-    static bool isMicrosoftMyDay = mainBundleIsEqualTo("com.microsoft.myday");
-    return isMicrosoftMyDay;
+    static NeverDestroyed<Optional<int>> pid;
+#if !ASSERT_MSG_DISABLED
+    presentingApplicationPIDOverrideWasQueried = true;
+#endif
+    return pid;
 }
 
-bool applicationIsMicrosoftOutlook()
+int presentingApplicationPID()
 {
-    static bool isMicrosoftOutlook = mainBundleIsEqualTo("com.microsoft.Outlook");
-    return isMicrosoftOutlook;
+    const auto& pid = presentingApplicationPIDOverride();
+    ASSERT(!pid || RunLoop::isMain());
+    return pid ? pid.value() : getCurrentProcessID();
 }
 
-bool applicationIsAperture()
+void setPresentingApplicationPID(int pid)
 {
-    static bool isAperture = mainBundleIsEqualTo("com.apple.Aperture");
-    return isAperture;
+    ASSERT(RunLoop::isMain());
+    ASSERT_WITH_MESSAGE(!presentingApplicationPIDOverrideWasQueried, "presentingApplicationPID() should not be called before setPresentingApplicationPID()");
+    presentingApplicationPIDOverride() = pid;
 }
 
 } // namespace WebCore