Commit Graph

265 Commits

Author SHA1 Message Date
Vadim Zeitlin
360268ee25 Extend life time of wxWebRequest while it is in process
We already did it just before processing the state change event, but
this was too late, as the object could have been already deleted by then
and this actually happened with the example from wxWebRequest
documentation.

Do it earlier now, as soon as the request becomes active, which normally
happens when Start() is called, and keep the reference until the event
is processed after the request reaches one of the final states
(completed, failed or cancelled).

Add a unit test checking that deleting the wxWebRequest object doesn't
prevent the request from running to the completion any more.
2021-03-24 17:45:01 +01:00
Maarten Bent
1f36582d87 Initialize wxWinHTTP when wxWebSessionFactoryWinHTTP is created 2021-03-23 00:42:46 +01:00
Vadim Zeitlin
06bb60f0f8 Merge branch 'curlmultisocket' of https://github.com/NewPagodi/wxWidgets
Rewrite CURL-based wxWebRequest implementation using multi-socket
support for much better efficiency and reliability.

See https://github.com/wxWidgets/wxWidgets/pull/2193
2021-02-22 00:40:53 +01:00
New Pagodi
ab63e73920 Record active sockets in wxWebSessionCURL
If a wxWebRequestCURL object is canceled or deleted before its transfer
is complete, we need to manually close its active socket.  Record each
transfer’s active socket in wxWebSessionCURL::SocketCallback so can use
it if needed.

