RuntimeApplicationChecks.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright (C) 2011 Apple Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
  14. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  15. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
  17. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  18. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  19. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  21. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  23. * THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include "config.h"
  26. #include "RuntimeApplicationChecks.h"
  27. #if USE(CF)
  28. #include <CoreFoundation/CoreFoundation.h>
  29. #include <wtf/RetainPtr.h>
  30. #endif
  31. #include <wtf/text/WTFString.h>
  32. namespace WebCore {
  33. static bool mainBundleIsEqualTo(const String& bundleIdentifierString)
  34. {
  35. #if USE(CF)
  36. CFBundleRef mainBundle = CFBundleGetMainBundle();
  37. if (!mainBundle)
  38. return false;
  39. CFStringRef bundleIdentifier = CFBundleGetIdentifier(mainBundle);
  40. if (!bundleIdentifier)
  41. return false;
  42. return CFStringCompare(bundleIdentifier, bundleIdentifierString.createCFString().get(), 0) == kCFCompareEqualTo;
  43. #else
  44. UNUSED_PARAM(bundleIdentifierString);
  45. return false;
  46. #endif
  47. }
  48. bool applicationIsSafari()
  49. {
  50. // FIXME: For the WebProcess case, ensure that this is Safari's WebProcess.
  51. static bool isSafari = mainBundleIsEqualTo("com.apple.Safari") || mainBundleIsEqualTo("com.apple.WebProcess");
  52. return isSafari;
  53. }
  54. bool applicationIsAppleMail()
  55. {
  56. static bool isAppleMail = mainBundleIsEqualTo("com.apple.mail");
  57. return isAppleMail;
  58. }
  59. bool applicationIsITunes()
  60. {
  61. static bool isITunes = mainBundleIsEqualTo("com.apple.iTunes");
  62. return isITunes;
  63. }
  64. bool applicationIsMicrosoftMessenger()
  65. {
  66. static bool isMicrosoftMessenger = mainBundleIsEqualTo("com.microsoft.Messenger");
  67. return isMicrosoftMessenger;
  68. }
  69. bool applicationIsAdobeInstaller()
  70. {
  71. static bool isAdobeInstaller = mainBundleIsEqualTo("com.adobe.Installers.Setup");
  72. return isAdobeInstaller;
  73. }
  74. bool applicationIsAOLInstantMessenger()
  75. {
  76. static bool isAOLInstantMessenger = mainBundleIsEqualTo("com.aol.aim.desktop");
  77. return isAOLInstantMessenger;
  78. }
  79. bool applicationIsMicrosoftMyDay()
  80. {
  81. static bool isMicrosoftMyDay = mainBundleIsEqualTo("com.microsoft.myday");
  82. return isMicrosoftMyDay;
  83. }
  84. bool applicationIsMicrosoftOutlook()
  85. {
  86. static bool isMicrosoftOutlook = mainBundleIsEqualTo("com.microsoft.Outlook");
  87. return isMicrosoftOutlook;
  88. }
  89. bool applicationIsAperture()
  90. {
  91. static bool isAperture = mainBundleIsEqualTo("com.apple.Aperture");
  92. return isAperture;
  93. }
  94. bool applicationIsVersions()
  95. {
  96. static bool isVersions = mainBundleIsEqualTo("com.blackpixel.versions");
  97. return isVersions;
  98. }
  99. bool applicationIsHRBlock()
  100. {
  101. static bool isHRBlock = mainBundleIsEqualTo("com.hrblock.tax.2010");
  102. return isHRBlock;
  103. }
  104. bool applicationIsSolidStateNetworksDownloader()
  105. {
  106. static bool isSolidStateNetworksDownloader = mainBundleIsEqualTo("com.solidstatenetworks.awkhost");
  107. return isSolidStateNetworksDownloader;
  108. }
  109. } // namespace WebCore