[BlackBerry] Clear local storage won't take effect until browser exit and relaunch
[WebKit-https.git] / Source / WebKit / blackberry / Api / BlackBerryGlobal.cpp
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
19 #include "config.h"
20 #include "BlackBerryGlobal.h"
21
22 #include "ApplicationCacheStorage.h"
23 #include "CacheClientBlackBerry.h"
24 #include "CookieManager.h"
25 #include "CrossOriginPreflightResultCache.h"
26 #include "FontCache.h"
27 #include "ImageSource.h"
28 #include "InitializeThreading.h"
29 #include "JSDOMWindow.h"
30 #include "JSGlobalData.h"
31 #include "Logging.h"
32 #include "MainThread.h"
33 #include "MemoryCache.h"
34 #include "NetworkStateNotifier.h"
35 #include "PageCache.h"
36 #include "PageGroup.h"
37 #include "TextureCacheCompositingThread.h"
38 #include "WebString.h"
39 #include "bindings/js/GCController.h"
40 #include "runtime/JSLock.h"
41 #include <BlackBerryPlatformExecutableMessage.h>
42 #include <BlackBerryPlatformMessageClient.h>
43 #include <BlackBerryPlatformSettings.h>
44
45 using namespace WebCore;
46
47 namespace BlackBerry {
48 namespace WebKit {
49
50 static bool gIsGlobalInitialized = false;
51
52 // Global initialization of various WebKit singletons.
53 void globalInitialize()
54 {
55     if (gIsGlobalInitialized)
56         return;
57     gIsGlobalInitialized = true;
58
59 #if ENABLE(BLACKBERRY_DEBUG_MEMORY)
60     blackberryDebugInitialize();
61 #endif
62
63     // Turn on logging.
64     initializeLoggingChannelsIfNecessary();
65
66     // Initialize threading/
67     JSC::initializeThreading();
68
69     // Normally this is called from initializeThreading, but we're using ThreadingNone
70     // we're grabbing callOnMainThread without using the rest of the threading support.
71     WTF::initializeMainThread();
72
73     // Track visited links.
74     PageGroup::setShouldTrackVisitedLinks(true);
75
76     CacheClientBlackBerry::get()->initialize();
77
78     BlackBerry::Platform::Settings* settings = BlackBerry::Platform::Settings::get();
79
80     ImageSource::setMaxPixelsPerDecodedImage(settings->maxPixelsPerDecodedImage());
81 }
82
83 void collectJavascriptGarbageNow()
84 {
85     if (gIsGlobalInitialized)
86         gcController().garbageCollectNow();
87 }
88
89 void clearCookieCache()
90 {
91     cookieManager().removeAllCookies(RemoveFromBackingStore);
92 }
93
94 #if USE(ACCELERATED_COMPOSITING)
95 static void clearMemoryCachesInCompositingThread()
96 {
97     textureCacheCompositingThread()->prune(0);
98 }
99 #endif
100
101 void clearMemoryCaches()
102 {
103 #if USE(ACCELERATED_COMPOSITING)
104     // Call textureCacheCompositingThread()->prune(0) in UI thread.
105     BlackBerry::Platform::userInterfaceThreadMessageClient()->dispatchMessage(BlackBerry::Platform::createFunctionCallMessage(clearMemoryCachesInCompositingThread));
106 #endif
107
108     {
109         JSC::JSLock lock(JSC::SilenceAssertionsOnly);
110         // This function also performs a GC.
111         JSC::releaseExecutableMemory(*JSDOMWindow::commonJSGlobalData());
112     }
113
114     // Clean caches after JS garbage collection because JS GC can
115     // generate more dead resources.
116     int capacity = pageCache()->capacity();
117     pageCache()->setCapacity(0);
118     pageCache()->setCapacity(capacity);
119     pageCache()->releaseAutoreleasedPagesNow();
120
121     CrossOriginPreflightResultCache::shared().empty();
122
123     if (!memoryCache()->disabled()) {
124         // Evict all dead resources and prune live resources.
125         memoryCache()->setCapacities(0, 0, 0);
126
127         // Update cache capacity based on current memory status.
128         CacheClientBlackBerry::get()->updateCacheCapacity();
129     }
130
131     fontCache()->invalidate();
132 }
133
134 void clearAppCache(const WebString& pageGroupName)
135 {
136     cacheStorage().empty();
137 }
138
139 void clearDatabase(const WebString& pageGroupName)
140 {
141 }
142
143 void updateOnlineStatus(bool online)
144 {
145     networkStateNotifier().networkStateChange(online);
146 }
147
148 }
149 }