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>
32 #include <widget_string.h>
34 namespace ViewModule {
35 using namespace SecurityOriginDB;
36 using namespace ViewModule::SecurityOriginSupportUtil;
39 struct WebStoragePermissionData {
40 WebStorageSupport::ewkQuotaReply m_replyEAPI;
41 Evas_Object* m_ewkView;
42 WebStoragePermissionData(WebStorageSupport::ewkQuotaReply replyEAPI,
43 Evas_Object* ewkView) :
44 m_replyEAPI(replyEAPI),
49 const char* const WEB_STORAGE_CREATE_ASK_BODY_PREFIX = "Do you want to allow ";
50 const char* const WEB_STORAGE_CREATE_ASK_BODY =
52 const char* const WEB_STORAGE_CREATE_ASK_BODY_POSTFIX =
56 void askUserForWebStorageCreatePermission(
58 unsigned long long expectedQuota,
59 PermissionData* data);
60 static void popupCallback(void* data, Evas_Object* obj, void* eventInfo);
62 void askUserForWebStorageCreatePermission(
64 unsigned long long expectedQuota,
67 LogDebug("askUserForWebStorageCreatePermission called");
68 std::ostringstream size;
69 size << expectedQuota / (1024 * 1024);
72 WEB_STORAGE_CREATE_ASK_BODY_PREFIX +
73 DPL::ToUTF8String(data->m_originData.origin.host) +
74 WEB_STORAGE_CREATE_ASK_BODY +
76 WEB_STORAGE_CREATE_ASK_BODY_POSTFIX;
78 Evas_Object* popup = createPopup(window,
80 WRT_BODY_REMEMBER_PREFERENCE,
85 LogError("Fail to create popup object");
89 evas_object_show(popup);
93 void popupCallback(void* data, Evas_Object* obj, void* /*eventInfo*/)
95 LogDebug("popupCallback");
97 PermissionData* permData = static_cast<PermissionData*>(data);
98 WebStoragePermissionData* webStoragePermissionData =
99 static_cast<WebStoragePermissionData*>(permData->m_data);
100 Evas_Object* ewkView =
101 static_cast<Evas_Object*>(webStoragePermissionData->m_ewkView);
103 Evas_Object* popup = getPopup(obj);
104 Result result = getResult(obj);
106 if (result != RESULT_UNKNOWN) {
107 permData->m_originDao->setSecurityOriginData(permData->m_originData,
111 (result == RESULT_ALLOW_ALWAYS || result == RESULT_ALLOW_ONCE) ?
112 EINA_TRUE : EINA_FALSE;
113 webStoragePermissionData->m_replyEAPI(ewkView, ret);
115 delete webStoragePermissionData;
117 evas_object_hide(popup);
118 evas_object_del(popup);
122 void WebStorageSupport::createPermissionRequest(
124 SecurityOriginDB::SecurityOriginDAO* securityOriginDAO,
125 Evas_Object* ewkView,
126 Ewk_Security_Origin* ewkOrigin,
127 unsigned long long expectedQuota,
128 ewkQuotaReply replyEAPI)
130 LogDebug("createPermissionRequest called");
131 Assert(securityOriginDAO);
134 SecurityOriginData securityOriginData(
135 WrtDB::FEATURE_WEB_DATABASE,
137 DPL::FromUTF8String(ewk_security_origin_protocol_get(ewkOrigin)),
138 DPL::FromUTF8String(ewk_security_origin_host_get(ewkOrigin)),
139 ewk_security_origin_port_get(ewkOrigin)));
141 // check cache database
142 Result result = securityOriginDAO->getResult(securityOriginData);
143 if (result != RESULT_UNKNOWN) {
145 (result == RESULT_ALLOW_ALWAYS || result == RESULT_ALLOW_ONCE) ?
146 EINA_TRUE : EINA_FALSE;
147 replyEAPI(ewkView, ret);
152 WebStoragePermissionData* webStoragePermissionData =
153 new WebStoragePermissionData(replyEAPI, ewkView);
154 PermissionData* permissionData =
155 new PermissionData(securityOriginDAO,
157 webStoragePermissionData);
158 askUserForWebStorageCreatePermission(window,
163 } // namespace ViewModule