|
| 1 | +// Copyright © 2020 The CefSharp Authors. All rights reserved. |
| 2 | +// |
| 3 | +// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +#include "Stdafx.h" |
| 6 | +#include "RequestContextBuilder.h" |
| 7 | +#include "RequestContext.h" |
| 8 | + |
| 9 | +namespace CefSharp |
| 10 | +{ |
| 11 | + IRequestContext^ RequestContextBuilder::Create() |
| 12 | + { |
| 13 | + if (_otherContext != nullptr) |
| 14 | + { |
| 15 | + return gcnew RequestContext(_otherContext, _handler); |
| 16 | + } |
| 17 | + |
| 18 | + if(_settings != nullptr) |
| 19 | + { |
| 20 | + return gcnew RequestContext(_settings, _handler); |
| 21 | + } |
| 22 | + |
| 23 | + return gcnew RequestContext(_handler); |
| 24 | + } |
| 25 | + |
| 26 | + RequestContextBuilder^ RequestContextBuilder::OnInitialize(Action<IRequestContext^>^ action) |
| 27 | + { |
| 28 | + if (_handler == nullptr) |
| 29 | + { |
| 30 | + _handler = gcnew RequestContextHandler(); |
| 31 | + } |
| 32 | + |
| 33 | + _handler->OnInitialize(action); |
| 34 | + |
| 35 | + return this; |
| 36 | + } |
| 37 | + |
| 38 | + RequestContextBuilder^ RequestContextBuilder::WithPreference(String^ name, Object^ value) |
| 39 | + { |
| 40 | + if (_handler == nullptr) |
| 41 | + { |
| 42 | + _handler = gcnew RequestContextHandler(); |
| 43 | + } |
| 44 | + |
| 45 | + _handler->SetPreferenceOnContextInitialized(name, value); |
| 46 | + |
| 47 | + return this; |
| 48 | + } |
| 49 | + |
| 50 | + RequestContextBuilder^ RequestContextBuilder::WithProxyServer(String^ host) |
| 51 | + { |
| 52 | + if (_handler == nullptr) |
| 53 | + { |
| 54 | + _handler = gcnew RequestContextHandler(); |
| 55 | + } |
| 56 | + |
| 57 | + _handler->SetProxyOnContextInitialized(host, Nullable<int>()); |
| 58 | + |
| 59 | + return this; |
| 60 | + } |
| 61 | + |
| 62 | + RequestContextBuilder^ RequestContextBuilder::WithProxyServer(String^ host, Nullable<int> port) |
| 63 | + { |
| 64 | + if (_handler == nullptr) |
| 65 | + { |
| 66 | + _handler = gcnew RequestContextHandler(); |
| 67 | + } |
| 68 | + |
| 69 | + _handler->SetProxyOnContextInitialized(host, port); |
| 70 | + |
| 71 | + return this; |
| 72 | + } |
| 73 | + |
| 74 | + RequestContextBuilder^ RequestContextBuilder::WithProxyServer(String^ scheme, String^ host, Nullable<int> port) |
| 75 | + { |
| 76 | + if (_handler == nullptr) |
| 77 | + { |
| 78 | + _handler = gcnew RequestContextHandler(); |
| 79 | + } |
| 80 | + |
| 81 | + _handler->SetProxyOnContextInitialized(scheme, host, port); |
| 82 | + |
| 83 | + return this; |
| 84 | + } |
| 85 | + |
| 86 | + RequestContextBuilder^ RequestContextBuilder::PersistUserPreferences() |
| 87 | + { |
| 88 | + ThrowExceptionIfContextAlreadySet(); |
| 89 | + |
| 90 | + if (_settings == nullptr) |
| 91 | + { |
| 92 | + _settings = gcnew RequestContextSettings(); |
| 93 | + } |
| 94 | + |
| 95 | + _settings->PersistUserPreferences = true; |
| 96 | + |
| 97 | + return this; |
| 98 | + } |
| 99 | + |
| 100 | + RequestContextBuilder^ RequestContextBuilder::WithCachePath(String^ cachePath) |
| 101 | + { |
| 102 | + ThrowExceptionIfContextAlreadySet(); |
| 103 | + |
| 104 | + if (_settings == nullptr) |
| 105 | + { |
| 106 | + _settings = gcnew RequestContextSettings(); |
| 107 | + } |
| 108 | + |
| 109 | + _settings->CachePath = cachePath; |
| 110 | + |
| 111 | + return this; |
| 112 | + } |
| 113 | + |
| 114 | + RequestContextBuilder^ RequestContextBuilder::WithSharedSettings(IRequestContext^ other) |
| 115 | + { |
| 116 | + if (other == nullptr) |
| 117 | + { |
| 118 | + throw gcnew ArgumentNullException("other"); |
| 119 | + } |
| 120 | + |
| 121 | + ThrowExceptionIfCustomSettingSpecified(); |
| 122 | + |
| 123 | + _otherContext = other; |
| 124 | + |
| 125 | + return this; |
| 126 | + } |
| 127 | +} |
0 commit comments