Files
cefsharp/CefSharp.Core/RequestContextBuilder.cpp
T
Alex Maitland 3eca8bdba6 Enhancement - Simplify Setting of RequestContext Proxy (#3250)
Core - Simplify Setting of Proxy for new RequestContext

- Throw exception if requestContext.CanSetPreference returns false.
Proxy likely set via command line args.
- Add IRequestContext.SetPreferenceAsync
-  Test - Add SelfHosted Proxy
Use Titanium.Web.Proxy to self host a proxy for testing proxy settings
Only run Proxy Tests when run locally
- Add RequestContext Builder Fluent API
2020-10-13 13:40:46 +10:00

128 lines
3.0 KiB
C++

// Copyright © 2020 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 "RequestContextBuilder.h"
#include "RequestContext.h"
namespace CefSharp
{
IRequestContext^ RequestContextBuilder::Create()
{
if (_otherContext != nullptr)
{
return gcnew RequestContext(_otherContext, _handler);
}
if(_settings != nullptr)
{
return gcnew RequestContext(_settings, _handler);
}
return gcnew RequestContext(_handler);
}
RequestContextBuilder^ RequestContextBuilder::OnInitialize(Action<IRequestContext^>^ action)
{
if (_handler == nullptr)
{
_handler = gcnew RequestContextHandler();
}
_handler->OnInitialize(action);
return this;
}
RequestContextBuilder^ RequestContextBuilder::WithPreference(String^ name, Object^ value)
{
if (_handler == nullptr)
{
_handler = gcnew RequestContextHandler();
}
_handler->SetPreferenceOnContextInitialized(name, value);
return this;
}
RequestContextBuilder^ RequestContextBuilder::WithProxyServer(String^ host)
{
if (_handler == nullptr)
{
_handler = gcnew RequestContextHandler();
}
_handler->SetProxyOnContextInitialized(host, Nullable<int>());
return this;
}
RequestContextBuilder^ RequestContextBuilder::WithProxyServer(String^ host, Nullable<int> port)
{
if (_handler == nullptr)
{
_handler = gcnew RequestContextHandler();
}
_handler->SetProxyOnContextInitialized(host, port);
return this;
}
RequestContextBuilder^ RequestContextBuilder::WithProxyServer(String^ scheme, String^ host, Nullable<int> port)
{
if (_handler == nullptr)
{
_handler = gcnew RequestContextHandler();
}
_handler->SetProxyOnContextInitialized(scheme, host, port);
return this;
}
RequestContextBuilder^ RequestContextBuilder::PersistUserPreferences()
{
ThrowExceptionIfContextAlreadySet();
if (_settings == nullptr)
{
_settings = gcnew RequestContextSettings();
}
_settings->PersistUserPreferences = true;
return this;
}
RequestContextBuilder^ RequestContextBuilder::WithCachePath(String^ cachePath)
{
ThrowExceptionIfContextAlreadySet();
if (_settings == nullptr)
{
_settings = gcnew RequestContextSettings();
}
_settings->CachePath = cachePath;
return this;
}
RequestContextBuilder^ RequestContextBuilder::WithSharedSettings(IRequestContext^ other)
{
if (other == nullptr)
{
throw gcnew ArgumentNullException("other");
}
ThrowExceptionIfCustomSettingSpecified();
_otherContext = other;
return this;
}
}