123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- /*
- * Copyright (C) 2009, 2010, 2011, 2012 Research In Motion Limited. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
- #include "config.h"
- #include "BlackBerryGlobal.h"
- #include "ApplicationCacheStorage.h"
- #include "CacheClientBlackBerry.h"
- #include "CookieManager.h"
- #include "CrossOriginPreflightResultCache.h"
- #include "FontCache.h"
- #include "ImageSource.h"
- #include "InitializeLogging.h"
- #include "InitializeThreading.h"
- #include "JSDOMWindow.h"
- #include "VM.h"
- #include "MemoryCache.h"
- #include "NetworkStateNotifier.h"
- #include "PageCache.h"
- #include "PageGroup.h"
- #include "PlatformStrategiesBlackBerry.h"
- #include "Settings.h"
- #include "TextureCacheCompositingThread.h"
- #include "bindings/js/GCController.h"
- #include "runtime/JSLock.h"
- #include <BlackBerryPlatformExecutableMessage.h>
- #include <BlackBerryPlatformMessageClient.h>
- #include <BlackBerryPlatformSettings.h>
- #include <BlackBerryPlatformString.h>
- #include <wtf/MainThread.h>
- using namespace WebCore;
- namespace BlackBerry {
- namespace WebKit {
- static bool gIsGlobalInitialized = false;
- // Global initialization of various WebKit singletons.
- void globalInitialize()
- {
- if (gIsGlobalInitialized)
- return;
- gIsGlobalInitialized = true;
- WebCore::Settings::setHiddenPageDOMTimerAlignmentInterval(BlackBerry::Platform::Settings::instance()->isChromeProcess() ? 0 : 1);
- #if ENABLE(BLACKBERRY_DEBUG_MEMORY)
- blackberryDebugInitialize();
- #endif
- #if !LOG_DISABLED
- // Turn on logging.
- initializeLoggingChannelsIfNecessary();
- #endif // !LOG_DISABLED
- // Initialize threading.
- JSC::initializeThreading();
- // Normally this is called from initializeThreading, but we're using ThreadingNone
- // we're grabbing callOnMainThread without using the rest of the threading support.
- WTF::initializeMainThread();
- // Initialize our platform strategies.
- PlatformStrategiesBlackBerry::initialize();
- // Set the minimal timer interval to 4 milliseconds.
- WebCore::Settings::setDefaultMinDOMTimerInterval(0.004);
- // Track visited links.
- PageGroup::setShouldTrackVisitedLinks(true);
- CacheClientBlackBerry::get()->initialize();
- BlackBerry::Platform::Settings* settings = BlackBerry::Platform::Settings::instance();
- ImageSource::setMaxPixelsPerDecodedImage(settings->maxPixelsPerDecodedImage());
- updateOnlineStatus(settings->isNetworkAvailable());
- }
- void collectJavascriptGarbageNow()
- {
- if (gIsGlobalInitialized)
- gcController().garbageCollectNow();
- }
- void clearCookieCache()
- {
- cookieManager().removeAllCookies(RemoveFromBackingStore);
- }
- #if USE(ACCELERATED_COMPOSITING)
- static void clearMemoryCachesInCompositingThread()
- {
- textureCacheCompositingThread()->prune(0);
- }
- #endif
- void clearMemoryCaches()
- {
- #if USE(ACCELERATED_COMPOSITING)
- // Call textureCacheCompositingThread()->prune(0) in UI thread.
- BlackBerry::Platform::userInterfaceThreadMessageClient()->dispatchMessage(BlackBerry::Platform::createFunctionCallMessage(clearMemoryCachesInCompositingThread));
- #endif
- {
- JSC::JSLockHolder lock(JSDOMWindow::commonVM());
- collectJavascriptGarbageNow();
- }
- // Clean caches after JS garbage collection because JS GC can
- // generate more dead resources.
- int capacity = pageCache()->capacity();
- pageCache()->setCapacity(0);
- pageCache()->setCapacity(capacity);
- CrossOriginPreflightResultCache::shared().empty();
- if (!memoryCache()->disabled()) {
- // Evict all dead resources and prune live resources.
- memoryCache()->setCapacities(0, 0, 0);
- // Update cache capacity based on current memory status.
- CacheClientBlackBerry::get()->updateCacheCapacity();
- }
- fontCache()->invalidate();
- }
- void clearAppCache(const BlackBerry::Platform::String&)
- {
- cacheStorage().empty();
- }
- void clearDatabase(const BlackBerry::Platform::String&)
- {
- }
- void updateOnlineStatus(bool online)
- {
- networkStateNotifier().networkStateChange(online);
- }
- bool isRunningDrt()
- {
- #if !defined(PUBLIC_BUILD) || !PUBLIC_BUILD
- return getenv("drtRun");
- #else
- return false;
- #endif
- }
- }
- }
|