Tizen 2.2.1
[framework/osp/web.git] / src / FWebWebHistory.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                FWebWebHistory.cpp
20  * @brief               The file contains the definition of WebHistory class.
21  *
22  * This file contains the definition of WebHistory class.
23  */
24 #include <new>
25 #include <unique_ptr.h>
26 #include <FBaseResult.h>
27 #include <FBaseSysLog.h>
28 #include <FWebWebHistory.h>
29 #include <FSec_AccessController.h>
30 #include "FWeb_WebHistoryImpl.h"
31
32
33 using namespace Tizen::Security;
34
35
36 namespace Tizen { namespace Web
37 {
38
39
40 WebHistory::WebHistory(void)
41         : __pWebHistoryImpl(null)
42 {
43 }
44
45
46 WebHistory::~WebHistory(void)
47 {
48         delete __pWebHistoryImpl;
49         __pWebHistoryImpl = null;
50 }
51
52
53 result
54 WebHistory::Construct(void)
55 {
56         SysAssertf(__pWebHistoryImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
57
58         result r = E_SUCCESS;
59
60         std::unique_ptr<_WebHistoryImpl> pWebHistoryImpl(new (std::nothrow) _WebHistoryImpl());
61         SysTryReturnResult(NID_WEB, pWebHistoryImpl.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
62
63         r = pWebHistoryImpl->Construct();
64         SysTryReturn(NID_WEB, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
65
66         __pWebHistoryImpl = pWebHistoryImpl.release();
67
68         return E_SUCCESS;
69 }
70
71
72 const HistoryItem*
73 WebHistory::GetItemAt(int index) const
74 {
75         SysAssertf(__pWebHistoryImpl != null, "Not yet constructed. Construct() should be called before use.");
76
77         ClearLastResult();
78         result r = E_SUCCESS;
79
80         r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY);
81         SysTryReturn(NID_WEB, r == E_SUCCESS, null, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
82
83         const HistoryItem* pItem = __pWebHistoryImpl->GetItemAt(index);
84         SysTryReturn(NID_WEB, pItem, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
85         
86         SysLog(NID_WEB, "The current value of index is %d", index);
87         
88         return pItem;
89 }
90
91
92 int
93 WebHistory::GetItemCount(void) const
94 {
95         SysAssertf(__pWebHistoryImpl != null, "Not yet constructed. Construct() should be called before use.");
96
97         ClearLastResult();
98         result r = E_SUCCESS;
99
100         r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY);
101         SysTryReturn(NID_WEB, r == E_SUCCESS, -1, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
102
103         return __pWebHistoryImpl->GetItemCount();
104 }
105
106
107 }} // Tizen::Web