| 926 | } |
| 927 | |
| 928 | bool TextDocument::loadAsyncFromURL( const std::string& url, |
| 929 | const Http::Request::FieldTable& headers, |
| 930 | std::function<void( TextDocument*, bool success )> onLoaded, |
| 931 | const Http::Request::ProgressCallback& progressCallback ) { |
| 932 | mLoading = true; |
| 933 | URI uri( url ); |
| 934 | |
| 935 | if ( uri.getScheme().empty() || ( uri.getScheme() != "https" && uri.getScheme() != "http" ) ) { |
| 936 | mLoading = false; |
| 937 | return false; |
| 938 | } |
| 939 | |
| 940 | mLoadingAsync = true; |
| 941 | |
| 942 | Http::getAsync( |
| 943 | [this, onLoaded = std::move( onLoaded ), |
| 944 | uri = std::move( uri )]( const Http&, Http::Request&, Http::Response& response ) { |
| 945 | if ( response.getStatus() <= Http::Response::Ok ) { |
| 946 | std::string path( URI::getTempPathFromURI( uri ) ); |
| 947 | FileSystem::fileWrite( path, (const Uint8*)response.getBody().c_str(), |
| 948 | response.getBody().size() ); |
| 949 | if ( loadFromFile( path ) == LoadStatus::Loaded ) { |
| 950 | setDeleteOnClose( true ); |
| 951 | if ( onLoaded ) |
| 952 | onLoaded( this, true ); |
| 953 | } |
| 954 | } else { |
| 955 | onLoaded( this, false ); |
| 956 | } |
| 957 | mLoading = false; |
| 958 | notifyDocumentLoaded(); |
| 959 | mLoadingAsync = false; |
| 960 | }, |
| 961 | uri, Seconds( 10 ), progressCallback, headers, "", true, Http::getEnvProxyURI() ); |
| 962 | return true; |
| 963 | } |
| 964 | |
| 965 | TextDocument::LoadStatus TextDocument::reload() { |
| 966 | TextDocument::LoadStatus ret = LoadStatus::Failed; |