Files
cefsharp/CefSharp.Core/Internals/CefRequestWrapper.cpp
T
2016-01-11 13:57:51 +10:00

143 lines
3.9 KiB
C++

// Copyright © 2010-2015 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
#include "Stdafx.h"
#include "CefRequestWrapper.h"
#include "CefPostDataWrapper.h"
using namespace System::Text;
namespace CefSharp
{
namespace Internals
{
String^ CefRequestWrapper::Url::get()
{
ThrowIfDisposed();
return StringUtils::ToClr(_wrappedRequest->GetURL());
}
void CefRequestWrapper::Url::set(String^ url)
{
if (url == nullptr)
{
throw gcnew System::ArgumentException("cannot be null", "url");
}
ThrowIfDisposed();
CefString str = StringUtils::ToNative(url);
_wrappedRequest->SetURL(str);
}
String^ CefRequestWrapper::Method::get()
{
ThrowIfDisposed();
return StringUtils::ToClr(_wrappedRequest->GetMethod());
}
void CefRequestWrapper::Method::set(String^ method)
{
if (method == nullptr)
{
throw gcnew System::ArgumentException("cannot be null", "method");
}
ThrowIfDisposed();
_wrappedRequest->SetMethod(StringUtils::ToNative(method));
}
void CefRequestWrapper::SetReferrer(String^ referrerUrl, CefSharp::ReferrerPolicy policy)
{
ThrowIfDisposed();
_wrappedRequest->SetReferrer(StringUtils::ToNative(referrerUrl), (cef_referrer_policy_t)policy);
}
String^ CefRequestWrapper::ReferrerUrl::get()
{
ThrowIfDisposed();
return StringUtils::ToClr(_wrappedRequest->GetReferrerURL());
}
CefSharp::ReferrerPolicy CefRequestWrapper::ReferrerPolicy::get()
{
ThrowIfDisposed();
return (CefSharp::ReferrerPolicy)_wrappedRequest->GetReferrerPolicy();
}
NameValueCollection^ CefRequestWrapper::Headers::get()
{
ThrowIfDisposed();
CefRequest::HeaderMap hm;
_wrappedRequest->GetHeaderMap(hm);
NameValueCollection^ headers = gcnew NameValueCollection();
for (CefRequest::HeaderMap::iterator it = hm.begin(); it != hm.end(); ++it)
{
String^ name = StringUtils::ToClr(it->first);
String^ value = StringUtils::ToClr(it->second);
headers->Add(name, value);
}
return headers;
}
void CefRequestWrapper::Headers::set(NameValueCollection^ headers)
{
ThrowIfDisposed();
CefRequest::HeaderMap hm;
for each(String^ key in headers)
{
CefString name = StringUtils::ToNative(key);
for each(String^ element in headers->GetValues(key))
{
CefString value = StringUtils::ToNative(element);
hm.insert(std::make_pair(name, value));
}
}
_wrappedRequest->SetHeaderMap(hm);
}
TransitionType CefRequestWrapper::TransitionType::get()
{
ThrowIfDisposed();
return (CefSharp::TransitionType) _wrappedRequest->GetTransitionType();
}
IPostData^ CefRequestWrapper::PostData::get()
{
ThrowIfDisposed();
if (_postData == nullptr)
{
auto postData = _wrappedRequest->GetPostData();
if (postData.get())
{
_postData = gcnew CefPostDataWrapper(postData);
}
}
return _postData;
}
void CefRequestWrapper::InitializePostData()
{
ThrowIfDisposed();
_wrappedRequest->SetPostData(CefPostData::Create());
}
}
}