upload tizen1.0 source
[platform/framework/web/wrt.git] / src / view / webkit1 / view_logic_password_support.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /**
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
20  */
21 #include "view_logic_password_support.h"
22 #include <string>
23 #include <vconf.h>
24 #include <iri.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>
32
33 namespace ViewModule {
34 namespace PasswordSupport {
35
36 namespace
37 { //anonymous
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";
44 }
45
46 DPL::Optional<AutoSaveDB::AutoSaveData>
47     getAutoFillData(const char *uri)
48 {
49     LogDebug("getAutoFillData called");
50     Assert(uri);
51
52     using namespace AutoSaveDB;
53
54     const char* const autoSaveIDPass =
55         vconf_get_str(AUTOSAVEIDPASS_KEY.c_str());
56     DPL::Optional<AutoSaveData> autoData;
57
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(
62             iri_parse(uri));
63
64         if (iri.Get() && NULL != iri->host) {
65             autoData = AutoSaveDAO::getAutoSaveIdPasswd(
66                 DPL::FromASCIIString(std::string(iri->host)));
67         }
68     }
69     return autoData;
70 }
71
72 void submitClicked(char ** personalData)
73 {
74     LogDebug("submitClicked called");
75     Assert(personalData);
76
77     using namespace AutoSaveDB;
78
79     const char* autoSaveStatus = vconf_get_str(AUTOSAVEIDPASS_KEY.c_str());
80
81     Assert(autoSaveStatus);
82     Assert(personalData[0] && personalData[1] && personalData[2]);
83
84     std::string userId = personalData[0];
85     std::string userPasswd = personalData[1];
86     std::string currentUri = personalData[2];
87
88     if (!strcmp(autoSaveStatus, AUTOSAVEIDPASS_OFF)) {
89         LogDebug("AutoSaveStatus is AUTOSAVEIDPASS_ALWAYS_OFF");
90         return;
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);
100         }
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);
111
112                 if (!userId.compare(tempid) &&
113                         !userPasswd.compare(temppass))
114                 {
115                     return;
116                 }
117             }
118             AutoSaveData saveData;
119             saveData.userId = DPL::FromUTF8String(userId);
120             saveData.passwd = DPL::FromUTF8String(userPasswd);
121
122             DPL::ScopedPtr<AutoSavePopup> autoPopup(new AutoSavePopup);
123             autoPopup->checkAutoSave(host, saveData);
124         }
125     }
126 }
127
128 } // namespaec PasswordSupport
129 } // namespaec ViewModule