2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file view_logic_utils.cpp
18 * @author Lukasz Marek (l.marek@samsung.com)
19 * @brief Implementation file of utils API used by ViewLogic
22 #include "view_logic_utils.h"
24 namespace ViewModule {
26 DPL::OptionalString toString(WKStringRef str)
28 if (WKStringIsEmpty(str)) {
29 return DPL::OptionalString::Null;
31 size_t size = WKStringGetMaximumUTF8CStringSize(str);
32 char buffer[size + 1];
33 WKStringGetUTF8CString(str, buffer, size + 1);
34 return DPL::FromUTF8String(buffer);
37 DPL::OptionalString toString(WKURLRef url)
39 WKStringRef urlStr = WKURLCopyString(url);
40 DPL::OptionalString str = toString(urlStr);
45 DPL::OptionalString toString(WKURLRequestRef req)
47 WKURLRef reqUrl = WKURLRequestCopyURL(req);
48 DPL::OptionalString str = toString(reqUrl);
53 DPL::OptionalString toString(WKFrameRef req)
55 WKURLRef reqUrl = WKFrameCopyURL(req);
56 DPL::OptionalString str = toString(reqUrl);
61 DPL::OptionalString toString(WKErrorRef err)
63 WKStringRef domErr = WKErrorCopyDomain(err);
64 WKStringRef desc = WKErrorCopyLocalizedDescription(err);
66 (WKStringIsEmpty(domErr) ? L"null" : *toString(domErr)) +
68 (WKStringIsEmpty(desc) ? L"null" : *toString(desc));
74 } // namespace ViewModule