From ed62c3396d157c192543eda64860f90fae6a9464 Mon Sep 17 00:00:00 2001 From: Jihye Kang Date: Fri, 29 Mar 2013 09:56:46 +0900 Subject: [PATCH] [WK2] Apply quota policy for LocalFileSystem [Title] Apply quota policy for LocalFileSystem [Issue#] N/A [Problem] Quota is not limited for LocalFileSystem [Cause] [Solution] apply quota policy for LocalFileSystem - Default quota per origin: 100*1024*1024 - Maximum quota per origin: 2*1024*1024*1024 - Request quota for UA when quota is about to exceed from default - ewk_view_exceeded_local_file_system_quota_callback_set() is added for calling the callback when request quota for UA - ewk_view_exceeded_local_file_system_quota_reply() is added to allow/deny quota Change-Id: I6262bedbf76db651dc50df905d2896edb6738fc3 --- Source/WebCore/loader/EmptyClients.h | 4 + Source/WebCore/page/ChromeClient.h | 4 + Source/WebCore/page/GroupSettings.cpp | 9 ++ Source/WebCore/page/GroupSettings.h | 8 ++ Source/WebCore/platform/FileSystem.h | 7 +- .../platform/efl/tizen/AsyncFileSystemTizen.cpp | 95 +++++++++++++++++++--- .../platform/efl/tizen/AsyncFileSystemTizen.h | 1 + .../platform/efl/tizen/AsyncFileWriterTizen.cpp | 14 +++- .../WebCore/platform/efl/tizen/FileSystemTizen.cpp | 38 +++++++++ Source/WebCore/workers/WorkerThread.cpp | 4 + .../UIProcess/API/C/efl/tizen/WKPageTizen.cpp | 7 ++ .../UIProcess/API/C/efl/tizen/WKPageTizen.h | 11 +++ Source/WebKit2/UIProcess/API/efl/EwkViewImpl.h | 6 ++ Source/WebKit2/UIProcess/API/efl/ewk_view.cpp | 55 +++++++++++++ Source/WebKit2/UIProcess/API/efl/ewk_view.h | 6 ++ .../WebKit2/UIProcess/API/efl/ewk_view_private.h | 4 + .../UIProcess/API/efl/ewk_view_tizen_client.cpp | 12 ++- Source/WebKit2/UIProcess/WebPageProxy.h | 12 +++ Source/WebKit2/UIProcess/WebPageProxy.messages.in | 4 + Source/WebKit2/UIProcess/efl/WebPageProxyEfl.cpp | 32 ++++++++ Source/WebKit2/UIProcess/tizen/WebTizenClient.cpp | 10 +++ Source/WebKit2/UIProcess/tizen/WebTizenClient.h | 4 + .../WebProcess/WebCoreSupport/WebChromeClient.cpp | 18 ++++ .../WebProcess/WebCoreSupport/WebChromeClient.h | 4 + Source/WebKit2/WebProcess/WebPage/WebPage.cpp | 4 + 25 files changed, 354 insertions(+), 19 deletions(-) diff --git a/Source/WebCore/loader/EmptyClients.h b/Source/WebCore/loader/EmptyClients.h index 90cb2b3..6fcde13 100755 --- a/Source/WebCore/loader/EmptyClients.h +++ b/Source/WebCore/loader/EmptyClients.h @@ -237,6 +237,10 @@ public: virtual bool exceededIndexedDatabaseQuota(Frame*, int64_t) { } #endif +#if ENABLE(TIZEN_FILE_SYSTEM) + virtual bool exceededLocalFileSystemQuota(Frame* frame, int64_t currentUsage) { } +#endif + }; class EmptyFrameLoaderClient : public FrameLoaderClient { diff --git a/Source/WebCore/page/ChromeClient.h b/Source/WebCore/page/ChromeClient.h index 2f9f7eb..55dcd35 100755 --- a/Source/WebCore/page/ChromeClient.h +++ b/Source/WebCore/page/ChromeClient.h @@ -406,6 +406,10 @@ namespace WebCore { virtual bool exceededIndexedDatabaseQuota(Frame*, int64_t) = 0; #endif +#if ENABLE(TIZEN_FILE_SYSTEM) + virtual bool exceededLocalFileSystemQuota(Frame*, int64_t currentUsage) = 0; +#endif + protected: virtual ~ChromeClient() { } }; diff --git a/Source/WebCore/page/GroupSettings.cpp b/Source/WebCore/page/GroupSettings.cpp index 0762861..7801cfd 100644 --- a/Source/WebCore/page/GroupSettings.cpp +++ b/Source/WebCore/page/GroupSettings.cpp @@ -31,6 +31,9 @@ namespace WebCore { GroupSettings::GroupSettings() : m_localStorageQuotaBytes(5 * 1024 * 1024) // Suggested by the HTML5 spec. , m_indexedDBQuotaBytes(5 * 1024 * 1024) +#if ENABLE(TIZEN_FILE_SYSTEM) + , m_localFileSystemQuotaBytes(0x6400000) // 100M +#endif { } @@ -49,5 +52,11 @@ void GroupSettings::setIndexedDBQuotaBytes(int64_t quota) m_indexedDBQuotaBytes = quota; } +#if ENABLE(TIZEN_FILE_SYSTEM) +void GroupSettings::setLocalFileSystemQuotaBytes(int64_t quota) +{ + m_localFileSystemQuotaBytes = quota; +} +#endif } // namespace WebCore diff --git a/Source/WebCore/page/GroupSettings.h b/Source/WebCore/page/GroupSettings.h index 1bbad2b..2f1bcd7 100644 --- a/Source/WebCore/page/GroupSettings.h +++ b/Source/WebCore/page/GroupSettings.h @@ -50,12 +50,20 @@ public: void setIndexedDBDatabasePath(const String&); const String& indexedDBDatabasePath() const { return m_indexedDBDatabasePath; } +#if ENABLE(TIZEN_FILE_SYSTEM) + void setLocalFileSystemQuotaBytes(int64_t quota); + int64_t localFileSystemQuotaBytes() const { return m_localFileSystemQuotaBytes; } +#endif + private: GroupSettings(); unsigned m_localStorageQuotaBytes; String m_indexedDBDatabasePath; int64_t m_indexedDBQuotaBytes; +#if ENABLE(TIZEN_FILE_SYSTEM) + int64_t m_localFileSystemQuotaBytes; +#endif }; } // namespace WebCore diff --git a/Source/WebCore/platform/FileSystem.h b/Source/WebCore/platform/FileSystem.h index 35d70b9..7529d20 100644 --- a/Source/WebCore/platform/FileSystem.h +++ b/Source/WebCore/platform/FileSystem.h @@ -228,10 +228,11 @@ bool safeCreateFile(const String&, CFDataRef); #endif #if ENABLE(TIZEN_FILE_SYSTEM) -bool copyFile(const String&, const String&); -bool linkFile(const String&, const String&); +bool copyFile(const String& sourcePath, const String& destinationPath); +bool getDirectorySize(const String& path, long long& size); +bool linkFile(const String& sourcePath, const String& destinationPath); bool removeDirectory(const String& path); -bool renameFile(const String&, const String&); +bool renameFile(const String& sourcePath, const String& destinationPath); #endif } // namespace WebCore diff --git a/Source/WebCore/platform/efl/tizen/AsyncFileSystemTizen.cpp b/Source/WebCore/platform/efl/tizen/AsyncFileSystemTizen.cpp index 17bb48e..8f85f9f 100644 --- a/Source/WebCore/platform/efl/tizen/AsyncFileSystemTizen.cpp +++ b/Source/WebCore/platform/efl/tizen/AsyncFileSystemTizen.cpp @@ -32,9 +32,11 @@ #include "FileMetadata.h" #include "FileSystem.h" #include "GOwnPtr.h" +#include "GroupSettings.h" #include "LocalFileSystem.h" #include "NotImplemented.h" #include "Page.h" +#include "PageGroup.h" #include "SecurityOrigin.h" #include "WorkerContext.h" #include "WorkerRunLoop.h" @@ -49,14 +51,6 @@ namespace WebCore { -/* -// Defined but not used. -static void openFileSystemNotAllowed(ScriptExecutionContext*, PassOwnPtr callbacks) -{ - callbacks->didFail(FileError::SECURITY_ERR); -} -*/ - static void openFileSystem(ScriptExecutionContext* context, const String& basePath, const String& identifier, FileSystemType type, bool create, PassOwnPtr callbacks, FileSystemSynchronousType synchronousType) { String typeString = (type == FileSystemTypePersistent) ? "Persistent" : "Temporary"; @@ -172,7 +166,7 @@ void AsyncFileSystemTizen::move(const KURL& srcPath, const KURL& destPath, PassO m_taskController->postTaskToMainThread(createCallbackTask(&moveAsync, AsyncFileSystemCallbacksTizen::create(m_taskController.get(), callbacks, mode), sourceFileSystemPath, destinationFileSystemPath)); } -static void copyAsync(ScriptExecutionContext*, PassOwnPtr helperCallbacks, const String& sourcePath, const String& destinationPath) +static void copyAsync(ScriptExecutionContext* context, PassOwnPtr helperCallbacks, const String& sourcePath, const String& destinationPath) { if (!fileExists(sourcePath)) { helperCallbacks->didFail(FileError::NOT_FOUND_ERR); @@ -184,6 +178,12 @@ static void copyAsync(ScriptExecutionContext*, PassOwnPtrdidFail(errorCode); + return; + } + if (copyFile(sourcePath, destinationPath)) helperCallbacks->didSucceed(); else @@ -251,13 +251,19 @@ void AsyncFileSystemTizen::readMetadata(const KURL& path, PassOwnPtrpostTaskToMainThread(createCallbackTask(&readMetadataAsync, AsyncFileSystemCallbacksTizen::create(m_taskController.get(), callbacks, mode), fileSystemPath)); } -static void createFileAsync(ScriptExecutionContext*, bool exclusive, PassOwnPtr helperCallbacks, const String& path) +static void createFileAsync(ScriptExecutionContext* context, bool exclusive, PassOwnPtr helperCallbacks, const String& path) { if (exclusive && fileExists(path)) { helperCallbacks->didFail(FileError::PATH_EXISTS_ERR); return; } + int errorCode = 0; + if (!AsyncFileSystemTizen::checkQuota(context, path, errorCode)) { + helperCallbacks->didFail(errorCode); + return; + } + PlatformFileHandle handle; handle = openFile(path, OpenForWrite); @@ -275,13 +281,19 @@ void AsyncFileSystemTizen::createFile(const KURL& path, bool exclusive, PassOwnP m_taskController->postTaskToMainThread(createCallbackTask(&createFileAsync, exclusive, AsyncFileSystemCallbacksTizen::create(m_taskController.get(), callbacks, mode), fileSystemPath)); } -static void createDirectoryAsync(ScriptExecutionContext*, bool exclusive, PassOwnPtr helperCallbacks, const String& path) +static void createDirectoryAsync(ScriptExecutionContext* context, bool exclusive, PassOwnPtr helperCallbacks, const String& path) { if (exclusive && fileExists(path)) { helperCallbacks->didFail(FileError::PATH_EXISTS_ERR); return; } + int errorCode = 0; + if (!AsyncFileSystemTizen::checkQuota(context, path, errorCode)) { + helperCallbacks->didFail(errorCode); + return; + } + if (makeAllDirectories(path)) helperCallbacks->didSucceed(); else @@ -418,9 +430,66 @@ String AsyncFileSystemTizen::virtualPathToFileSystemPath(const KURL& virtualPath fileSystemPath.append(origin->databaseIdentifier()); fileSystemPath.append(innerURL.path()); - return String(fileSystemRepresentation(fileSystemPath.toString()).data()); + return fileSystemPath.toString(); +} + +bool AsyncFileSystemTizen::checkQuota(ScriptExecutionContext* context, const String& sourcePath, int& errorCode) +{ + if (!sourcePath.startsWith(LocalFileSystem::localFileSystem().fileSystemBasePath())) { + errorCode = FileError::NOT_FOUND_ERR; + return false; + } + + String subPath = sourcePath.substring(LocalFileSystem::localFileSystem().fileSystemBasePath().length()); + Vector components; + subPath.split('/', components); + size_t componentsSize = components.size(); + if (!componentsSize) { + errorCode = FileError::NOT_FOUND_ERR; + return false; + } + + StringBuilder fileSystemPath; + fileSystemPath.append(LocalFileSystem::localFileSystem().fileSystemBasePath()); + if (subPath.startsWith('/')) + fileSystemPath.append('/'); + fileSystemPath.append(components[0]); + String originRootPath = String(fileSystemRepresentation(fileSystemPath.toString()).data()); + + int64_t usage = 0; + if (!getDirectorySize(originRootPath, usage)) { + errorCode = FileError::NOT_READABLE_ERR; + return false; + } + + if (context->isDocument()) { + Document* document = static_cast(context); + int64_t defaultQuota = document->page()->group().groupSettings()->localFileSystemQuotaBytes(); + int64_t maxQuota = 0x80000000; // 2GB + if (usage > maxQuota) { + errorCode = FileError::QUOTA_EXCEEDED_ERR; + return false; + } + + if (usage >= defaultQuota && defaultQuota != maxQuota) { + if (document->page()->chrome()->client()->exceededLocalFileSystemQuota(document->frame(), usage)) + document->page()->group().groupSettings()->setLocalFileSystemQuotaBytes(maxQuota); + else { + errorCode = FileError::QUOTA_EXCEEDED_ERR; + return false; + } + } + } else { + WorkerContext* workerContext = static_cast(context); + if (usage >= workerContext->groupSettings()->localFileSystemQuotaBytes()) { + errorCode = FileError::QUOTA_EXCEEDED_ERR; + return false; + } + } + + return true; } } // namespace WebCore -#endif // ENABLE(FILE_SYSTEM) +#endif// ENABLE(FILE_SYSTEM) diff --git a/Source/WebCore/platform/efl/tizen/AsyncFileSystemTizen.h b/Source/WebCore/platform/efl/tizen/AsyncFileSystemTizen.h index bf7a656..1dd95e1 100644 --- a/Source/WebCore/platform/efl/tizen/AsyncFileSystemTizen.h +++ b/Source/WebCore/platform/efl/tizen/AsyncFileSystemTizen.h @@ -56,6 +56,7 @@ public: void setTaskController(PassRefPtr); static String virtualPathToFileSystemPath(const KURL&); + static bool checkQuota(ScriptExecutionContext*, const String& path, int& errorCode); private: String m_localFileSystemBasePath; diff --git a/Source/WebCore/platform/efl/tizen/AsyncFileWriterTizen.cpp b/Source/WebCore/platform/efl/tizen/AsyncFileWriterTizen.cpp index f31fab7..2925e1f 100644 --- a/Source/WebCore/platform/efl/tizen/AsyncFileWriterTizen.cpp +++ b/Source/WebCore/platform/efl/tizen/AsyncFileWriterTizen.cpp @@ -25,6 +25,7 @@ #if ENABLE(TIZEN_FILE_SYSTEM) +#include "AsyncFileSystemTizen.h" #include "AsyncFileWriterClientTizen.h" #include "Blob.h" #include "BlobRegistryImpl.h" @@ -42,14 +43,23 @@ AsyncFileWriterTizen::AsyncFileWriterTizen(AsyncFileWriterClient* client, const { } -static void writeAsync(ScriptExecutionContext*, PassOwnPtr helperClient, const String& path, long long position, Blob* data) +static void writeAsync(ScriptExecutionContext* context, PassOwnPtr helperClient, const String& path, long long position, Blob* data) { int bytesWritten; PlatformFileHandle handle; handle = openFile(path, OpenForWrite); - if (!isHandleValid(handle)) + if (!isHandleValid(handle)) { + helperClient->didFail(FileError::NOT_FOUND_ERR); + return; + } + + int errorCode = 0; + if (!AsyncFileSystemTizen::checkQuota(context, path, errorCode)) { + closeFile(handle); + helperClient->didFail(static_cast(errorCode)); return; + } RefPtr blobStorage = static_cast(blobRegistry()).getBlobDataFromURL(data->url()); if (blobStorage) { diff --git a/Source/WebCore/platform/efl/tizen/FileSystemTizen.cpp b/Source/WebCore/platform/efl/tizen/FileSystemTizen.cpp index 83053cf..a0d6f9c 100644 --- a/Source/WebCore/platform/efl/tizen/FileSystemTizen.cpp +++ b/Source/WebCore/platform/efl/tizen/FileSystemTizen.cpp @@ -31,6 +31,7 @@ #if ENABLE(TIZEN_FILE_SYSTEM) #include "FileMetadata.h" +#include #include #include #include @@ -38,6 +39,43 @@ namespace WebCore { +bool getDirectorySize(const String& path, long long& size) +{ + if(!fileExists(path)) + return false; + + DIR* directory = opendir(fileSystemRepresentation(path).data()); + if(!directory) + return false; + + struct dirent* directoryEntry; + struct stat buf; + + while (directoryEntry = readdir(directory)) { + if (!strcmp(directoryEntry->d_name, ".") || !strcmp(directoryEntry->d_name, "..")) + continue; + + String absolutePath = pathByAppendingComponent(path, String(directoryEntry->d_name)); + + if (lstat(absolutePath.utf8().data(), &buf) == -1) { + closedir(directory); + return false; + } + + bool result; + if (S_ISDIR(buf.st_mode)) { + if (!getDirectorySize(absolutePath, size)) { + closedir(directory); + return false; + } + } else + size += buf.st_size; + } + + closedir(directory); + return true; +} + bool getFileMetadata(const String& path, FileMetadata& metadata) { CString fsRep = fileSystemRepresentation(path); diff --git a/Source/WebCore/workers/WorkerThread.cpp b/Source/WebCore/workers/WorkerThread.cpp index bd0355c..3b90ea2 100644 --- a/Source/WebCore/workers/WorkerThread.cpp +++ b/Source/WebCore/workers/WorkerThread.cpp @@ -102,6 +102,10 @@ WorkerThreadStartupData::WorkerThreadStartupData(const KURL& scriptURL, const St m_groupSettings->setLocalStorageQuotaBytes(settings->localStorageQuotaBytes()); m_groupSettings->setIndexedDBQuotaBytes(settings->indexedDBQuotaBytes()); m_groupSettings->setIndexedDBDatabasePath(settings->indexedDBDatabasePath().isolatedCopy()); +#if ENABLE(TIZEN_FILE_SYSTEM) + m_groupSettings->setLocalFileSystemQuotaBytes(settings->localFileSystemQuotaBytes()); +#endif + } WorkerThread::WorkerThread(const KURL& scriptURL, const String& userAgent, const GroupSettings* settings, const String& sourceCode, WorkerLoaderProxy& workerLoaderProxy, WorkerReportingProxy& workerReportingProxy, WorkerThreadStartMode startMode, const String& contentSecurityPolicy, ContentSecurityPolicy::HeaderType contentSecurityPolicyType) diff --git a/Source/WebKit2/UIProcess/API/C/efl/tizen/WKPageTizen.cpp b/Source/WebKit2/UIProcess/API/C/efl/tizen/WKPageTizen.cpp index bdd1c8b..01499fb 100644 --- a/Source/WebKit2/UIProcess/API/C/efl/tizen/WKPageTizen.cpp +++ b/Source/WebKit2/UIProcess/API/C/efl/tizen/WKPageTizen.cpp @@ -141,3 +141,10 @@ void WKPageReplyExceededDatabaseQuota(WKPageRef page, bool allow) toImpl(page)->replyExceededDatabaseQuota(allow); #endif } + +void WKPageReplyExceededLocalFileSystemQuota(WKPageRef page, bool allow) +{ +#if ENABLE(TIZEN_FILE_SYSTEM) + toImpl(page)->replyExceededLocalFileSystemQuota(allow); +#endif +} diff --git a/Source/WebKit2/UIProcess/API/C/efl/tizen/WKPageTizen.h b/Source/WebKit2/UIProcess/API/C/efl/tizen/WKPageTizen.h index a96728e..638d839 100644 --- a/Source/WebKit2/UIProcess/API/C/efl/tizen/WKPageTizen.h +++ b/Source/WebKit2/UIProcess/API/C/efl/tizen/WKPageTizen.h @@ -50,6 +50,9 @@ typedef bool (*WKPageDecidePolicyForCertificateErrorCallback)(WKPageRef page, WK //#if ENABLE(TIZEN_INDEXED_DATABASE) typedef bool (*WKPageExceededIndexedDatabaseQuotaCallback)(WKPageRef page, WKSecurityOriginRef origin, long long currentUsage, WKFrameRef frame, const void* clientInfo); //#endif +//#if ENABLE(TIZEN_FILE_SYSTEM) +typedef bool (*WKPageExceededLocalFileSystemQuotaCallback)(WKPageRef page, WKSecurityOriginRef origin, long long currentUsage, WKFrameRef frame, const void* clientInfo); +//#endif struct WKPageTizenClient { int version; @@ -73,6 +76,9 @@ struct WKPageTizenClient { //#if ENABLE(TIZEN_INDEXED_DATABASE) WKPageExceededIndexedDatabaseQuotaCallback exceededIndexedDatabaseQuota; //#endif + //#if ENABLE(TIZEN_FILE_SYSTEM) + WKPageExceededLocalFileSystemQuotaCallback exceededLocalFileSystemQuota; + //#endif }; typedef struct WKPageTizenClient WKPageTizenClient; @@ -123,6 +129,11 @@ WK_EXPORT void WKPageReplyExceededIndexedDatabaseQuota(WKPageRef page, bool allo // #if ENABLE(TIZEN_SQL_DATABASE) WK_EXPORT void WKPageReplyExceededDatabaseQuota(WKPageRef page, bool allow); // #endif + +//#if ENABLE(TIZEN_FILE_SYSTEM) +WK_EXPORT void WKPageReplyExceededLocalFileSystemQuota(WKPageRef page, bool allow); +//#endif + #ifdef __cplusplus } #endif diff --git a/Source/WebKit2/UIProcess/API/efl/EwkViewImpl.h b/Source/WebKit2/UIProcess/API/efl/EwkViewImpl.h index e90a50f..02cd6cb 100755 --- a/Source/WebKit2/UIProcess/API/efl/EwkViewImpl.h +++ b/Source/WebKit2/UIProcess/API/efl/EwkViewImpl.h @@ -161,6 +161,9 @@ struct Ewk_View_Callback_Context { #if ENABLE(TIZEN_SQL_DATABASE) Ewk_View_Exceeded_Database_Quota_Callback exceededDatabaseQuotaCallback; #endif +#if ENABLE(TIZEN_FILE_SYSTEM) + Ewk_View_Exceeded_Local_File_System_Quota_Callback exceededLocalFileSystemQuotaCallback; +#endif }; Evas_Object* ewkView; @@ -466,6 +469,9 @@ public: #if ENABLE(TIZEN_SQL_DATABASE) OwnPtr exceededDatabaseQuotaContext; #endif +#if ENABLE(TIZEN_FILE_SYSTEM) + OwnPtr exceededLocalFileSystemQuotaContext; +#endif Ewk_Security_Origin* exceededQuotaOrigin; bool isWaitingForExceededQuotaPopupReply; #endif // #if OS(TIZEN) diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_view.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_view.cpp index 1f9a9ec..8f0ff01 100755 --- a/Source/WebKit2/UIProcess/API/efl/ewk_view.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_view.cpp @@ -4635,3 +4635,58 @@ void ewk_view_exceeded_database_quota_reply(Evas_Object* ewkView, Eina_Bool allo UNUSED_PARAM(allow); #endif } + +#if ENABLE(TIZEN_FILE_SYSTEM) +bool ewkViewExceededLocalFileSystemQuota(Evas_Object* ewkView, WKSecurityOriginRef origin, long long currentUsage) +{ + EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false); + EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false); + + if (!impl->exceededLocalFileSystemQuotaContext || !impl->exceededLocalFileSystemQuotaContext->exceededLocalFileSystemQuotaCallback) + return false; + + impl->isWaitingForExceededQuotaPopupReply = true; + if (impl->exceededQuotaOrigin) + deleteSecurityOrigin(impl->exceededQuotaOrigin); + impl->exceededQuotaOrigin = createSecurityOrigin(origin); + + TIZEN_LOGI("currentUsage(%lld)", currentUsage); + + return impl->exceededLocalFileSystemQuotaContext->exceededLocalFileSystemQuotaCallback(ewkView, impl->exceededQuotaOrigin , currentUsage, impl->exceededLocalFileSystemQuotaContext->userData) == EINA_TRUE; +} +#endif + +void ewk_view_exceeded_local_file_system_quota_callback_set(Evas_Object* ewkView, Ewk_View_Exceeded_Indexed_Database_Quota_Callback callback, void* userData) +{ +#if ENABLE(TIZEN_FILE_SYSTEM) + EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData); + EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl); + + if (!impl->exceededLocalFileSystemQuotaContext) + impl->exceededLocalFileSystemQuotaContext = adoptPtr(new Ewk_View_Callback_Context); + impl->exceededLocalFileSystemQuotaContext->exceededLocalFileSystemQuotaCallback = callback; + impl->exceededLocalFileSystemQuotaContext->userData = userData; +#else + UNUSED_PARAM(ewkView); + UNUSED_PARAM(callback); + UNUSED_PARAM(userData); +#endif +} + +void ewk_view_exceeded_local_file_system_quota_reply(Evas_Object* ewkView, Eina_Bool allow) +{ +#if ENABLE(TIZEN_FILE_SYSTEM) + EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData); + EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl); + + TIZEN_LOGI("allow %d", allow); + WKPageReplyExceededLocalFileSystemQuota(toAPI(impl->page()), allow == EINA_TRUE); + if (impl->exceededQuotaOrigin) + deleteSecurityOrigin(impl->exceededQuotaOrigin); + impl->exceededQuotaOrigin = 0; + impl->isWaitingForExceededQuotaPopupReply = false; +#else + UNUSED_PARAM(ewkView); + UNUSED_PARAM(result); +#endif +} diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_view.h b/Source/WebKit2/UIProcess/API/efl/ewk_view.h index b6d4433..b7279be 100755 --- a/Source/WebKit2/UIProcess/API/efl/ewk_view.h +++ b/Source/WebKit2/UIProcess/API/efl/ewk_view.h @@ -717,6 +717,12 @@ EAPI void ewk_view_exceeded_database_quota_callback_set(Evas_Object* o, Ewk_View EAPI void ewk_view_exceeded_database_quota_reply(Evas_Object* o, Eina_Bool allow); // #endif +//#if ENABLE(TIZEN_FILE_SYSTEM) +typedef Eina_Bool (*Ewk_View_Exceeded_Local_File_System_Quota_Callback)(Evas_Object* o, Ewk_Security_Origin* origin, long long currentQuota, void* user_data); +EAPI void ewk_view_exceeded_local_file_system_quota_callback_set(Evas_Object* o, Ewk_View_Exceeded_Local_File_System_Quota_Callback callback, void* user_data); +EAPI void ewk_view_exceeded_local_file_system_quota_reply(Evas_Object* o, Eina_Bool allow); +//#endif + /** * Gets the Ewk_Settings of this view. * diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_view_private.h b/Source/WebKit2/UIProcess/API/efl/ewk_view_private.h index a1a1eff..99db2ed 100755 --- a/Source/WebKit2/UIProcess/API/efl/ewk_view_private.h +++ b/Source/WebKit2/UIProcess/API/efl/ewk_view_private.h @@ -286,4 +286,8 @@ void ewk_view_form_candidate_data_get(Evas_Object* ewkView, const String& name, void ewk_view_text_change_in_textfield(Evas_Object* ewkView, const String& name, const String& value); #endif +#if ENABLE(TIZEN_FILE_SYSTEM) +bool ewkViewExceededLocalFileSystemQuota(Evas_Object* ewkView, WKSecurityOriginRef origin, long long currentUsage); +#endif + #endif // ewk_view_private_h diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_view_tizen_client.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_view_tizen_client.cpp index 03b7b14..1a4eeb7 100755 --- a/Source/WebKit2/UIProcess/API/efl/ewk_view_tizen_client.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_view_tizen_client.cpp @@ -86,6 +86,15 @@ static bool exceededIndexedDatabaseQuota(WKPageRef page, WKSecurityOriginRef ori #endif } +static bool exceededLocalFileSystemQuota(WKPageRef page, WKSecurityOriginRef origin, long long currentUsage, WKFrameRef frame, const void *clientInfo) +{ +#if ENABLE(TIZEN_FILE_SYSTEM) + return ewkViewExceededLocalFileSystemQuota(static_cast(const_cast(clientInfo)), origin, currentUsage); +#else + return false; +#endif +} + void ewkViewTizenClientAttachClient(Evas_Object* ewkView) { EINA_SAFETY_ON_NULL_RETURN(ewkView); @@ -98,7 +107,8 @@ void ewkViewTizenClientAttachClient(Evas_Object* ewkView) decidePolicyForUserMediaPermissionRequest, processJSBridgePlugin, decidePolicyForCertificateError, - exceededIndexedDatabaseQuota + exceededIndexedDatabaseQuota, + exceededLocalFileSystemQuota }; WKPageSetPageTizenClient(toAPI(EwkViewImpl::fromEvasObject(ewkView)->page()), &tizenClient); diff --git a/Source/WebKit2/UIProcess/WebPageProxy.h b/Source/WebKit2/UIProcess/WebPageProxy.h index e130191..08fbadb 100755 --- a/Source/WebKit2/UIProcess/WebPageProxy.h +++ b/Source/WebKit2/UIProcess/WebPageProxy.h @@ -1039,6 +1039,10 @@ void recordingSurfaceSetEnableSet(bool enable); void replyExceededDatabaseQuota(bool allow); #endif +#if ENABLE(TIZEN_FILE_SYSTEM) + void replyExceededLocalFileSystemQuota(bool allow); +#endif + private: WebPageProxy(PageClient*, PassRefPtr, WebPageGroup*, uint64_t pageID); @@ -1402,6 +1406,10 @@ private: void exceededIndexedDatabaseQuota(uint64_t frameID, const String& originIdentifier, int64_t currentUsage, PassRefPtr reply); #endif +#if ENABLE(TIZEN_FILE_SYSTEM) + void exceededLocalFileSystemQuota(uint64_t frameID, const String& originIdentifier, int64_t currentUsage, PassRefPtr reply); +#endif + PageClient* m_pageClient; WebLoaderClient m_loaderClient; WebPolicyClient m_policyClient; @@ -1660,6 +1668,10 @@ private: #if ENABLE(TIZEN_INDEXED_DATABASE) RefPtr m_exceededIndexedDatabaseQuotaReply; #endif + +#if ENABLE(TIZEN_FILE_SYSTEM) + RefPtr m_exceededLocalFileSystemQuotaReply; +#endif }; } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/WebPageProxy.messages.in b/Source/WebKit2/UIProcess/WebPageProxy.messages.in index 5b439e8..8d3cb98 100755 --- a/Source/WebKit2/UIProcess/WebPageProxy.messages.in +++ b/Source/WebKit2/UIProcess/WebPageProxy.messages.in @@ -467,4 +467,8 @@ messages -> WebPageProxy { #if ENABLE(TIZEN_INDEXED_DATABASE) ExceededIndexedDatabaseQuota(uint64_t frameID, WTF::String originIdentifier, int64_t currentUsage) -> (bool returnValue) Delayed #endif + +#if ENABLE(TIZEN_FILE_SYSTEM) + ExceededLocalFileSystemQuota(uint64_t frameID, WTF::String originIdentifier, int64_t currentUsage) -> (bool allow) Delayed +#endif } diff --git a/Source/WebKit2/UIProcess/efl/WebPageProxyEfl.cpp b/Source/WebKit2/UIProcess/efl/WebPageProxyEfl.cpp index 4dff2e5..84098c2 100755 --- a/Source/WebKit2/UIProcess/efl/WebPageProxyEfl.cpp +++ b/Source/WebKit2/UIProcess/efl/WebPageProxyEfl.cpp @@ -1099,6 +1099,38 @@ void WebPageProxy::replyExceededDatabaseQuota(bool allow) } #endif +#if ENABLE(TIZEN_FILE_SYSTEM) +void WebPageProxy::exceededLocalFileSystemQuota(uint64_t frameID, const String& originIdentifier, int64_t currentUsage, PassRefPtr reply) +{ + WebFrameProxy* frame = process()->webFrame(frameID); + MESSAGE_CHECK(frame); + + // Since exceededLocalFileSystemQuota() can spin a nested run loop we need to turn off the responsiveness timer. + process()->responsivenessTimer()->stop(); + m_exceededLocalFileSystemQuotaReply = reply; +#if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP) + process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(true); +#endif + + RefPtr origin = WebSecurityOrigin::createFromDatabaseIdentifier(originIdentifier); + + if (!m_tizenClient.exceededLocalFileSystemQuota(this, origin.get(), currentUsage, frame)) + replyExceededLocalFileSystemQuota(false); +} + +void WebPageProxy::replyExceededLocalFileSystemQuota(bool allow) +{ + if (!m_exceededLocalFileSystemQuotaReply) + return; + + m_exceededLocalFileSystemQuotaReply->send(allow); + m_exceededLocalFileSystemQuotaReply = nullptr; +#if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP) + process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(false); +#endif +} +#endif + #endif // #if OS(TIZEN) void WebPageProxy::handleInputMethodKeydown(bool& handled) diff --git a/Source/WebKit2/UIProcess/tizen/WebTizenClient.cpp b/Source/WebKit2/UIProcess/tizen/WebTizenClient.cpp index 3a1fd5b..8bc474c 100644 --- a/Source/WebKit2/UIProcess/tizen/WebTizenClient.cpp +++ b/Source/WebKit2/UIProcess/tizen/WebTizenClient.cpp @@ -86,4 +86,14 @@ bool WebTizenClient::exceededIndexedDatabaseQuota(WebPageProxy* page, WebSecurit return m_client.exceededIndexedDatabaseQuota(toAPI(page), toAPI(origin), currentUsage, toAPI(frame), m_client.clientInfo); } #endif + +#if ENABLE(TIZEN_FILE_SYSTEM) +bool WebTizenClient::exceededLocalFileSystemQuota(WebPageProxy* page, WebSecurityOrigin* origin, long long currentUsage, WebFrameProxy* frame) +{ + if (!m_client.exceededLocalFileSystemQuota) + return currentUsage; + + return m_client.exceededLocalFileSystemQuota(toAPI(page), toAPI(origin), currentUsage, toAPI(frame), m_client.clientInfo); +} +#endif } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/tizen/WebTizenClient.h b/Source/WebKit2/UIProcess/tizen/WebTizenClient.h index c653f00..03afdba 100644 --- a/Source/WebKit2/UIProcess/tizen/WebTizenClient.h +++ b/Source/WebKit2/UIProcess/tizen/WebTizenClient.h @@ -67,6 +67,10 @@ public: #if ENABLE(TIZEN_INDEXED_DATABASE) bool exceededIndexedDatabaseQuota(WebPageProxy*, WebSecurityOrigin*, long long, WebFrameProxy*); #endif + +#if ENABLE(TIZEN_FILE_SYSTEM) + bool exceededLocalFileSystemQuota(WebPageProxy*, WebSecurityOrigin*, long long, WebFrameProxy*); +#endif }; } // namespace WebKit diff --git a/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp b/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp index 6f83af7..bd3f50d 100755 --- a/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp +++ b/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp @@ -1026,4 +1026,22 @@ bool WebChromeClient::exceededIndexedDatabaseQuota(Frame* frame, int64_t current } #endif +#if ENABLE(TIZEN_FILE_SYSTEM) +bool WebChromeClient::exceededLocalFileSystemQuota(Frame* frame, int64_t currentQuota) +{ + WebFrame* webFrame = static_cast(frame->loader()->client())->webFrame(); + SecurityOrigin* origin = frame->document()->securityOrigin(); + + unsigned syncSendFlags = (WebCore::AXObjectCache::accessibilityEnabled()) ? CoreIPC::SpinRunLoopWhileWaitingForReply : 0; + bool result = false; +#if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP) + WebProcess::WaitForJavaScriptPopupFinished waiting; +#endif + if (!WebProcess::shared().connection()->sendSync(Messages::WebPageProxy::ExceededLocalFileSystemQuota(webFrame->frameID(), origin->databaseIdentifier(), currentQuota), Messages::WebPageProxy::ExceededLocalFileSystemQuota::Reply(result), m_page->pageID(), CoreIPC::Connection::DefaultTimeout, syncSendFlags)) + return false; + + return result; +} +#endif + } // namespace WebKit diff --git a/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h b/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h index 77e53d0..876ac46 100755 --- a/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h +++ b/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h @@ -268,6 +268,10 @@ private: virtual bool exceededIndexedDatabaseQuota(Frame*, int64_t) OVERRIDE; #endif +#if ENABLE(TIZEN_FILE_SYSTEM) + virtual bool exceededLocalFileSystemQuota(Frame*, int64_t currentQuota) OVERRIDE; +#endif + String m_cachedToolTip; mutable RefPtr m_cachedFrameSetLargestFrame; mutable bool m_cachedMainFrameHasHorizontalScrollbar; diff --git a/Source/WebKit2/WebProcess/WebPage/WebPage.cpp b/Source/WebKit2/WebProcess/WebPage/WebPage.cpp index 05f5572..f40a1ad 100755 --- a/Source/WebKit2/WebProcess/WebPage/WebPage.cpp +++ b/Source/WebKit2/WebProcess/WebPage/WebPage.cpp @@ -2478,6 +2478,10 @@ void WebPage::updatePreferences(const WebPreferencesStore& store) settings->setTextAutosizingEnabled(store.getBoolValueForKey(WebPreferencesKey::textAutosizingEnabledKey())); #endif +#if ENABLE(TIZEN_FILE_SYSTEM) + m_page->group().groupSettings()->setLocalFileSystemQuotaBytes(0x6400000); //100M +#endif + platformPreferencesDidChange(store); if (m_drawingArea) -- 2.7.4