2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file view_logic_web_storage_support.cpp
18 * @author Jihoon Chung (jihoon.chung@samsung.com)
21 #include "view_logic_web_storage_support.h"
25 #include <dpl/log/log.h>
26 #include <dpl/assert.h>
27 #include <wrt-commons/security-origin-dao/security_origin_dao_types.h>
28 #include <wrt-commons/security-origin-dao/security_origin_dao.h>
30 #include <common/view_logic_security_origin_support.h>
31 #include <Elementary.h>
33 namespace ViewModule {
35 using namespace SecurityOriginDB;
36 using namespace ViewModule::SecurityOriginSupportUtil;
39 const char* const WEB_STORAGE_CREATE_ASK_BODY_PREFIX = "Do you want to allow ";
40 const char* const WEB_STORAGE_CREATE_ASK_BODY =
42 const char* const WEB_STORAGE_CREATE_ASK_BODY_POSTFIX =
44 const char* const WEB_STORAGE_CREATE_ASK_CHECK = "Don't ask again";
47 void askUserForWebStorageCreatePermission(
49 PermissionData* data);
50 static void popupCallback(void* data, Evas_Object* obj, void* eventInfo);
52 void askUserForWebStorageCreatePermission(
56 LogDebug("askUserForWebStorageCreatePermission called");
57 PermissionData* permData = static_cast<PermissionData*>(data);
58 Ewk_Context_Exceeded_Quota* exceededQuota =
59 static_cast<Ewk_Context_Exceeded_Quota*>(permData->m_data);
61 std::ostringstream size;
62 size << ewk_context_web_database_exceeded_quota_expected_usage_get(exceededQuota) /
66 WEB_STORAGE_CREATE_ASK_BODY_PREFIX +
67 DPL::ToUTF8String(data->m_originData.origin.host) +
68 WEB_STORAGE_CREATE_ASK_BODY +
70 WEB_STORAGE_CREATE_ASK_BODY_POSTFIX;
72 Evas_Object* popup = createPopup(window,
74 WEB_STORAGE_CREATE_ASK_CHECK,
79 LogError("Fail to create popup object");
83 evas_object_show(popup);
87 void popupCallback(void* data, Evas_Object* obj, void* /*eventInfo*/)
89 LogDebug("popupCallback");
91 PermissionData* permData = static_cast<PermissionData*>(data);
92 Ewk_Context_Exceeded_Quota* exceededQuota =
93 static_cast<Ewk_Context_Exceeded_Quota*>(permData->m_data);
95 Evas_Object* popup = getPopup(obj);
96 Result result = getResult(obj);
98 if (result != RESULT_UNKNOWN) {
99 permData->m_originDao->setSecurityOriginData(permData->m_originData, result);
101 if (result == RESULT_ALLOW_ALWAYS || result == RESULT_ALLOW_ONCE) {
102 ewk_context_web_database_exceeded_quota_new_quota_set(
104 ewk_context_web_database_exceeded_quota_expected_usage_get(
106 10*(1024*1024)); //10MB
110 evas_object_hide(popup);
111 evas_object_del(popup);
115 void WebStorageSupport::webStorageCreatePermissionRequest(
117 SecurityOriginDAO* securityOriginDAO,
120 LogDebug("webStorageCreatePermissionRequest called");
121 Assert(securityOriginDAO);
123 Ewk_Context_Exceeded_Quota* exceededQuota =
124 static_cast<Ewk_Context_Exceeded_Quota*>(data);
125 Ewk_Security_Origin* ewkOrigin =
126 ewk_context_web_database_exceeded_quota_security_origin_get(
130 SecurityOriginData securityOriginData(
131 FEATURE_WEB_DATABASE,
133 DPL::FromUTF8String(ewk_security_origin_protocol_get(ewkOrigin)),
134 DPL::FromUTF8String(ewk_security_origin_host_get(ewkOrigin)),
135 ewk_security_origin_port_get(ewkOrigin)));
137 // check cache database
138 Result result = securityOriginDAO->getResult(securityOriginData);
139 if (RESULT_ALLOW_ONCE == result || RESULT_ALLOW_ALWAYS == result) {
141 ewk_context_web_database_exceeded_quota_new_quota_set(
143 ewk_context_web_database_exceeded_quota_expected_usage_get(
145 10*(1024*1024)); //10MB
147 } else if (RESULT_DENY_ONCE == result || RESULT_DENY_ALWAYS == result) {
153 PermissionData* permissionData =
154 new PermissionData(securityOriginDAO,
157 askUserForWebStorageCreatePermission(window, permissionData);
160 } // namespace ViewModule