Previously, this was done using curl_easy_getinfo, but this required
some compile time and run time checks and could fail in some specific
cases. Recording the socket ourselves significantly simplifies the code
and should always work.
2021-02-08 12:32:32 -06:00
Tobias Taschner
1cd0904260 Fix mixed line breaks in webview sources 2021-02-08 11:27:49 +01:00
New Pagodi
4c8f9ff34d Cancel a transfer if socket poller operation fails
When using the socket poller implementation using wxEventLoopSource
objects to monitor sockets, the operation
wxEventLoopBase::AddSourceForFD(... can sometimes return NULL. In these
cases the socket will not be monitored as needed. The only option seems
to be to cancel the transfer and report a failure
2021-02-07 20:56:27 -06:00
New Pagodi
88dca37b3f Change cancel method for wxWebRequestCURL objects
Previously wxWebRequestCURL objects were canceled by removing their
CURL easy handle from the CURLM multihandle. Unfortunately the really
only pauses the connection and does not truly cancel it. This commit
tries to stop the transfer by retrieving the active socket from the CURL
handle for the transfer and closing it.

There are some complications in doing this because the option curl uses
to get the socket have changed over the years. A combination of compile
time and run time checks are used to use the appropriate options to get
the socket. However in the case of 64bit windows using a curl version
older than 7.45.0 simply won’t have an usable option. In this case,
it seems nothing can be done.
2021-02-07 20:49:50 -06:00
New Pagodi
774a752bed Track active transfers in wxWebSessionCURL class
At various points in a transfer being managed by the wxWebSessionCURL
class we need to perform operations on a wxWebRequestCURL object.
However it’s possible for the request object to be deleted while the
transfer is in progress.

To ensure that the request objects are valid, keep track of the request
objects with a hash map. Objects are added to the map when a transfer is
started and removed when the transfer is complete or in the request’s
destructor.
2021-02-07 20:49:37 -06:00
New Pagodi
48cba4f88e Set wxWebResponseCURL buffer size as soon as known
Currently for wxWebRequestCURL objects using memory storage, a download
is processed by appending to a wxMemoryBuffer each time the write
callback is called. For a large transfer, this can result in many, many
reallocation calls and can block the main application.

This commit uses the progress callback for wxWebRequestCURL objects
added in a previous commit to set a minimum size for the buffer as soon
as it is known.
2021-02-07 20:43:51 -06:00
New Pagodi
3e5fd5462d Add a progress callback for wxWebRequestCURL
This commit adds a progress callback for use with wxWebRequestCURL
objects. This has some complications because over the years curl has
changed the signature of the callback.

A combination of compile-time and run-time checks is used to make sure
the appropriate callback and preferred return value are used.
2021-02-07 20:37:47 -06:00
New Pagodi
b1b53ed85c Remove the worker thread from wxWebSessionCURL
Instead of having wxWebSessionCURL run a worker thread that uses curl
to monitor and process network activity, set up a separate socket
poller class to monitor socket activity. The socket poller class will
throw an event back to wxWebSessionCURL when it detects activity on the
sockets so that it can tell curl to process the activity in the main
thread.
2021-02-07 00:02:04 -06:00
Tobias Taschner
2e94551f6f Clear string in wxJSON::DecodeString() to avoid unintentional appending 2021-02-05 22:18:30 +01:00
Tobias Taschner
457b213315 Apply suggestions from code review
Co-authored-by: VZ <vz-github@zeitlins.org>
2021-01-19 21:06:31 +01:00
Tobias Taschner
036b7f29a7 Add wxWebRequest::DisablePeerVerify()
This method allows insecure HTTPS connections when required
2021-01-19 13:16:25 +01:00
Vadim Zeitlin
3107a17353 Remove wxWebRequestImpl::IsActiveState()
Semantics of this function wasn't really clear and it was used only
once, so just inline it at the point of use and define better what
happens for various states there.

Also use a switch rather than testing for individual states to make sure
this code is updated if another state is added in the future.

No real changes.
2021-01-16 14:48:47 +01:00
Vadim Zeitlin
508a4f6ca8 Fix Cancel() semantics under MSW and other improvements to it
Under MSW, don't set the state to State_Cancelled as soon as Cancel()
was called, as the request was still used from the other threads
afterwards, resulting in race conditions and crashes.

Fix this by just removing the SetState(State_Cancelled) call from the
main thread, as it was redundant anyhow. This also makes the behaviour
correspond to the documentation, which indicates that Cancel() works
asynchronously.

Also ensure, for all backends, that we actually cancel the request only
once, even if public Cancel() is called multiple times. This required
renaming the existing wxWebRequestImpl::Cancel() to DoCancel().
2021-01-16 13:50:29 +01:00
Vadim Zeitlin
65aad890e3 Add GetNativeHandle() to wxWebSession and wxWebRequest
This allows to retrieve the handles used internally in order to do
something not supported by the public API yet.
2021-01-16 00:21:00 +01:00
Vadim Zeitlin
a561cf199b Remove semi-public wxWebSession::GetImpl()
It's better not to have this method in the public class, even if it
means that we need to pass a wxWebSessionImpl object to wxWebRequestImpl
ctor explicitly now.

No real changes.
2021-01-15 23:50:52 +01:00
Vadim Zeitlin
ef08d499ce Remove unnecessary SetIgnoreServerErrorStatus() from the API
It's up to the application code to decide how it handles the HTTP status
codes it gets back from server, there is no need to have a special
method for handling them in wxWebRequest itself.

We also shouldn't skip downloading the response body just because it was
unsuccessful, we may still need it (e.g. it's very common to return the
detailed error description in a JSON object in the message body when
returning some 4xx error), so don't do it in wxMSW implementation and
add a test verifying that we still get the expected body even for an
error status.

Also improve wxWebRequest::State values documentation.
2021-01-15 03:08:18 +01:00
Vadim Zeitlin
d2840d2516 Add some wxLogTrace() calls to wxWebRequestURLSession code
This is helpful when trying to understand what is going on, especially
because CFNETWORK_DIAGNOSTICS, which is supposed to do the same thing at
native level, doesn't seem to work (at least under 10.14).
2021-01-13 02:04:13 +01:00
Vadim Zeitlin
0ccc6d4047 Remove useless wxWebAuthChallengeCURL::Init()
This just always returned true, so simply remove it to simplify the
code.
2021-01-12 19:15:37 +01:00
Vadim Zeitlin
20a3317839 Rename wxWebRequestEvent::GetResponseFileName() to GetDataFile()
This is shorter and doesn't imply that just the name (and not the full
path) is being returned.

