#include <dali/devel-api/adaptor-framework/web-engine-load-error.h>
#include <dali/devel-api/adaptor-framework/web-engine-policy-decision.h>
#include <dali/devel-api/adaptor-framework/web-engine-request-interceptor.h>
+#include <dali/devel-api/adaptor-framework/web-engine-security-origin.h>
#include <dali/devel-api/adaptor-framework/web-engine-settings.h>
#include <dali/public-api/adaptor-framework/native-image-source.h>
#include <dali/public-api/images/pixel-data.h>
{
class WebEngine;
+class MockWebEngineContext;
namespace
{
// Generally only one WebEngine instance exists.
// If > 1, a new web engine has been created by CreateWindowSignal.
-static WebEngine* gInstance = 0;
+static WebEngine* gInstance = nullptr;
static int gInstanceCount = 0;
+static MockWebEngineContext* gWebEngineContextInstance = nullptr;
bool OnGoBack();
bool OnGoForward();
bool OnVideoPlaying();
bool OnGeolocationPermission();
bool OnClearHistory();
+bool OnSecurityOriginAcquired();
+bool OnStorageUsageAcquired();
+bool OnFormPasswordAcquired();
+bool OnDownloadStarted();
+bool OnMimeOverridden();
static void ConnectToGlobalSignal( bool ( *func )() )
{
{
}
- void DeleteWebDatabase() override
+ void DeleteAllWebDatabase() override
{
}
- void DeleteWebStorage() override
+ bool GetWebDatabaseOrigins(Dali::WebEngineContext::WebEngineSecurityOriginAcquiredCallback callback)
{
+ if (callback)
+ {
+ ConnectToGlobalSignal(&OnSecurityOriginAcquired);
+ mSecurityOriginAcquiredCallback = callback;
+ }
+ return true;
+ }
+
+ bool DeleteWebDatabase(Dali::WebEngineSecurityOrigin& origin)
+ {
+ return true;
+ }
+
+ bool GetWebStorageOrigins(Dali::WebEngineContext::WebEngineSecurityOriginAcquiredCallback callback)
+ {
+ if (callback)
+ {
+ ConnectToGlobalSignal(&OnSecurityOriginAcquired);
+ mSecurityOriginAcquiredCallback = callback;
+ }
+ return true;
+ }
+
+ bool GetWebStorageUsageForOrigin(Dali::WebEngineSecurityOrigin& origin, Dali::WebEngineContext::WebEngineStorageUsageAcquiredCallback callback)
+ {
+ if (callback)
+ {
+ ConnectToGlobalSignal(&OnStorageUsageAcquired);
+ mStorageUsageAcquiredCallback = callback;
+ }
+ return true;
+ }
+
+ void DeleteAllWebStorage() override
+ {
+ }
+
+ bool DeleteWebStorageOrigin(Dali::WebEngineSecurityOrigin& origin)
+ {
+ return true;
}
void DeleteLocalFileSystem() override
{
}
+ bool DeleteApplicationCache(Dali::WebEngineSecurityOrigin& origin)
+ {
+ return true;
+ }
+
+ void GetFormPasswordList(Dali::WebEngineContext::WebEngineFormPasswordAcquiredCallback callback)
+ {
+ if (callback)
+ {
+ ConnectToGlobalSignal(&OnFormPasswordAcquired);
+ mFormPasswordAcquiredCallback = callback;
+ }
+ }
+
+ void RegisterDownloadStartedCallback(Dali::WebEngineContext::WebEngineDownloadStartedCallback callback)
+ {
+ if (callback)
+ {
+ ConnectToGlobalSignal(&OnDownloadStarted);
+ mDownloadStartedCallback = callback;
+ }
+ }
+
+ void RegisterMimeOverriddenCallback(Dali::WebEngineContext::WebEngineMimeOverriddenCallback callback)
+ {
+ if (callback)
+ {
+ ConnectToGlobalSignal(&OnMimeOverridden);
+ mMimeOverriddenCallback = callback;
+ }
+ }
+
+public:
+ Dali::WebEngineContext::WebEngineSecurityOriginAcquiredCallback mSecurityOriginAcquiredCallback;
+ Dali::WebEngineContext::WebEngineStorageUsageAcquiredCallback mStorageUsageAcquiredCallback;
+ Dali::WebEngineContext::WebEngineFormPasswordAcquiredCallback mFormPasswordAcquiredCallback;
+ Dali::WebEngineContext::WebEngineDownloadStartedCallback mDownloadStartedCallback;
+ Dali::WebEngineContext::WebEngineMimeOverriddenCallback mMimeOverriddenCallback;
+
private:
Dali::WebEngineContext::CacheModel mockModel;
};
+class MockWebEngineSecurityOrigin : public Dali::WebEngineSecurityOrigin
+{
+public:
+ MockWebEngineSecurityOrigin()
+ : mockUrl("https://test.html")
+ , mockPotocol("https")
+ {
+ }
+
+ std::string GetHost() const
+ {
+ return mockUrl;
+ }
+
+ std::string GetProtocol() const
+ {
+ return mockPotocol;
+ }
+
+private:
+ std::string mockUrl;
+ std::string mockPotocol;
+};
+
class MockWebEngineCookieManager : public Dali::WebEngineCookieManager
{
public:
}
mockWebEngineSettings = new MockWebEngineSettings();
- mockWebEngineContext = new MockWebEngineContext();
+ MockWebEngineContext* engineContext = new MockWebEngineContext();
+ mockWebEngineContext = engineContext;
+ if ( gInstanceCount == 1 )
+ {
+ gWebEngineContextInstance = engineContext;
+ }
mockWebEngineCookieManager = new MockWebEngineCookieManager();
mockWebEngineBackForwardList = new MockWebEngineBackForwardList();
}
if( !gInstanceCount )
{
gInstance = 0;
+ gWebEngineContextInstance = 0;
}
delete mockWebEngineSettings;
return false;
}
+bool OnSecurityOriginAcquired()
+{
+ DisconnectFromGlobalSignal(&OnSecurityOriginAcquired);
+ if (gWebEngineContextInstance)
+ {
+ std::vector<std::unique_ptr<Dali::WebEngineSecurityOrigin>> securityOriginList;
+ std::unique_ptr<Dali::WebEngineSecurityOrigin> origin(new MockWebEngineSecurityOrigin());
+ securityOriginList.push_back(std::move(origin));
+ gWebEngineContextInstance->mSecurityOriginAcquiredCallback(securityOriginList);
+ }
+ return false;
+}
+
+bool OnStorageUsageAcquired()
+{
+ DisconnectFromGlobalSignal(&OnStorageUsageAcquired);
+ if (gWebEngineContextInstance)
+ {
+ gWebEngineContextInstance->mStorageUsageAcquiredCallback(0);
+ }
+ return false;
+}
+
+bool OnFormPasswordAcquired()
+{
+ DisconnectFromGlobalSignal(&OnFormPasswordAcquired);
+ if (gWebEngineContextInstance)
+ {
+ std::vector<std::unique_ptr<Dali::WebEngineContext::PasswordData>> formPasswordList;
+ std::unique_ptr<Dali::WebEngineContext::PasswordData> data(new Dali::WebEngineContext::PasswordData());
+ data->url = "http://test.html";
+ data->useFingerprint = false;
+ formPasswordList.push_back(std::move(data));
+ gWebEngineContextInstance->mFormPasswordAcquiredCallback(formPasswordList);
+ }
+ return false;
+}
+
+bool OnDownloadStarted()
+{
+ DisconnectFromGlobalSignal(&OnDownloadStarted);
+ if (gWebEngineContextInstance)
+ {
+ gWebEngineContextInstance->mDownloadStartedCallback("http://test.html");
+ }
+ return false;
+}
+
+bool OnMimeOverridden()
+{
+ DisconnectFromGlobalSignal(&OnMimeOverridden);
+ if (gWebEngineContextInstance)
+ {
+ std::string newMime;
+ gWebEngineContextInstance->mMimeOverriddenCallback("http://test.html", "txt/xml", newMime);
+ }
+ return false;
+}
+
} // namespace
inline WebEngine& GetImplementation( Dali::WebEngine& webEngine )
#include <dali/devel-api/adaptor-framework/web-engine-load-error.h>
#include <dali/devel-api/adaptor-framework/web-engine-policy-decision.h>
#include <dali/devel-api/adaptor-framework/web-engine-request-interceptor.h>
+#include <dali/devel-api/adaptor-framework/web-engine-context.h>
+#include <dali/devel-api/adaptor-framework/web-engine-security-origin.h>
#include <dali/integration-api/events/hover-event-integ.h>
#include <dali/integration-api/events/key-event-integ.h>
#include <dali/integration-api/events/touch-event-integ.h>
static std::shared_ptr<Dali::WebEngineCertificate> gSslCertificateInstance = nullptr;
static int gHttpAuthHandlerCallbackCalled = 0;
static std::shared_ptr<Dali::WebEngineHttpAuthHandler> gHttpAuthInstance = nullptr;
+static int gSecurityOriginsAcquiredCallbackCalled = 0;
+static int gStorageUsageAcquiredCallbackCalled = 0;
+static int gFormPasswordsAcquiredCallbackCalled = 0;
+static int gDownloadStartedCallbackCalled = 0;
+static int gMimeOverriddenCallbackCalled = 0;
+static std::vector<std::unique_ptr<Dali::WebEngineSecurityOrigin>> gSecurityOriginList;
+static std::vector<std::unique_ptr<Dali::WebEngineContext::PasswordData>> gPasswordDataList;
struct CallbackFunctor
{
static void OnScreenshotCaptured(Dali::Toolkit::ImageView)
{
- gScreenshotCapturedCallbackCalled++;\r
+ gScreenshotCapturedCallbackCalled++;
}
static void OnVideoPlaying(bool isPlaying)
gHttpAuthInstance = std::move(hander);
}
+static void OnSecurityOriginsAcquired(std::vector<std::unique_ptr<Dali::WebEngineSecurityOrigin>>& origins)
+{
+ gSecurityOriginsAcquiredCallbackCalled++;
+ gSecurityOriginList.clear();
+ gSecurityOriginList.swap(origins);
+}
+
+static void OnStorageUsageAcquired(uint64_t usage)
+{
+ gStorageUsageAcquiredCallbackCalled++;
+}
+
+static void OnFormPasswordsAcquired(std::vector<std::unique_ptr<Dali::WebEngineContext::PasswordData>>& passwords)
+{
+ gFormPasswordsAcquiredCallbackCalled++;
+ gPasswordDataList.clear();
+ gPasswordDataList.swap(passwords);
+}
+
+static void OnDownloadStarted(const std::string& url)
+{
+ gDownloadStartedCallbackCalled++;
+}
+
+static bool OnMimeOverridden(const std::string&, const std::string&, std::string&)
+{
+ gMimeOverriddenCallbackCalled++;
+ return false;
+}
+
} // namespace
void web_view_startup(void)
context->SetCertificateFilePath( kDefaultValue );
context->DisableCache( false );
context->SetDefaultProxyAuth( kDefaultValue, kDefaultValue );
- context->DeleteWebDatabase();
- context->DeleteWebStorage();
+ context->DeleteAllWebDatabase();
+ context->DeleteAllWebStorage();
context->DeleteLocalFileSystem();
context->ClearCache();
END_TEST;
}
+int UtcDaliWebContextGetWebDatabaseStorageOrigins(void)
+{
+ ToolkitTestApplication application;
+
+ WebView view = WebView::New();
+ DALI_TEST_CHECK( view );
+
+ Dali::Toolkit::WebContext* context = view.GetContext();
+ DALI_TEST_CHECK( context != 0 )
+
+ std::string kDefaultValue;
+
+ // get origins of web database
+ bool result = context->GetWebDatabaseOrigins(&OnSecurityOriginsAcquired);
+ DALI_TEST_CHECK( result );
+
+ Test::EmitGlobalTimerSignal();
+ DALI_TEST_EQUALS( gSecurityOriginsAcquiredCallbackCalled, 1, TEST_LOCATION );
+ DALI_TEST_CHECK(gSecurityOriginList.size() == 1);
+
+ Dali::WebEngineSecurityOrigin* origin = gSecurityOriginList[0].get();
+ DALI_TEST_CHECK( origin );
+
+ result = context->DeleteWebDatabase(*origin);
+ DALI_TEST_CHECK( result );
+
+ // get origins of web storage
+ result = context->GetWebStorageOrigins(&OnSecurityOriginsAcquired);
+ DALI_TEST_CHECK( result );
+
+ Test::EmitGlobalTimerSignal();
+ DALI_TEST_EQUALS( gSecurityOriginsAcquiredCallbackCalled, 2, TEST_LOCATION );
+ DALI_TEST_CHECK(gSecurityOriginList.size() == 1);
+
+ origin = gSecurityOriginList[0].get();
+ DALI_TEST_CHECK( origin );
+
+ result = context->GetWebStorageUsageForOrigin(*origin, &OnStorageUsageAcquired);
+ DALI_TEST_CHECK( result );
+ Test::EmitGlobalTimerSignal();
+ DALI_TEST_EQUALS( gStorageUsageAcquiredCallbackCalled, 1, TEST_LOCATION );
+
+ result = context->DeleteWebStorageOrigin(*origin);
+ DALI_TEST_CHECK( result );
+
+ result = context->DeleteApplicationCache(*origin);
+ DALI_TEST_CHECK( result );
+
+ // form passwords, download state, mime type.
+ context->GetFormPasswordList(&OnFormPasswordsAcquired);
+ Test::EmitGlobalTimerSignal();
+ DALI_TEST_EQUALS(gFormPasswordsAcquiredCallbackCalled, 1, TEST_LOCATION);
+ DALI_TEST_CHECK(gPasswordDataList.size() == 1);
+ DALI_TEST_EQUALS(gPasswordDataList[0]->url, "http://test.html", TEST_LOCATION);
+ DALI_TEST_CHECK(gPasswordDataList[0]->useFingerprint == false);
+
+ context->RegisterDownloadStartedCallback(&OnDownloadStarted);
+ Test::EmitGlobalTimerSignal();
+ DALI_TEST_EQUALS(gDownloadStartedCallbackCalled, 1, TEST_LOCATION);
+
+ context->RegisterMimeOverriddenCallback(&OnMimeOverridden);
+ Test::EmitGlobalTimerSignal();
+ DALI_TEST_EQUALS(gMimeOverriddenCallbackCalled, 1, TEST_LOCATION);
+
+ gSecurityOriginList.clear();
+ gPasswordDataList.clear();
+
+ END_TEST;
+}
+
// test cases for web cookie manager.
int UtcDaliWebCookieManagerGetSetCookieAcceptPolicy(void)
// CLASS HEADER
#include <dali-toolkit/devel-api/controls/web-view/web-context.h>
+// EXTERNAL INCLUDES
+#include <dali/devel-api/adaptor-framework/web-engine-security-origin.h>
+
namespace Dali
{
namespace Toolkit
mWebEngineContext.SetDefaultProxyAuth(username, password);
}
-void WebContext::DeleteWebDatabase()
+void WebContext::DeleteAllWebDatabase()
+{
+ mWebEngineContext.DeleteAllWebDatabase();
+}
+
+bool WebContext::GetWebDatabaseOrigins(Dali::WebEngineContext::WebEngineSecurityOriginAcquiredCallback callback)
{
- mWebEngineContext.DeleteWebDatabase();
+ return mWebEngineContext.GetWebDatabaseOrigins(callback);
}
-void WebContext::DeleteWebStorage()
+bool WebContext::DeleteWebDatabase(Dali::WebEngineSecurityOrigin& origin)
{
- mWebEngineContext.DeleteWebStorage();
+ return mWebEngineContext.DeleteWebDatabase(origin);
+}
+
+bool WebContext::GetWebStorageOrigins(Dali::WebEngineContext::WebEngineSecurityOriginAcquiredCallback callback)
+{
+ return mWebEngineContext.GetWebStorageOrigins(callback);
+}
+
+bool WebContext::GetWebStorageUsageForOrigin(Dali::WebEngineSecurityOrigin& origin, Dali::WebEngineContext::WebEngineStorageUsageAcquiredCallback callback)
+{
+ return mWebEngineContext.GetWebStorageUsageForOrigin(origin, callback);
+}
+
+void WebContext::DeleteAllWebStorage()
+{
+ mWebEngineContext.DeleteAllWebStorage();
+}
+
+bool WebContext::DeleteWebStorageOrigin(Dali::WebEngineSecurityOrigin& origin)
+{
+ return mWebEngineContext.DeleteWebStorageOrigin(origin);
}
void WebContext::DeleteLocalFileSystem()
mWebEngineContext.ClearCache();
}
-} // namespace Toolkit
+bool WebContext::DeleteApplicationCache(Dali::WebEngineSecurityOrigin& origin)
+{
+ return mWebEngineContext.DeleteApplicationCache(origin);
+}
+
+void WebContext::GetFormPasswordList(Dali::WebEngineContext::WebEngineFormPasswordAcquiredCallback callback)
+{
+ mWebEngineContext.GetFormPasswordList(callback);
+}
+void WebContext::RegisterDownloadStartedCallback(Dali::WebEngineContext::WebEngineDownloadStartedCallback callback)
+{
+ mWebEngineContext.RegisterDownloadStartedCallback(callback);
+}
+
+void WebContext::RegisterMimeOverriddenCallback(Dali::WebEngineContext::WebEngineMimeOverriddenCallback callback)
+{
+ mWebEngineContext.RegisterMimeOverriddenCallback(callback);
+}
+
+} // namespace Toolkit
} // namespace Dali
namespace Dali
{
+class WebEngineSecurityOrigin;
+
namespace Toolkit
{
/**
*/
/**
- * @brief WebContext is a control for settings of WebView.
+ * @brief WebContext is a control for context of WebView.
*
- * For working WebContext, a WebView should be provided.
+ * For working WebContext, a WebEngineContext should be provided.
*
*/
class DALI_TOOLKIT_API WebContext
{
public:
/**
- * @brief Creates a WebContext.
+ * @brief Create a WebContext.
*
* @param[in] context The context of web engine.
*/
virtual ~WebContext() final;
/**
- * @brief Returns the cache model type.
+ * @brief Return the cache model type.
*
* @return #Dali::WebEngineContext::CacheModel
*/
Dali::WebEngineContext::CacheModel GetCacheModel() const;
/**
- * @brief Requests to set the cache model.
+ * @brief Request to set the cache model.
*
* @param[in] cacheModel The cache model
*/
void SetCacheModel(Dali::WebEngineContext::CacheModel cacheModel);
/**
- * @brief Sets the given proxy URI to network backend of specific context.
+ * @brief Set the given proxy URI to network backend of specific context.
*
* @param[in] uri The proxy URI to set
*/
void SetProxyUri(const std::string& uri);
/**
- * Adds CA certificates to persistent NSS certificate database
+ * @brief Add CA certificates to persistent NSS certificate database
*
* Function accepts a path to a CA certificate file, a path to a directory
* containing CA certificate files, or a colon-seprarated list of those.
void SetCertificateFilePath(const std::string& certificatePath);
/**
- * Toggles the cache to be enabled or disabled
+ * @brief Toggle the cache to be enabled or disabled
*
* Function works asynchronously.
* By default the cache is disabled resulting in not storing network data on disk.
void DisableCache(bool cacheDisabled);
/**
- * @brief Sets a proxy auth credential to network backend of specific context.
+ * @brief Set a proxy auth credential to network backend of specific context.
*
* @param[in] username username to set
* @param[in] password password to set
void SetDefaultProxyAuth(const std::string& username, const std::string& password);
/**
- * Requests for deleting all web databases.
+ * @brief Requests for deleting all web databases.
+ */
+ void DeleteAllWebDatabase();
+
+ /**
+ * @brief Request for getting web database origins.
+ *
+ * @param[in] callback callback called after getting web database origins
+ *
+ * @return true if succeeded, false otherwise
+ */
+ bool GetWebDatabaseOrigins(Dali::WebEngineContext::WebEngineSecurityOriginAcquiredCallback callback);
+
+ /**
+ * @brief Request for deleting web databases for origin.
+ *
+ * @param[in] origin database origin
+ *
+ * @return true if succeeded, false otherwise
+ */
+ bool DeleteWebDatabase(Dali::WebEngineSecurityOrigin& origin);
+
+ /**
+ * @brief Gets list of origins that is stored in web storage db.
+ *
+ * @param[in] callback callback called after getting web storage origins
+ *
+ * @return true if succeeded, false otherwise
*/
- void DeleteWebDatabase();
+ bool GetWebStorageOrigins(Dali::WebEngineContext::WebEngineSecurityOriginAcquiredCallback callback);
/**
- * @brief Deletes web storage.
+ * @brief Get list of origins that is stored in web storage db.
+ *
+ * @param[in] origin storage origin
+ * @param[in] callback callback called after getting web storage origins
+ *
+ * @return true if succeeded, false otherwise
+ */
+ bool GetWebStorageUsageForOrigin(Dali::WebEngineSecurityOrigin& origin, Dali::WebEngineContext::WebEngineStorageUsageAcquiredCallback callback);
+
+ /**
+ * @brief Delete all web storage.
*
* @details This function does not ensure that all data will be removed.
* Should be used to extend free physical memory.
*/
- void DeleteWebStorage();
+ void DeleteAllWebStorage();
/**
- * @brief Requests for deleting all local file systems.
+ * @brief Delete origin that is stored in web storage db.
+ *
+ * @param[in] origin origin of db
+ *
+ * @return true if succeeded, false otherwise
+ */
+ bool DeleteWebStorageOrigin(Dali::WebEngineSecurityOrigin& origin);
+
+ /**
+ * @brief Request for deleting all local file systems.
*/
void DeleteLocalFileSystem();
*/
void ClearCache();
+ /**
+ * @brief Request for deleting web application cache for origin.
+ *
+ * @param[in] origin application cache origin
+ *
+ * @return true if succeeded, false otherwise
+ */
+ bool DeleteApplicationCache(Dali::WebEngineSecurityOrigin& origin);
+
+ /**
+ * @brief Asynchronous request to get list of all password data.
+ *
+ * @param[in] callback callback called after getting form password
+ */
+ void GetFormPasswordList(Dali::WebEngineContext::WebEngineFormPasswordAcquiredCallback callback);
+
+ /**
+ * @brief Register callback for download started.
+ *
+ * @param[in] callback callback for download started
+ */
+ void RegisterDownloadStartedCallback(Dali::WebEngineContext::WebEngineDownloadStartedCallback callback);
+
+ /**
+ * @brief Register callback for mime overridden.
+ *
+ * @param[in] callback callback for mime overridden
+ */
+ void RegisterMimeOverriddenCallback(Dali::WebEngineContext::WebEngineMimeOverriddenCallback callback);
+
private:
Dali::WebEngineContext& mWebEngineContext;
};