@@ -244,7 +244,15 @@ namespace flutter_inappwebview_plugin
244
244
auto isResponseStage = requestPausedData.contains (" responseStatusCode" );
245
245
auto frameId = requestPausedData.at (" frameId" ).get <std::string>();
246
246
247
- auto allowRequest = [this , requestId]()
247
+ auto request = requestPausedData.at (" request" ).get <nlohmann::json>();
248
+ std::optional<std::string> url = request.at (" url" ).is_string () ? request.at (" url" ).get <std::string>() : std::optional<std::string>{};
249
+ std::optional<std::string> urlFragment = request.contains (" urlFragment" ) && request.at (" urlFragment" ).is_string () ? request.at (" urlFragment" ).get <std::string>() : std::optional<std::string>{};
250
+ if (url.has_value () && urlFragment.has_value ()) {
251
+ url = url.value () + urlFragment.value ();
252
+ }
253
+ auto isForMainFrame = pageFrameId_.empty () || string_equals (pageFrameId_, frameId);
254
+
255
+ auto allowRequest = [this , requestId, url, isForMainFrame]()
248
256
{
249
257
failedAndLog (webView->CallDevToolsProtocolMethod (L" Fetch.continueRequest" ,
250
258
utf8_to_wide (" {\" requestId\" :\" " + requestId + " \" }" ).c_str (),
@@ -255,6 +263,13 @@ namespace flutter_inappwebview_plugin
255
263
return S_OK;
256
264
}
257
265
).Get ()));
266
+
267
+ if (channelDelegate && isForMainFrame) {
268
+ // if shouldOverrideUrlLoading is used, then call onLoadStart and onProgressChanged here
269
+ // to match the behaviour of the other platforms
270
+ channelDelegate->onLoadStart (url);
271
+ channelDelegate->onProgressChanged (0 );
272
+ }
258
273
};
259
274
260
275
auto cancelRequest = [this , requestId]()
@@ -271,12 +286,6 @@ namespace flutter_inappwebview_plugin
271
286
};
272
287
273
288
if (!isResponseStage && channelDelegate && settings->useShouldOverrideUrlLoading && string_equals (resourceType, " Document" )) {
274
- auto request = requestPausedData.at (" request" ).get <nlohmann::json>();
275
- std::optional<std::string> url = request.at (" url" ).is_string () ? request.at (" url" ).get <std::string>() : std::optional<std::string>{};
276
- std::optional<std::string> urlFragment = request.contains (" urlFragment" ) && request.at (" urlFragment" ).is_string () ? request.at (" urlFragment" ).get <std::string>() : std::optional<std::string>{};
277
- if (url.has_value () && urlFragment.has_value ()) {
278
- url = url.value () + urlFragment.value ();
279
- }
280
289
std::optional<std::string> method = request.at (" method" ).is_string () ? request.at (" method" ).get <std::string>() : std::optional<std::string>{};
281
290
std::optional<std::map<std::string, std::string>> headers = request.at (" headers" ).is_object () ? request.at (" headers" ).get <std::map<std::string, std::string>>() : std::optional<std::map<std::string, std::string>>{};
282
291
std::optional<std::string> redirectedRequestId = request.contains (" redirectedRequestId" ) && request.at (" redirectedRequestId" ).is_string () ? request.at (" redirectedRequestId" ).get <std::string>() : std::optional<std::string>{};
@@ -311,8 +320,6 @@ namespace flutter_inappwebview_plugin
311
320
312
321
std::optional<NavigationActionType> navigationType = isRedirect ? NavigationActionType::other : std::optional<NavigationActionType>{};
313
322
314
- auto isForMainFrame = pageFrameId_.empty () || string_equals (pageFrameId_, frameId);
315
-
316
323
auto urlRequest = std::make_shared<URLRequest>(url, method, headers, body);
317
324
auto navigationAction = std::make_shared<NavigationAction>(
318
325
urlRequest,
@@ -345,7 +352,8 @@ namespace flutter_inappwebview_plugin
345
352
channelDelegate->shouldOverrideUrlLoading (std::move (navigationAction), std::move (callback));
346
353
}
347
354
else {
348
- // check if a custom event listener is found and give the opportunity to it to handle the request
355
+ // check if a custom event listener is found and give back the opportunity to it to handle the request
356
+ // through the Chrome Dev Protocol API
349
357
if (!map_contains (devToolsProtocolEventListener_, std::string (" Fetch.requestPaused" ))) {
350
358
// if a custom event listener is not found, continue the request
351
359
allowRequest ();
@@ -449,8 +457,11 @@ namespace flutter_inappwebview_plugin
449
457
navigationActions_.insert ({ navigationId, navigationAction });
450
458
}
451
459
452
- channelDelegate->onLoadStart (url);
453
- channelDelegate->onProgressChanged (0 );
460
+ // if shouldOverrideUrlLoading is not used, then call onLoadStart and onProgressChanged here
461
+ if (!settings->useShouldOverrideUrlLoading ) {
462
+ channelDelegate->onLoadStart (url);
463
+ channelDelegate->onProgressChanged (0 );
464
+ }
454
465
args->put_Cancel (false );
455
466
456
467
return S_OK;
0 commit comments