Tizen 2.1 base
[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 wchar_t __allowedAppControlTable[][2][64] =
51 {
52         {L"osp.appcontrol.BROWSER", L"osp.appcontrol.operation.DEFAULT"},
53         {L"osp.appcontrol.provider.browser", L"osp.appcontrol.operation.view"},
54         {L"http://tizen.org/appcontrol/provider/browser", L"http://tizen.org/appcontrol/operation/view"},
55         {L"tizen.internet", L"http://tizen.org/appcontrol/operation/view"},
56 };
57
58 result
59 StartAppControl(int req, const String& aId, const String& oId, const String* pUri, const String* pMime, const IMap* pMap)
60 {
61         SysLog(NID_APP, "StartAppControl: Entry to Browser AppControl");
62
63         const bool isAllowed = _AppControlManager::IsAllowedAppControl(__allowedAppControlTable, 4, aId, oId);
64         SysTryReturnResult(NID_APP, isAllowed, E_SYSTEM, "Invalid AppControl entry for (%ls, %ls).", aId.GetPointer(), oId.GetPointer());
65
66         _AppMessageImpl msg;
67
68         char* pUriLiteral = null;
69         if (pMap)
70         {
71                 msg.AddData(pMap);
72
73                 if (pUri == null)
74                 {
75                         // if there is not pUri, then search for "url" key.
76                         const String* pUriData = static_cast<const String*>(pMap->GetValue(String(L"url")));
77                         if (pUriData)
78                         {
79                                 pUriLiteral = _StringConverter::CopyToCharArrayN(*pUriData);
80                         }
81                 }
82         }
83
84         result r = _AppControlManager::GetInstance()->LaunchPkg(msg, "org.tizen.browser", SERVICE_OPERATION_VIEW, NULL, pUriLiteral, NULL, 0);
85         if (IsFailed(r))
86         {
87                 r = _AppControlManager::GetInstance()->LaunchPkg(msg, "com.samsung.browser", SERVICE_OPERATION_VIEW, NULL, pUriLiteral, NULL, 0);
88         }
89
90         delete [] pUriLiteral;
91
92         SysTryLog(NID_APP, !IsFailed(r), "[%s] System error.", GetErrorMessage(r));
93
94         SysLog(NID_APP, "StartAppControl: Launching Browser AppControl succeeded");
95
96         return r;
97 }
98
99 result
100 TerminateAppControl(int req)
101 {
102         return E_SUCCESS;
103 }
104
105 #ifdef __cplusplus
106 }
107 #endif