Fix for lockup
[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 <FAppAppControl.h>
25 #include <FBaseSysLog.h>
26 #include <FBaseUtilStringUtil.h>
27 #include "FWebCtrl_AppControlListener.h"
28
29
30 using namespace Tizen::App;
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33 using namespace Tizen::Base::Utility;
34
35 namespace Tizen { namespace Web { namespace Controls
36 {
37
38
39 _CertificateListener::_CertificateListener(void)
40 {
41 }
42
43
44 _CertificateListener::~_CertificateListener(void)
45 {
46 }
47
48
49 void
50 _CertificateListener::OnAppControlCompleteResponseReceived(const Tizen::App::AppId& providerId, const Tizen::Base::String& operationId, Tizen::App::AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pAppData)
51 {
52         if (providerId == L"tizen.certificatemanager" && operationId == L"http://tizen.org/appcontrol/operation/pick")
53         {
54                 SysTryReturnVoidResult(NID_WEB_CTRL, pAppData, E_SYSTEM, "[E_SYSTEM] Certificate Manager AppControl failed");
55
56                 //String* pCertID = static_cast< String* >(const_cast< Object* >(pAppData->GetValue(String(L"Id"))));
57                 // TODO : test if the result of Certificate AppControl complies with the following
58                 // const char* pCertificateFile;
59                 // ewk_set_certificate_file(pCertificateFile);
60         }
61
62         delete this;
63 }
64
65
66 _LocationSettingListener::_LocationSettingListener(Ewk_Geolocation_Permission_Request* pGeoLocationObject)
67         : __pGeoLocationObject(pGeoLocationObject)
68 {
69 }
70
71
72 _LocationSettingListener::~_LocationSettingListener(void)
73 {
74 }
75
76
77 void
78 _LocationSettingListener::OnAppControlCompleteResponseReceived(const Tizen::App::AppId& providerId, const Tizen::Base::String& operationId, Tizen::App::AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pAppData)
79 {
80         if (providerId == L"tizen.settings")
81         {
82                 SysTryReturnVoidResult(NID_WEB_CTRL, pAppData, E_SYSTEM, "[E_SYSTEM] Settings AppControl failed");
83
84                 String* pCategoryStr = static_cast< String* >(const_cast< Object* >(pAppData->GetValue(String("category"))));
85                 String* pGPSStr = static_cast< String* >(const_cast< Object* >(pAppData->GetValue(String("GPS"))));
86
87                 if (pCategoryStr && pCategoryStr->Equals(String(L"Location")) && pGPSStr && pGPSStr->Equals(String(L"GPSEnabled")))
88                 {
89                         ewk_geolocation_permission_request_set(__pGeoLocationObject, true);
90                 }
91                 else
92                 {
93                         ewk_geolocation_permission_request_set(__pGeoLocationObject, false);
94                 }
95         }
96         delete this;
97 }
98
99
100 _MediaSelectionListener::_MediaSelectionListener(void)
101         : __pWebFrame(null)
102         , __pMediaAppControl(null)
103 {
104
105 }
106
107 void
108 _MediaSelectionListener::Construct(Evas_Object* pWebFrame, Tizen::App::AppControl* pMediaAppControl)
109 {
110         __pWebFrame = pWebFrame;
111         std::unique_ptr<AppControl> pAppControl(pMediaAppControl);
112         __pMediaAppControl = std::move(pAppControl);
113 }
114
115
116 _MediaSelectionListener::~_MediaSelectionListener(void)
117 {
118
119 }
120
121
122 void
123 _MediaSelectionListener::OnAppControlCompleteResponseReceived(const Tizen::App::AppId& providerId, const Tizen::Base::String& operationId, Tizen::App::AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pAppData)
124 {
125         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");
126
127         Eina_List* pSelectedFileNames = null;
128         int fileCount = 0;
129
130         ArrayList *pSelectedFiles = dynamic_cast< ArrayList* >(const_cast< Object* >(pAppData->GetValue(String("http://tizen.org/appcontrol/data/selected"))));
131         SysTryCatch(NID_WEB_CTRL, pSelectedFiles, , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
132
133         fileCount = pSelectedFiles->GetCount();
134
135         for (int i = 0; i < fileCount; i++)
136         {
137                 std::unique_ptr<String> pFile((String*)pSelectedFiles->GetAt(i));
138                 SysTryCatch(NID_WEB_CTRL, pFile, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
139
140                 std::unique_ptr<ByteBuffer> pByteBuf(StringUtil::StringToUtf8N(*pFile));
141                 SysTryCatch(NID_WEB_CTRL, pByteBuf.get(), , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
142
143                 pSelectedFileNames = eina_list_append(pSelectedFileNames, strdup((const char*)pByteBuf->GetPointer()));
144                 SysTryCatch(NID_WEB_CTRL, pSelectedFileNames, , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
145         }
146
147         ewk_view_open_panel_reply(__pWebFrame, pSelectedFileNames, EINA_TRUE);
148         eina_list_free(pSelectedFileNames);
149
150         delete this;
151         return;
152
153 CATCH:
154         ewk_view_open_panel_reply(__pWebFrame, null, EINA_FALSE);
155         eina_list_free(pSelectedFileNames);
156         delete this;
157 }
158
159
160 }}} // Tizen::Web::Controls