I found this thread on GitHub, but seems that the code is not C++:
WebView2 _webView2 = new WebView2();
CoreWebView2EnvironmentOptions options = new CoreWebView2EnvironmentOptions();
// Set a proxy pac for the browser
// options.AdditionalBrowserArguments = "--proxy-pac-url=http://myproxy.com/my.pac";
// Set the proxy for the browser
options.AdditionalBrowserArguments = "--proxy-server=\"foopy:99\"";
// Create the environment manually
CoreWebView2Environment env = await CoreWebView2Environment.CreateAsync(null, null, options);
await _webView2 .EnsureCoreWebView2Async(env);
So the only what am I asking for is to provide the solution for setting up a proxy for WebView2 via C++.
I have ICoreWebView2 interface, but it doesn’t have EnsureCoreWebView2Async method. In another hand, I have CoreWebView2EnvironmentOptions class.
auto opt = Microsoft::WRL::Make<CoreWebView2EnvironmentOptions>();
opt->put_AdditionalBrowserArguments(L"--proxy-server=\"SERVER\"");
CreateCoreWebView2EnvironmentWithOptions(nullptr, nullptr, opt.Get(), Microsoft::WRL::Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>(
[hwnd](HRESULT result, ICoreWebView2Environment* env) -> HRESULT {
...
}).Get());
Instead of SERVER put ip address or something else.
I tested, it works, but seems there is a bug (or feature): you can’t create two or more webviews with different run-arguments.
To those looking to specify webview environment options and cannot find CoreWebView2EnvironmentOptions in C++ similar to what is available in .Net. Visit documentation page for ICoreWebView2EnvironmentOptions and you should find this line:
A default implementation is provided in WebView2EnvironmentOptions.h
Include WebView2EnvironmentOptions.h and create CoreWebView2EnvironmentOptions as below
#include <WebView2EnvironmentOptions.h>
auto options = Microsoft::WRL::Make<CoreWebView2EnvironmentOptions>();
// Use options however you want. I simply added an argument to autoplay videos.
options->put_AdditionalBrowserArguments(L"--autoplay-policy=no-user-gesture-required");
HRESULT hr = CreateCoreWebView2EnvironmentWithOptions(
subFolder, m_userDataFolder.c_str(), options.Get(),
Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>(
this, &AppWindow::OnCreateEnvironmentCompleted)
.Get());
Related
I have a Rest API which needs to return an item's presentation details.
I tried this line of code, but Sitecore.Context.Device is null, since this is a rest API call.
LayoutItem layoutItem = item.Visualization.GetLayout(Sitecore.Context.Device);
Update: I tried moving this code to when I index my data (hoping to read the value and write it to Solr), but I am facing the same issue.
How would I go about doing this?
The renderings are added per "device" in Sitecore, but in most cases nowadays, there's only one device. Depending on how you route your API endpoint etc., the device may not be resolved automatically. If you know you only have one device, you could pick the first device, or provide the device as a parameter. Then you can use a device switcher in case you need to call other Sitecore methods that requires a device to be set. For example like this:
var deviceName = "Default"; // The default device. Modify according to needs
var deviceItem = item.Database.Resources.Devices.GetAll().First(d => string.Equals(d.Name, deviceName, StringComparison.OrdinalIgnoreCase))
using (new DeviceSwitcher(deviceItem))
{
...
}
I've started to investigate how credential providers work, but due to poor documentation I got stuck in couple of places.
I have console application(sort of like ssh server) when I connect remotly to this application and authenticate(none is logged on), I want it to be able to forward those credentials to credential provider and I want CP to login user(create session).
I've also noticed that In documentation it says that SetSerialization method always gets called after SetusageScenario. But I've added logs and SetSerialization never gets called after SetusageScenario.
As I know SetSerialization is called when credential is provided by application. I can't understand what does it mean to provide credential through application? It seems like this is what I need, to forward credentials from application to credential provider, but How can I do that? Are there some functions that I could call from credential provider dll to provoke login?
Is there any way I can achieve this? I've read that when remote login is done, UpdateRemoteCredential is called, But As I understand(correct me if I'm wrong) in remote login it means RDP but my application is simple, it just listens to some port and gets username and password and then uses Logonuser function.
A program named MxLogon2 implements this scheme. A remote server with MxLogon2 installed can authenticate a USB key(But I want username/password) connected to the client side in a remote desktop session.
Any suggestion that would direct me to right way would be greatly appriciated.
P.S
I'm using pGina as my credential provider.
I wouldn't mind too much of SetSerialization in your case. This is used for pre-initializing tile.
One example would be, with RDP connection, you can store certificates of credentials on your system. This function is used to pre-inquire tiles with those credentials (not the only solution though).
Make it return E_NOTIMPL in your case.
The main purpose of the provider is to initialize Credentials and tiles :
Credentials initialization
is done through SetUsageScenario function (automatically called after Provider construction).
In there, you can customize the behavior depending on scenario you are in. Most basic one being CPUS_LOGON.
It shall look like this (this is only a preview)
HRESULT Provider::SetUsageScenario(
__in CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus,
__in DWORD dwFlags
)
{
HRESULT hr;
switch(cpus)
{
case CPUS_UNLOCK_WORKSTATION:
case CPUS_LOGON:
hr = this->_InitCredential();
break;
default:
hr = E_INVALIDARG;
break;
}
return hr;
}
Tiles initialization
begins in GetCredentialCount function. It allows you to define how many tiles you gonna show (pdwCount out parameter), as well as the one to be used as the default tile (pdwDefault).
Auto-Logon is also handle in here (through pbAutoLogonWithDefault).
Tiles Enumeration is then beginning in GetCredentialAt function.
Passing credentials for authentication is done in the credential you're using through the GetSerialization function.
Examples of implementation can be found here.
I hardly insist on example as it easily divert depending on what you are trying to achieve. This is very flexible and you'd better understand the purpose of any function / parameter to fit your goals.
EDIT - cf comments :
#define IDCredential 0x1
Credential::Credential(Provider* parent)
{
//Do ssh connection or whatever
if(success)
{
parent->login = retrievedLogin;
parent->pwd = retrievedPwd;
parent->CredentialUsed = IDCredential;
parent->autoLogin = true;
parent->ProviderEvents->CredentialsChanged(AdviseContext);
}
}
HRESULT Provider::GetCredentialCount(
__out DWORD* pdwCount,
__out_range(<,*pdwCount) DWORD* pdwDefault,
__out BOOL* pbAutoLogonWithDefault
)
{
if(this->autoLogin && this->CredentialUsed)
{
*pbAutoLogonWithDefault = true; // --> Instant call to GetSerialization
*pdwDefault = this->CredentialUsed; //index of the tile
}
else
{
*pbAutoLogonWithDefault = false;
*pdwDefault = IDCredential;
}
return S_OK;
}
I was able to obtain proxy data that was manually entered into proxy settings on my Windows machine (Use a proxy server for your LAN option was checked) but I'm wondering if WinHttpGetIEProxyConfigForCurrentUser will also set field LPWSTR lpszProxy in case when Use automatic configuration script or Automatically detect settings checkboxes are checked in this dialog:
If not, how to obtain address of the currently used proxy?
You will get that in lpszAutoConfigUrl.
lpszAutoConfigUrl is variable of the structure WINHTTP_CURRENT_USER_IE_PROXY_CONFIG that is parameter of WinHttpGetIEProxyConfigForCurrentUser
Documentation link.
https://learn.microsoft.com/en-us/windows/desktop/api/winhttp/ns-winhttp-winhttp_current_user_ie_proxy_config
Code used for a quick test:
WINHTTP_CURRENT_USER_IE_PROXY_CONFIG pProxyConfig;
pProxyConfig.fAutoDetect = TRUE;
WinHttpGetIEProxyConfigForCurrentUser(&pProxyConfig);
WinHttpGetIEProxyConfigForCurrentUser() can be used to determine if both:
"Automatically detect settings" is enabled (member 'fAutoDetect' of WINHTTP_CURRENT_USER_IE_PROXY_CONFIG structure) and
"Automatic configuration script" is set (member 'lpszAutoConfigUrl' of WINHTTP_CURRENT_USER_IE_PROXY_CONFIG structure)
However, to obtain the proxy address itself for particular endpoint, WinHttpGetProxyForUrl() should be used.
If you already have 'Automatic configuration script' read from IE Internet options, you may use it like this:
WINHTTP_AUTOPROXY_OPTIONS autoProxyOptions= {0};
WINHTTP_PROXY_INFO proxyInfo= {0};
PCWSTR endpointUrl = <URL, that you need proxy for>;
autoProxyOptions.lpszAutoConfigUrl = <auto config address obtain from WINHTTP_CURRENT_USER_IE_PROXY_CONFIG>;
.
. //set suitable autoProxyOptions flags
.
if (!WinHttpGetProxyForUrl(hSession, endpointUrl, &autoProxyOptions, &proxyInfo))
{
GetLastError();
}
I am trying to connect to a mobile network via a modem and a sim card. Every time I try to set the APN String and User Credentials in a Context via SetProvisionedContext() I get the E_INVALIDARG HRESULT.
As Parameters I used an Instance of MBN_CONTEXT, a wchar_t* in form of &std::vector<wchar_t>[0], and a ULONG*.
MBN_CONTEXT context;
std::vector<WCHAR> apnVector;
inParamAPN.GetCString(apnVector);
std::vector<WCHAR> userNameVec;
inParamUsername.GetCString(userNameVec);
std::vector<WCHAR> passwordVector;
inParamPassword.GetCString(passwordVector);
context.contextID = MBN_CONTEXT_ID_APPEND;
context.contextType = MBN_CONTEXT_TYPE_INTERNET;
context.accessString = &apnVector[0];
context.userName = &userNameVec[0];
context.password = &passwordVector[0];
context.compression = MBN_COMPRESSION_NONE;
context.authType = MBN_AUTH_PROTOCOL_PAP;
and later when I have the IMbnConnectionContext:
std::vector<WCHAR> providerVector;
InParamProvider.GetCString(providerVector);
ULONG requestID;
contextInterface->SetProvisionedContext(context, &providerVector[0], &requestID);
So my Question is: Which Parameter does the WinAPI have a Problem with, and how can I fix it?
Also any Tips of additional Sources for Information are appriciated.
All I have so far are the official MSDN and the Code Example contained in the Windows 7 SDK. Are there any further sources of Information I am not aware of? A google search didn't yield the hoped for results.
In the end I did not get it working as it should. I used the second way of connecting to a custom APN, by making a new connection profile. For this I used a XML filled with the Values I needed.
Along the way I encountered another problem with an unforseen Error Code which I described here.
Best regards,
Stefan
For my Flash Builder 4.6 Project I have a http service defined which looks at a url from our website.
What I'd like to be able to do though is to change the web service url on the fly within the app. i.e. using the existing url as default but having an admin/settings screen to change where the web service points (either stored in our sqlite database or in local memory).
This would be so that we could allow our customers to host their own version of the website/database but still be able to use/download the app through the app stores.
Has anyone had any experience with doing this?
EDIT: Adding some more details after the comments below.
When I created the HTTP Service through the FlashBuilder wizard it creates two web service classes a super class and a sub class which inherits from the super class. All of the code that the wizard populates goes into the super class.
I can assume that the code I need to put in would be in the sub class. But I do not know which function I'd put it in or how.
Below is a sample of the Super's constructor:
// initialize service control
_serviceControl = new mx.rpc.http.HTTPMultiService("websitehere");
var operations:Array = new Array();
var operation:mx.rpc.http.Operation;
var argsArray:Array;
operation = new mx.rpc.http.Operation(null, "loginRequest");
operation.url = "login.php";
operation.method = "GET";
argsArray = new Array("un","pw");
operation.argumentNames = argsArray;
operation.serializationFilter = serializer0;
operation.properties = new Object();
operation.properties["xPath"] = "/";
operation.contentType = "application/x-www-form-urlencoded";
operation.resultType = valueObjects.Data;
operations.push(operation);
_serviceControl.operationList = operations;
I'm not sure what property of the _serviceControl variable I would need to alter.
Also when I search for my website in my code it brings back a .fml file inside a .model directory which seems to get auto refreshed if I change the service url through the wizard. Would this not cause an issue?
I then have the challenge of accessing the user defined url. Within the app we use an sqlite database to store data but I think it would probably be better to use a 'SharedObject' which we also use to know what account they are logged into. How reliable is this? I assume I would be able to access this via the Service?
Though the awkward thing is that we were planning to have this configurable on a settings screen that would have been accessed after logging in. But to log in it would already need to know which server to point to.
if im reading your question correctly then your main ambition is to dynamically change the url for the services based on a user defined variable.
This is very easy to accomplish and even easier to accomplish if you are using parsley / spicelib.
a few points
dont change the code in the super file, this will get overwritten whenever the service gets refreshed. change everything in its generated sub-Class.
Shared Objects are very good for small quantities of data but should never be used for massive datasets i.e storing a big arraycollection.
Anyway here is how i achieve this.
In the SubClass you can change the constructor function.
Here is how i change my urls based on a config variable but you can just as easily use a SharedObject instead.
public function SubClassConstructor(){
if(CONFIG::DOMAIN_IDENT == "development" || CONFIG::DOMAIN_IDENT == "dev" || CONFIG::DOMAIN_IDENT == "d"){
_serviceControl.endpoint = "http://yoururl1";
}
else if(CONFIG::DOMAIN_IDENT == "production" || CONFIG::DOMAIN_IDENT == "prod" || CONFIG::DOMAIN_IDENT == "p"){
_serviceControl.endpoint = "http://yoururl2";
}
}
Of course this isn't exactly what your looking for but its a working solution, of course you can use Bindings to a Global ApplicationModel or direct reference to the SharedObject i guess you already know how to use the SharedObject.
Ask if you need any further help or guidance.
As cghrmauritius' solution didn't quite work for me, I am posting up the final solution that did work in my situation.
public function subConstructor()
{
super();
_serviceControl.baseURL = "http://url1";
}
Obviously for my final solution I need to implement the shareobject as well but overriding the url was my main priority.