Tizen 2.2.1
[framework/osp/web.git] / src / FWebWebBookmark.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                FWebWebBookmark.cpp
20  * @brief               The file contains the definition of WebBookmark class.
21  *
22  * This file contains the definition of WebBookmark class.
23  */
24 #include <new>
25 #include <unique_ptr.h>
26 #include <FBaseResult.h>
27 #include <FBaseSysLog.h>
28 #include <FGrpBitmap.h>
29 #include <FWebWebBookmark.h>
30 #include <FSec_AccessController.h>
31 #include "FWeb_WebBookmarkImpl.h"
32
33
34 using namespace Tizen::Base;
35 using namespace Tizen::Graphics;
36 using namespace Tizen::Security;
37
38
39 namespace Tizen { namespace Web
40 {
41
42
43 WebBookmark::WebBookmark(void)
44         : __pWebBookmarkImpl(null)
45 {
46 }
47
48
49 WebBookmark::~WebBookmark(void)
50 {
51         delete __pWebBookmarkImpl;
52         __pWebBookmarkImpl = null;
53 }
54
55
56 result
57 WebBookmark::Construct(void)
58 {
59         SysAssertf(__pWebBookmarkImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
60
61         result r = E_SUCCESS;
62
63         std::unique_ptr<_WebBookmarkImpl> pWebBookmarkImpl(new (std::nothrow) _WebBookmarkImpl());
64         SysTryReturnResult(NID_WEB, pWebBookmarkImpl.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
65
66         r = pWebBookmarkImpl->Construct();
67         SysTryReturn(NID_WEB, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
68
69         __pWebBookmarkImpl = pWebBookmarkImpl.release();
70
71         return E_SUCCESS;
72 }
73
74
75 result
76 WebBookmark::AddFolder(const String& title, RecordId& folderId, RecordId parentId)
77 {
78         SysAssertf(__pWebBookmarkImpl != null, "Not yet constructed. Construct() should be called before use.");
79
80         result r = E_SUCCESS;
81
82         r = _AccessController::CheckUserPrivilege(_PRV_BOOKMARK_WRITE);
83         SysTryReturnResult(NID_WEB, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
84
85         r = __pWebBookmarkImpl->AddFolder(title, parentId, folderId);
86         SysTryReturn(NID_WEB, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
87         
88         SysLog(NID_WEB, "The current value of title is %ls, folderId is %d, parentId is %d", title.GetPointer(), folderId, parentId);
89         
90         return E_SUCCESS;
91 }
92
93
94 result
95 WebBookmark::AddBookmark(const String& title, const String& url, RecordId& bookmarkId, RecordId parentId)
96 {
97         SysAssertf(__pWebBookmarkImpl != null, "Not yet constructed. Construct() should be called before use.");
98
99         result r = E_SUCCESS;
100
101         r = _AccessController::CheckUserPrivilege(_PRV_BOOKMARK_WRITE);
102         SysTryReturnResult(NID_WEB, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
103
104         r = __pWebBookmarkImpl->AddBookmark(title, url, parentId, bookmarkId);
105         SysTryReturn(NID_WEB, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
106         
107         SysSecureLog(NID_WEB, "The current value of title is %ls, url is %ls, parentId is %d", title.GetPointer(), url.GetPointer(), parentId);
108         
109         return E_SUCCESS;
110 }
111
112
113 result 
114 WebBookmark::SetFavicon(RecordId bookmarkId, const Bitmap& favicon)
115 {
116         SysAssertf(__pWebBookmarkImpl != null, "Not yet constructed. Construct() should be called before use.");
117
118         result r = E_SUCCESS;
119
120         r = _AccessController::CheckUserPrivilege(_PRV_BOOKMARK_WRITE);
121         SysTryReturnResult(NID_WEB, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
122
123         r = __pWebBookmarkImpl->SetFavicon(bookmarkId, favicon);
124         SysTryReturn(NID_WEB, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
125         
126         SysSecureLog(NID_WEB, "The current value of bookmarkId is %d", bookmarkId);
127         
128         return E_SUCCESS;
129 }
130
131
132 const BookmarkItem*
133 WebBookmark::GetItemAt(int index) const
134 {
135         SysAssertf(__pWebBookmarkImpl != null, "Not yet constructed. Construct() should be called before use.");
136
137         ClearLastResult();
138         result r = E_SUCCESS;
139
140         r = _AccessController::CheckUserPrivilege(_PRV_BOOKMARK_READ);
141         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));
142
143         const BookmarkItem* pItem = __pWebBookmarkImpl->GetItemAt(index);
144         SysTryReturn(NID_WEB, pItem, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
145         
146         SysLog(NID_WEB, "The current value of index is %d", index);
147         
148         return pItem;
149 }
150
151
152 int
153 WebBookmark::GetItemCount(void) const
154 {
155         SysAssertf(__pWebBookmarkImpl != null, "Not yet constructed. Construct() should be called before use.");
156
157         ClearLastResult();
158         result r = E_SUCCESS;
159
160         r = _AccessController::CheckUserPrivilege(_PRV_BOOKMARK_READ);
161         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));
162
163         return __pWebBookmarkImpl->GetItemCount();
164 }
165
166
167 result
168 WebBookmark::RemoveAll(void)
169 {
170         SysAssertf(__pWebBookmarkImpl != null, "Not yet constructed. Construct() should be called before use.");
171
172         result r = E_SUCCESS;
173
174         r = _AccessController::CheckUserPrivilege(_PRV_BOOKMARK_WRITE);
175         SysTryReturnResult(NID_WEB, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
176
177         r = __pWebBookmarkImpl->RemoveAll();
178         SysTryReturn(NID_WEB, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
179         
180         return E_SUCCESS;
181 }
182
183
184 }} // Tizen::Web