BlackBerryGlobal.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * Copyright (C) 2009, 2010, 2011, 2012 Research In Motion Limited. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "config.h"
  19. #include "BlackBerryGlobal.h"
  20. #include "ApplicationCacheStorage.h"
  21. #include "CacheClientBlackBerry.h"
  22. #include "CookieManager.h"
  23. #include "CrossOriginPreflightResultCache.h"
  24. #include "FontCache.h"
  25. #include "ImageSource.h"
  26. #include "InitializeLogging.h"
  27. #include "InitializeThreading.h"
  28. #include "JSDOMWindow.h"
  29. #include "VM.h"
  30. #include "MemoryCache.h"
  31. #include "NetworkStateNotifier.h"
  32. #include "PageCache.h"
  33. #include "PageGroup.h"
  34. #include "PlatformStrategiesBlackBerry.h"
  35. #include "Settings.h"
  36. #include "TextureCacheCompositingThread.h"
  37. #include "bindings/js/GCController.h"
  38. #include "runtime/JSLock.h"
  39. #include <BlackBerryPlatformExecutableMessage.h>
  40. #include <BlackBerryPlatformMessageClient.h>
  41. #include <BlackBerryPlatformSettings.h>
  42. #include <BlackBerryPlatformString.h>
  43. #include <wtf/MainThread.h>
  44. using namespace WebCore;
  45. namespace BlackBerry {
  46. namespace WebKit {
  47. static bool gIsGlobalInitialized = false;
  48. // Global initialization of various WebKit singletons.
  49. void globalInitialize()
  50. {
  51. if (gIsGlobalInitialized)
  52. return;
  53. gIsGlobalInitialized = true;
  54. WebCore::Settings::setHiddenPageDOMTimerAlignmentInterval(BlackBerry::Platform::Settings::instance()->isChromeProcess() ? 0 : 1);
  55. #if ENABLE(BLACKBERRY_DEBUG_MEMORY)
  56. blackberryDebugInitialize();
  57. #endif
  58. #if !LOG_DISABLED
  59. // Turn on logging.
  60. initializeLoggingChannelsIfNecessary();
  61. #endif // !LOG_DISABLED
  62. // Initialize threading.
  63. JSC::initializeThreading();
  64. // Normally this is called from initializeThreading, but we're using ThreadingNone
  65. // we're grabbing callOnMainThread without using the rest of the threading support.
  66. WTF::initializeMainThread();
  67. // Initialize our platform strategies.
  68. PlatformStrategiesBlackBerry::initialize();
  69. // Set the minimal timer interval to 4 milliseconds.
  70. WebCore::Settings::setDefaultMinDOMTimerInterval(0.004);
  71. // Track visited links.
  72. PageGroup::setShouldTrackVisitedLinks(true);
  73. CacheClientBlackBerry::get()->initialize();
  74. BlackBerry::Platform::Settings* settings = BlackBerry::Platform::Settings::instance();
  75. ImageSource::setMaxPixelsPerDecodedImage(settings->maxPixelsPerDecodedImage());
  76. updateOnlineStatus(settings->isNetworkAvailable());
  77. }
  78. void collectJavascriptGarbageNow()
  79. {
  80. if (gIsGlobalInitialized)
  81. gcController().garbageCollectNow();
  82. }
  83. void clearCookieCache()
  84. {
  85. cookieManager().removeAllCookies(RemoveFromBackingStore);
  86. }
  87. #if USE(ACCELERATED_COMPOSITING)
  88. static void clearMemoryCachesInCompositingThread()
  89. {
  90. textureCacheCompositingThread()->prune(0);
  91. }
  92. #endif
  93. void clearMemoryCaches()
  94. {
  95. #if USE(ACCELERATED_COMPOSITING)
  96. // Call textureCacheCompositingThread()->prune(0) in UI thread.
  97. BlackBerry::Platform::userInterfaceThreadMessageClient()->dispatchMessage(BlackBerry::Platform::createFunctionCallMessage(clearMemoryCachesInCompositingThread));
  98. #endif
  99. {
  100. JSC::JSLockHolder lock(JSDOMWindow::commonVM());
  101. collectJavascriptGarbageNow();
  102. }
  103. // Clean caches after JS garbage collection because JS GC can
  104. // generate more dead resources.
  105. int capacity = pageCache()->capacity();
  106. pageCache()->setCapacity(0);
  107. pageCache()->setCapacity(capacity);
  108. CrossOriginPreflightResultCache::shared().empty();
  109. if (!memoryCache()->disabled()) {
  110. // Evict all dead resources and prune live resources.
  111. memoryCache()->setCapacities(0, 0, 0);
  112. // Update cache capacity based on current memory status.
  113. CacheClientBlackBerry::get()->updateCacheCapacity();
  114. }
  115. fontCache()->invalidate();
  116. }
  117. void clearAppCache(const BlackBerry::Platform::String&)
  118. {
  119. cacheStorage().empty();
  120. }
  121. void clearDatabase(const BlackBerry::Platform::String&)
  122. {
  123. }
  124. void updateOnlineStatus(bool online)
  125. {
  126. networkStateNotifier().networkStateChange(online);
  127. }
  128. bool isRunningDrt()
  129. {
  130. #if !defined(PUBLIC_BUILD) || !PUBLIC_BUILD
  131. return getenv("drtRun");
  132. #else
  133. return false;
  134. #endif
  135. }
  136. }
  137. }