summaryrefslogtreecommitdiff
path: root/Source/WebKit/blackberry/Api/BlackBerryGlobal.cpp
blob: a7feffd66cfe4a3013f39a7e6e673c68420ac376 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
 * 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
}

}
}