Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ONEM-21141] On frame url reload trigger image decoded data destruction #53

Open
wants to merge 2 commits into
base: lgi-legacy-ports
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion Source/WebCore/Modules/websockets/WebSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,33 @@
#include "WebCoreThreadRun.h"
#endif

#include <sstream>
#include <vector>

namespace WebCore {

namespace {

bool isWhitelisted(const URL &url) {
static std::vector<URL> whitelisted_urls;
if (whitelisted_urls.empty() && getenv("WPE_WEBSOCKET_WHITELIST")) {
std::stringstream wl_env(getenv("WPE_WEBSOCKET_WHITELIST"));
std::string wl_item;
while (std::getline(wl_env, wl_item, ',')) {
wl_item.insert(0, "ws://");
URL wl_url(URL(), wl_item.c_str());
whitelisted_urls.push_back(wl_url);
}
}

for (auto &wl_url : whitelisted_urls) {
if (protocolHostAndPortAreEqual(wl_url, url)) return true;
}
return false;
}

} // namespace

const size_t maxReasonSizeInBytes = 123;

static inline bool isValidProtocolCharacter(UChar character)
Expand Down Expand Up @@ -282,7 +307,7 @@ ExceptionOr<void> WebSocket::connect(const String& url, const Vector<String>& pr
if (is<Document>(context)) {
Document& document = downcast<Document>(context);
RefPtr<Frame> frame = document.frame();
if (!frame || !frame->loader().mixedContentChecker().canRunInsecureContent(document.securityOrigin(), m_url)) {
if (!frame || (!frame->loader().mixedContentChecker().canRunInsecureContent(document.securityOrigin(), m_url) && !isWhitelisted(m_url))) {
// Balanced by the call to ActiveDOMObject::unsetPendingActivity() in WebSocket::stop().
ActiveDOMObject::setPendingActivity(this);

Expand Down
9 changes: 9 additions & 0 deletions Source/WebCore/loader/FrameLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1328,13 +1328,22 @@ void FrameLoader::loadURL(FrameLoadRequest&& frameLoadRequest, const String& ref

Ref<Frame> protect(m_frame);

if(m_frame.document()) m_frame.document()->cachedResourceLoader().destroyImagesDecodedData();

String frameName = frameLoadRequest.frameName();
AllowNavigationToInvalidURL allowNavigationToInvalidURL = frameLoadRequest.allowNavigationToInvalidURL();
NewFrameOpenerPolicy openerPolicy = frameLoadRequest.newFrameOpenerPolicy();
LockHistory lockHistory = frameLoadRequest.lockHistory();
bool isFormSubmission = formState;

const URL& newURL = frameLoadRequest.resourceRequest().url();

LOG(
Loading,
"%s:%d %s %s",
::basename(__FILE__), __LINE__, __FUNCTION__,
newURL.string().utf8().data());

ResourceRequest request(newURL);
if (!referrer.isEmpty()) {
request.setHTTPReferrer(referrer);
Expand Down
46 changes: 46 additions & 0 deletions Source/WebCore/loader/cache/CachedResourceLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,31 @@ CachedResourceLoader::RevalidationPolicy CachedResourceLoader::determineRevalida
return Use;
}

void CachedResourceLoader::destroyImagesDecodedData()
{
int64_t sizeBefore = 0;
int64_t sizeAfter = 0;

for(auto& resource : m_documentResources)
{
if(CachedResource::Type::ImageResource == resource.value->type())
{
sizeBefore += resource.value->size();
resource.value->destroyDecodedData();
sizeAfter += resource.value->size();
}
}

LOG(
ResourceLoading,
"%s:%d %s"
" totalSize=%" PRId64
", reducedBy=%" PRId64,
::basename(__FILE__), __LINE__, __FUNCTION__,
sizeBefore,
sizeBefore - sizeAfter);
}

void CachedResourceLoader::printAccessDeniedMessage(const URL& url) const
{
if (url.isNull())
Expand Down Expand Up @@ -1331,16 +1356,37 @@ void CachedResourceLoader::garbageCollectDocumentResources()
{
typedef Vector<String, 10> StringVector;
StringVector resourcesToDelete;
int64_t totalSize = 0;
int64_t imgSize = 0;
int64_t deleteSize = 0;

for (auto& resource : m_documentResources) {

totalSize += resource.value->size();

if(CachedResource::Type::ImageResource == resource.value->type()) imgSize += resource.value->size();

if (resource.value->hasOneHandle()) {
deleteSize += resource.value->size();
resourcesToDelete.append(resource.key);
resource.value->setOwningCachedResourceLoader(nullptr);
}
}

for (auto& resource : resourcesToDelete)
m_documentResources.remove(resource);

LOG(
ResourceLoading,
"%s:%d %s"
" totalSize=%" PRId64
", imgSize=%" PRId64
", deleteSize=%" PRId64,
::basename(__FILE__), __LINE__, __FUNCTION__,
totalSize,
imgSize,
deleteSize);

}

void CachedResourceLoader::performPostLoadActions()
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/loader/cache/CachedResourceLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ friend class ResourceCacheValidationSuppressor;
#if ENABLE(APPLICATION_MANIFEST)
ResourceErrorOr<CachedResourceHandle<CachedApplicationManifest>> requestApplicationManifest(CachedResourceRequest&&);
#endif
void destroyImagesDecodedData();

// Called to load Web Worker main script, Service Worker main script, importScripts(), XHR,
// EventSource, Fetch, and App Cache.
Expand Down