2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file FWebWebBookmark.cpp
20 * @brief The file contains the definition of WebBookmark class.
22 * This file contains the definition of WebBookmark class.
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"
34 using namespace Tizen::Base;
35 using namespace Tizen::Graphics;
36 using namespace Tizen::Security;
39 namespace Tizen { namespace Web
43 WebBookmark::WebBookmark(void)
44 : __pWebBookmarkImpl(null)
49 WebBookmark::~WebBookmark(void)
51 delete __pWebBookmarkImpl;
52 __pWebBookmarkImpl = null;
57 WebBookmark::Construct(void)
59 SysAssertf(__pWebBookmarkImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
63 std::unique_ptr<_WebBookmarkImpl> pWebBookmarkImpl(new (std::nothrow) _WebBookmarkImpl());
64 SysTryReturnResult(NID_WEB, pWebBookmarkImpl.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
66 r = pWebBookmarkImpl->Construct();
67 SysTryReturn(NID_WEB, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
69 __pWebBookmarkImpl = pWebBookmarkImpl.release();
76 WebBookmark::AddFolder(const String& title, RecordId& folderId, RecordId parentId)
78 SysAssertf(__pWebBookmarkImpl != null, "Not yet constructed. Construct() should be called before use.");
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.");
85 r = __pWebBookmarkImpl->AddFolder(title, parentId, folderId);
86 SysTryReturn(NID_WEB, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
88 SysLog(NID_WEB, "The current value of title is %ls, folderId is %d, parentId is %d", title.GetPointer(), folderId, parentId);
95 WebBookmark::AddBookmark(const String& title, const String& url, RecordId& bookmarkId, RecordId parentId)
97 SysAssertf(__pWebBookmarkImpl != null, "Not yet constructed. Construct() should be called before use.");
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.");
104 r = __pWebBookmarkImpl->AddBookmark(title, url, parentId, bookmarkId);
105 SysTryReturn(NID_WEB, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
107 SysLog(NID_WEB, "The current value of title is %ls, url is %ls, parentId is %d", title.GetPointer(), url.GetPointer(), parentId);
114 WebBookmark::SetFavicon(RecordId bookmarkId, const Bitmap& favicon)
116 SysAssertf(__pWebBookmarkImpl != null, "Not yet constructed. Construct() should be called before use.");
118 result r = E_SUCCESS;
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.");
123 r = __pWebBookmarkImpl->SetFavicon(bookmarkId, favicon);
124 SysTryReturn(NID_WEB, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
126 SysLog(NID_WEB, "The current value of bookmarkId is %d", bookmarkId);
133 WebBookmark::GetItemAt(int index) const
135 SysAssertf(__pWebBookmarkImpl != null, "Not yet constructed. Construct() should be called before use.");
138 result r = E_SUCCESS;
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));
143 const BookmarkItem* pItem = __pWebBookmarkImpl->GetItemAt(index);
144 SysTryReturn(NID_WEB, pItem, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
146 SysLog(NID_WEB, "The current value of index is %d", index);
153 WebBookmark::GetItemCount(void) const
155 SysAssertf(__pWebBookmarkImpl != null, "Not yet constructed. Construct() should be called before use.");
158 result r = E_SUCCESS;
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));
163 return __pWebBookmarkImpl->GetItemCount();
168 WebBookmark::RemoveAll(void)
170 SysAssertf(__pWebBookmarkImpl != null, "Not yet constructed. Construct() should be called before use.");
172 result r = E_SUCCESS;
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.");
177 r = __pWebBookmarkImpl->RemoveAll();
178 SysTryReturn(NID_WEB, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));