AppControl 2.0/2.1 argument handling
[framework/osp/app-controls.git] / src / browser-app-control / BrowserAppControlDLLEntry.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         BrowserAppControlDllEntry.cpp
20  * @brief       This is the implementation for the BrowserAppControlDllEntry.cpp class.
21  */
22
23 #include <appsvc/appsvc.h>
24 #include <appfw/app_service.h>
25
26 #include <FBaseSysLog.h>
27 #include <FAppAppControl.h>
28 #include <FBaseColHashMap.h>
29
30 #include <FBase_StringConverter.h>
31 #include <FApp_AppControlManager.h>
32 #include <FApp_AppMessageImpl.h>
33 #include <FApp_AppArg.h>
34
35
36 using namespace Tizen::App;
37 using namespace Tizen::Base;
38 using namespace Tizen::Base::Collection;
39
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45
46 result _OSP_EXPORT_ StartAppControl(int req, const String&, const String&, const String*, const String*, const IMap*);
47 result _OSP_EXPORT_ TerminateAppControl(int req);
48
49
50 static const char __allowedAppControlTable[][2][96] =
51 {
52         {"osp.appcontrol.BROWSER", "osp.appcontrol.operation.DEFAULT"},
53         {"osp.appcontrol.provider.browser", "osp.appcontrol.operation.view"},
54         {"tizen.internet", "http://tizen.org/appcontrol/operation/view"},
55 };
56
57 result
58 StartAppControl(int req, const String& aId, const String& oId, const String* pUri, const String* pMime, const IMap* pMap)
59 {
60         SysLog(NID_APP, "StartAppControl: Entry to Browser AppControl");
61
62         const bool isAllowed = _AppControlManager::IsAllowedAppControl(__allowedAppControlTable, 3, aId, oId);
63         SysTryReturnResult(NID_APP, isAllowed, E_SYSTEM, "Invalid AppControl entry for (%ls, %ls).", aId.GetPointer(), oId.GetPointer());
64
65         _AppMessageImpl msg;
66
67         const String* pActualUri = pUri;
68         String tmp;
69
70         if (pMap)
71         {
72                 msg.AddData(pMap);
73
74                 if (pUri == null)
75                 {
76                         // if there is not pUri, then search for "url" key.
77                         const String* pData = static_cast<const String*>(pMap->GetValue(String(L"url")));
78                         if (pData)
79                         {
80                                 tmp = *pData;
81                                 pActualUri = &tmp;
82                         }
83                 }
84         }
85
86         const String& package = _AppControlManager::GetAliasAppId(aId);
87         SysLog(NID_APP, "Actual packageId is %ls.", package.GetPointer());
88
89         int pid = _AppControlManager::GetInstance()->LaunchPkg(msg, package, String(SERVICE_OPERATION_VIEW), pActualUri, pMime, NULL, 0);
90
91         result r = E_SUCCESS;
92         if (pid <= 0)
93         {
94                 r = GetLastResult();
95                 SysLog(NID_APP, "[%s] System error.", GetErrorMessage(r));
96         }
97
98         SysLog(NID_APP, "StartAppControl: Launching Browser AppControl succeeded");
99
100         return r;
101 }
102
103 result
104 TerminateAppControl(int req)
105 {
106         return E_SUCCESS;
107 }
108
109 #ifdef __cplusplus
110 }
111 #endif