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 FWeb_WebHistoryImplcpp
20 * @brief The file contains the definition of _WebHistoryImpl class.
22 * This file contains the definition of _WebHistoryImpl class.
25 #include <favorites.h>
26 #include <unique_ptr.h>
27 #include <FWebHistoryItem.h>
28 #include <FWebWebHistory.h>
29 #include <FBaseSysLog.h>
30 #include "FWeb_HistoryItemImpl.h"
31 #include "FWeb_WebHistoryImpl.h"
34 using namespace Tizen::Base;
37 namespace Tizen { namespace Web
42 _HistoryForEachCb(favorites_history_entry_s* pItem, void* pUserData)
44 SysAssertf(pItem && pUserData, "Failed to request");
48 _WebHistoryImpl* pImpl = reinterpret_cast< _WebHistoryImpl* >(pUserData);
50 String url(pItem->address);
51 String title(pItem->title);
53 r = pImpl->AddItem(url, title, pItem->id);
54 SysTryReturn(NID_WEB, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
60 _WebHistoryImpl::_WebHistoryImpl(void)
65 _WebHistoryImpl::~_WebHistoryImpl(void)
67 __historyList.RemoveAll(true);
72 _WebHistoryImpl::Construct(void)
76 r = __historyList.Construct();
77 SysTryReturn(NID_WEB, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
79 int ret = favorites_history_foreach(_HistoryForEachCb, this);
80 SysTryCatch(NID_WEB, ret == FAVORITES_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to Set history Callback.");
85 __historyList.RemoveAll(true);
92 _WebHistoryImpl::GetItemAt(int index) const
95 (index >= 0 && index < GetItemCount()), null, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The index is out of range.");
97 return dynamic_cast < const HistoryItem* >(__historyList.GetAt(index));
102 _WebHistoryImpl::GetItemCount(void) const
104 return __historyList.GetCount();
109 _WebHistoryImpl::AddItem(const Tizen::Base::String& url, const Tizen::Base::String& title, int id)
111 result r = E_SUCCESS;
113 std::unique_ptr<HistoryItem> pHistoryItem(new (std::nothrow) HistoryItem());
114 SysTryReturnResult(NID_WEB, pHistoryItem.get(), E_OUT_OF_MEMORY, "Memory allocation failed");
116 _HistoryItemImpl* pHistoryItemImpl = _HistoryItemImpl::GetInstance(pHistoryItem.get());
117 SysTryReturn(NID_WEB_CTRL, pHistoryItemImpl, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
119 pHistoryItemImpl->SetHistoryItem(url, title, id);
121 r = __historyList.Add(*pHistoryItem.get());
122 SysTryReturn(NID_WEB, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
123 pHistoryItem.release();
130 _WebHistoryImpl::GetInstance(WebHistory* pWebHistory)
132 return pWebHistory->__pWebHistoryImpl;
136 const _WebHistoryImpl*
137 _WebHistoryImpl::GetInstance(const WebHistory* pWebHistory)
139 return pWebHistory->__pWebHistoryImpl;