Also rename wxWebResponse::GetFileName() to GetDataFile() for the same
reasons and for consistency. And document this previously undocumented
method.
2021-01-12 03:34:40 +01:00
Vadim Zeitlin
d0f56b1d04 Document wxWebResponse::GetContentLength()
Also change its return type from wxInt64 to wxFileOffset for consistency
with all the other length/progress-related functions in wxWebRequest.
2021-01-12 03:25:16 +01:00
Vadim Zeitlin
591d02c979 Increase default buffer size for wxWebRequest operations
Use 64KiB rather than 8KiB, as the latter seems rather small nowadays.

Also add a symbolic constant for this number.
2021-01-12 03:00:35 +01:00
Vadim Zeitlin
468a961426 Rename methods called from libcurl to use more clear names
Indicate that they're callbacks used by libcurl rather than normal
methods used by the application code itself.

No real changes.
2021-01-12 02:40:38 +01:00
Vadim Zeitlin
4986850c63 Rename wxWebSession::SetHeader() to AddCommonHeader()
The old name wasn't very clear and it was confusing to have methods with
the same name in wxWebSession and wxWebRequest.
2021-01-11 03:02:25 +01:00
Vadim Zeitlin
0f82a1e043 Use atomic int for reference count in wxWebRequest classes
This is required because these classes are copied in both the main and
the worker threads and using plain int is MT-unsafe.
2021-01-11 01:24:55 +01:00
Vadim Zeitlin
1d52f1cbb5 Add a comment explaining mutex use in wxWebSessionCURL
No real changes.
2021-01-11 01:11:44 +01:00
Vadim Zeitlin
d88762d2f1 Collect mutex and data protected by it in a single struct
Also use critical section instead of a mutex, as this is more efficient
under MSW.

Main purpose of this commit is to make it clear that this mutex/critical
section is only used together with the data from the same struct.

No real changes.
2021-01-10 21:27:15 +01:00
Vadim Zeitlin
1e6d6be8bb Add wxWebCredentials and use it in SetCredentials()
Prefer using a class encapsulating both the user name and the password
to using a pair of variables.
2021-01-10 21:27:15 +01:00
Vadim Zeitlin
5d236edeed Ensure wxWebRequest is in idle state before starting it
Check that current state is State_Idle in wxWebRequest itself only once
instead of doing it in 2 (out of 3) wxWebRequestImpl implementations.

Also assert if this is not the case instead of silently doing nothing
which would surely be more difficult to debug.
2021-01-09 21:00:38 +01:00
Vadim Zeitlin
989cafe535 Take raw pointer and not wxSharedPtr<> in SetData()
Using shared pointer seems to be ill-advised here, the stream shouldn't
be shared as it's going to be used by wxWebRequest itself and can't be
used by the application code in parallel, so the ownership transfer
semantics is more appropriate.

We could take a wxScopedPtr<> instead, but wx API takes ownership of raw
pointers everywhere else, so do it here too.

Incidentally fix a bug with calling IsOk() on a possibly null pointer.
2021-01-04 01:57:36 +01:00
Vadim Zeitlin
50424cba2c Change wxWebRequest and related objects to hide ref counting
Don't force the application code to deal with wxObjectDataPtr<> or,
worse, calling {Inc,Dec}Ref() manually by hiding it inside the wx
objects themselves and giving the value-like semantics to them.

There should be no real changes in the behaviour, but the API does
change significantly. Notably, wxWebRequest is not a wxEvtHandler itself
any longer, as this would be incompatible with the value semantics, and
an event handler needs to be specified when creating it, so that it
could be notified about the request state changes.
2020-12-30 02:02:20 +01:00
Vadim Zeitlin
71d5729171 Make wxWebSessionFactory private
Having wxWebSessionFactory part of the public API implies keeping
compatibility with the possible ways of implementing it which is too
restrictive for no good reason, so move this class to the private header
and don't document it nor wxWebSession::RegisterFactory() (which is now
private).
2020-12-27 01:03:08 +01:00
Vadim Zeitlin
e5bd5a926c Move backend-specific wxWebRequest headers to private subdirs
There is no need to make these headers public and keeping them private
will allow making backwards-incompatible changes to them in the future.
2020-12-26 17:00:07 +01:00
PB
a6d4799de9 Remove BCC-specific conditionally compiled code 2020-10-13 18:40:31 +02:00
Pavel Tyunin
13700025be Add wx/private/unicode.h 2020-10-07 15:18:17 +03:00
Vadim Zeitlin
434faa39e6 Remove unused wxDisplayImpl::GetSizeMM()
This is not needed any longer after the changes of the last commit.

