Tizen 2.1 base
[framework/osp/web.git] / src / controls / FWebCtrl_AppControlListener.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FWebCtrl_AppControlListener.cpp
20  * @brief               The file contains the definition of _AppControlListener classes.
21  *
22  * The file contains the definition of _AppControlListener classes.
23  */
24 #include <EWebKit2.h>
25 #include <FAppAppControl.h>
26 #include <FBaseSysLog.h>
27 #include <FBaseUtilStringTokenizer.h>
28 #include "FWebCtrl_AppControlListener.h"
29
30
31 using namespace Tizen::App;
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::Base::Utility;
35
36 namespace Tizen { namespace Web { namespace Controls
37 {
38
39
40 _CertificateListener::_CertificateListener(void)
41 {
42 }
43
44
45 _CertificateListener::~_CertificateListener(void)
46 {
47 }
48
49
50 void
51 _CertificateListener::OnAppControlCompleteResponseReceived(const Tizen::App::AppId& providerId, const Tizen::Base::String& operationId, Tizen::App::AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pAppData)
52 {
53         if (providerId == L"tizen.certificatemanager" && operationId == L"http://tizen.org/appcontrol/operation/pick")
54         {
55                 SysTryReturnVoidResult(NID_WEB_CTRL, pAppData, E_SYSTEM, "[E_SYSTEM] Certificate Manager AppControl failed");
56
57                 String* pCertID = static_cast< String* >(const_cast< Object* >(pAppData->GetValue(String(L"Id"))));
58                 // TODO : test if the result of Certificate AppControl complies with the following
59                 // const char* pCertificateFile;
60                 // ewk_set_certificate_file(pCertificateFile);
61         }
62
63         delete this;
64 }
65
66
67 _LocationSettingListener::_LocationSettingListener(Ewk_Geolocation_Permission_Data* pGeoLocationObject)
68         : __pGeoLocationObject(pGeoLocationObject)
69 {
70 }
71
72
73 _LocationSettingListener::~_LocationSettingListener(void)
74 {
75 }
76
77
78 void
79 _LocationSettingListener::OnAppControlCompleteResponseReceived(const Tizen::App::AppId& providerId, const Tizen::Base::String& operationId, Tizen::App::AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pAppData)
80 {
81         if (providerId == L"tizen.settings")
82         {
83                 SysTryReturnVoidResult(NID_WEB_CTRL, pAppData, E_SYSTEM, "[E_SYSTEM] Settings AppControl failed");
84
85                 String* pCategoryStr = static_cast< String* >(const_cast< Object* >(pAppData->GetValue(String("category"))));
86                 String* pGPSStr = static_cast< String* >(const_cast< Object* >(pAppData->GetValue(String("GPS"))));
87
88                 Ewk_Geolocation_Permission_Request permistionRequest = ewk_geolocation_permission_request_get(__pGeoLocationObject);
89                 if (pCategoryStr && pCategoryStr->Equals(String(L"Location")) && pGPSStr && pGPSStr->Equals(String(L"GPSEnabled")))
90                 {
91                         ewk_geolocation_permission_request_allow_set(permistionRequest, true);
92                 }
93                 else
94                 {
95                         ewk_geolocation_permission_request_allow_set(permistionRequest, false);
96                 }
97         }
98         delete this;
99 }
100
101
102 _MediaSelectionListener::_MediaSelectionListener(void)
103         : __isSelectionCompleted(false)
104         , __pSelectedFiles(null)
105 {
106
107 }
108
109
110 _MediaSelectionListener::~_MediaSelectionListener(void)
111 {
112
113 }
114
115
116 const ArrayList*
117 _MediaSelectionListener::GetSelectedFiles(void) const
118 {
119         return __pSelectedFiles.get();
120 }
121
122
123 bool
124 _MediaSelectionListener::IsSelectionCompleted(void) const
125 {
126         return __isSelectionCompleted;
127 }
128
129
130 void
131 _MediaSelectionListener::OnAppControlCompleteResponseReceived(const Tizen::App::AppId& providerId, const Tizen::Base::String& operationId, Tizen::App::AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pAppData)
132 {
133         __isSelectionCompleted = true;
134         SysTryReturnVoidResult(NID_WEB_CTRL, pAppData &&  providerId == L"tizen.filemanager" && operationId == L"http://tizen.org/appcontrol/operation/pick", E_INVALID_ARG, "[E_INVALID_ARG] Invalid arguments to _MediaSelectionListener::OnAppControlCompleted");
135
136         std::unique_ptr<ArrayList, AllElementsDeleter> pSelectedFiles(new (std::nothrow) ArrayList());
137         SysTryReturnVoidResult(NID_WEB_CTRL, pSelectedFiles.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
138
139         result r = pSelectedFiles->Construct();
140         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
141
142         String *pFiles = static_cast< String* >(const_cast< Object* >(pAppData->GetValue(String("path"))));
143         SysTryReturnVoidResult(NID_WEB_CTRL, pFiles, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
144
145         StringTokenizer strTok(*pFiles, L";");
146         String token;
147
148         while (strTok.HasMoreTokens())
149         {
150                 strTok.GetNextToken(token);
151                 std::unique_ptr<String> pFile(new (std::nothrow) String(token));
152                 SysTryReturnVoidResult(NID_WEB_CTRL, pFile, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
153
154                 r = pSelectedFiles->Add(*pFile);
155                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
156                 pFile.release();
157         }
158
159         __pSelectedFiles = std::move(pSelectedFiles);
160 }
161
162
163 }}} // Tizen::Web::Controls