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_password_support.cpp
18 * @author Pawel Sikorski (p.sikorski@samsung.com)
19 * @brief Implementation file of PasswordSupport API used by ViewLogic
21 #include "view_logic_password_support.h"
25 #include <dpl/assert.h>
26 #include <dpl/log/log.h>
27 #include <dpl/scoped_ptr.h>
28 #include <dpl/string.h>
29 #include <dpl/optional.h>
30 #include <AutoSavePopup.h>
31 #include <wrt-commons/auto-save-dao-rw/auto_save_dao.h>
33 namespace ViewModule {
34 namespace PasswordSupport {
38 const char *AUTOSAVEIDPASS_OFF = "Off";
39 const char *AUTOSAVEIDPASS_ON = "On";
40 const char *AUTOSAVEIDPASS_ALWAYS_ASK = "Always ask";
41 const std::string SETTING_VCONF_PREFIX = "db/browsersetting/";
42 const std::string AUTOSAVEIDPASS_KEY =
43 SETTING_VCONF_PREFIX + "AutoSaveIDPassword";
46 DPL::Optional<AutoSaveDB::AutoSaveData>
47 getAutoFillData(const char *uri)
49 LogDebug("getAutoFillData called");
52 using namespace AutoSaveDB;
54 const char* const autoSaveIDPass =
55 vconf_get_str(AUTOSAVEIDPASS_KEY.c_str());
56 DPL::Optional<AutoSaveData> autoData;
58 if (NULL == autoSaveIDPass) {
59 LogDebug("Did not find vconf about AUTOSAVEIDPASS_KEY ");
60 } else if (strcmp(autoSaveIDPass, AUTOSAVEIDPASS_OFF)) {
61 DPL::ScopedPtr<iri_t> iri(
64 if (iri.Get() && NULL != iri->host) {
65 autoData = AutoSaveDAO::getAutoSaveIdPasswd(
66 DPL::FromASCIIString(std::string(iri->host)));
72 void submitClicked(char ** personalData)
74 LogDebug("submitClicked called");
77 using namespace AutoSaveDB;
79 const char* autoSaveStatus = vconf_get_str(AUTOSAVEIDPASS_KEY.c_str());
81 Assert(autoSaveStatus);
82 Assert(personalData[0] && personalData[1] && personalData[2]);
84 std::string userId = personalData[0];
85 std::string userPasswd = personalData[1];
86 std::string currentUri = personalData[2];
88 if (!strcmp(autoSaveStatus, AUTOSAVEIDPASS_OFF)) {
89 LogDebug("AutoSaveStatus is AUTOSAVEIDPASS_ALWAYS_OFF");
91 } else if (!strcmp(autoSaveStatus, AUTOSAVEIDPASS_ON)) {
92 LogDebug("AutoSaveStatus is AUTOSAVEIDPASS_ALWAYS_ON");
93 AutoSaveData saveData;
94 saveData.userId = DPL::FromUTF8String(userId);
95 saveData.passwd = DPL::FromUTF8String(userPasswd);
96 DPL::ScopedPtr<iri_t> iri(iri_parse(currentUri.c_str()));
97 if (iri.Get() && NULL != iri->host) {
98 AutoSaveDAO::setAutoSaveIdPasswd(
99 DPL::FromASCIIString(std::string(iri->host)), saveData);
101 } else if (!strcmp(autoSaveStatus, AUTOSAVEIDPASS_ALWAYS_ASK)) {
102 LogDebug("AutoSaveStatus is AUTOSAVEIDPASS_ALWAYS_ASK");
103 DPL::Optional<AutoSaveData> autoData;
104 DPL::ScopedPtr<iri_t> iri(iri_parse(currentUri.c_str()));
105 if (iri.Get() && NULL != iri->host) {
106 DPL::String host = DPL::FromASCIIString(std::string(iri->host));
107 autoData = AutoSaveDAO::getAutoSaveIdPasswd(host);
108 if (!autoData.IsNull()) {
109 std::string tempid = DPL::ToUTF8String(autoData->userId);
110 std::string temppass = DPL::ToUTF8String(autoData->passwd);
112 if (!userId.compare(tempid) &&
113 !userPasswd.compare(temppass))
118 AutoSaveData saveData;
119 saveData.userId = DPL::FromUTF8String(userId);
120 saveData.passwd = DPL::FromUTF8String(userPasswd);
122 DPL::ScopedPtr<AutoSavePopup> autoPopup(new AutoSavePopup);
123 autoPopup->checkAutoSave(host, saveData);
128 } // namespaec PasswordSupport
129 } // namespaec ViewModule