Note that the (still existent) public wxGetDisplaySizeMM() didn't use
this function, but used PPI instead.
2020-08-15 00:28:32 +02:00
Vadim Zeitlin
bcb101b9e9 Simplify PPI and scale factor handling in wxDisplay
Don't try computing the PPI ourselves from the physical size and the
number of pixels, this doesn't work and nobody else does it like this.

Just assume that we're using standard PPI by default and use
toolkit-specific functions for the platforms with support for high DPI.
2020-08-15 00:28:32 +02:00
Arrigo Marchiori
c86bcf962d Use wxASCII_STR() on string literals
Fix the build with wxNO_IMPLICIT_WXSTRING_ENCODING.
2020-07-17 17:52:16 +02:00
Vadim Zeitlin
2280e43fe9 Factor out wxTextMeasureBase::GetEmptyLineHeight()
No real changes, just refactor to extract a trivial helper function.
2020-07-15 01:16:23 +02:00
Artur Wieczorek
ae1e93cbae Don't allow wxSpinCtrl range to include negative values if base != 10 (wxMSW)
In a native up-down control hexadecimal numbers are always unsigned (see
UDM_SETBASE message documentation) so we need to prevent:
- Setting a range including negative values if base == 16.
- Setting base != 10 if current range includes negative values.

See #18805.
2020-07-12 19:58:30 +02:00
Vadim Zeitlin
d7f19ee610 Fix spelling in comments and documentation using codespell
Apply the utility from https://github.com/codespell-project/codespell/
to fix spelling issues in the headers under both include and interface
directories and add a file with a couple of exceptions.

The exact command line used was:

    $ codespell -w -I misc/scripts/codespell.ignore -i 3 in*
2020-06-27 22:56:22 +02:00
Paul Cornett
896512c732 Change fractional point size from float to double
There doesn't seem to be any compelling reason to use float. Using double
is simpler, and avoids otherwise unnecessary float<->double conversions.
2020-04-21 09:00:04 -07:00
Vadim Zeitlin
b08db49bf6 Make wxAnimationImpl private and get rid of wxAnimationImplType
Simplify and streamline animation classes relationship: wxAnimation is
the only public class representing an animation and it can be created by
both the native wxAnimationCtrl and wxGenericAnimationCtrl using the new
public CreateAnimation() method.

Replace wxAnimationImplType enum with more flexible type info based
check.
2020-04-06 01:00:15 +02:00
Vadim Zeitlin
789858a4d9 Merge branch 'secret-service-check'
Check if secret service can be used under Unix.

See https://github.com/wxWidgets/wxWidgets/pull/1733
2020-02-11 22:36:03 +01:00
Vadim Zeitlin
5a454d373b Optionally return error message from wxSecretStore::IsOk()
This allows to give at least some explanation about why the secrets
can't be stored to the user, e.g. they could search for a message such
as

The name org.freedesktop.secrets was not provided by any .service files

to find out that gnome-keyring package needs to be installed on their
system.

Note that this change means that under Unix an attempt to connect to the
secret service is now made when wxSecretStore is constructed and not
just when it's used for the first time, as before.
2020-02-10 18:23:59 +01:00
Vadim Zeitlin
b7547dbd27 Don't use Hungarian notation for variables
Rename a variable to remove the ugly "sz" prefix.

Also don't use "s_" prefix for non-static variables.
2020-02-05 15:37:27 +01:00
nns52k
24c56a413b Fix string escaping in JS code in wxWebView
For example, a newline was escaped to be a backslash followed by a
newline, but it actually shall be a backslash followed by a character
'n'. It seemed okay with most of codes until in the case that C++ style
comments, i.e. single line comments, in the JavaScript codes. If the
newline characters are not escaped correctly, the JavaScript interpreter
will ignore everything that goes after the single line comments because
the interpreter obviously cannot find the newline where it's supposed to
stop treating codes as comments.
2020-02-05 15:35:17 +01:00
Tobias Taschner
caf9285609 Improved JSON string parsing 2020-01-19 21:32:11 +01:00