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 {
27 DPL::OptionalString toString(WKStringRef str)
29 if (WKStringIsEmpty(str)) {
30 return DPL::OptionalString::Null;
32 size_t size = WKStringGetMaximumUTF8CStringSize(str);
33 char buffer[size + 1];
34 WKStringGetUTF8CString(str, buffer, size + 1);
35 return DPL::FromUTF8String(buffer);
38 DPL::OptionalString toString(WKURLRef url)
40 WKStringRef urlStr = WKURLCopyString(url);
41 DPL::OptionalString str = toString(urlStr);
46 DPL::OptionalString toString(WKURLRequestRef req)
48 WKURLRef reqUrl = WKURLRequestCopyURL(req);
49 DPL::OptionalString str = toString(reqUrl);
54 DPL::OptionalString toString(WKFrameRef req)
56 WKURLRef reqUrl = WKFrameCopyURL(req);
57 DPL::OptionalString str = toString(reqUrl);
62 DPL::OptionalString toString(WKErrorRef err)
64 WKStringRef domErr = WKErrorCopyDomain(err);
65 WKStringRef desc = WKErrorCopyLocalizedDescription(err);
67 (WKStringIsEmpty(domErr) ? L"null" : *toString(domErr)) +
69 (WKStringIsEmpty(desc) ? L"null" : *toString(desc));
76 } // namespace ViewModule