fix: don't emit did-fail-load for MediaDocuments (#37824)

* fix: don't emit did-fail-load for MediaDocuments

* spec: add test
This commit is contained in:
Shelley Vohr 2023-04-06 10:23:34 +02:00 committed by GitHub
parent 6bfef67aae
commit 251e567eff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 0 deletions

View file

@ -64,6 +64,7 @@
#include "gin/handle.h"
#include "gin/object_template_builder.h"
#include "gin/wrappable.h"
#include "media/base/mime_util.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
@ -1762,6 +1763,16 @@ void WebContents::DidFinishLoad(content::RenderFrameHost* render_frame_host,
void WebContents::DidFailLoad(content::RenderFrameHost* render_frame_host,
const GURL& url,
int error_code) {
// See DocumentLoader::StartLoadingResponse() - when we navigate to a media
// resource the original request for the media resource, which resulted in a
// committed navigation, is simply discarded. The media element created
// inside the MediaDocument then makes *another new* request for the same
// media resource.
bool is_media_document =
media::IsSupportedMediaMimeType(web_contents()->GetContentsMimeType());
if (error_code == net::ERR_ABORTED && is_media_document)
return;
bool is_main_frame = !render_frame_host->GetParent();
int frame_process_id = render_frame_host->GetProcess()->GetID();
int frame_routing_id = render_frame_host->GetRoutingID();

View file

@ -377,6 +377,15 @@ describe('BrowserWindow module', () => {
expect(code).to.equal(-300);
expect(isMainFrame).to.equal(true);
});
it('should not emit did-fail-load for a successfully loaded media file', async () => {
w.webContents.on('did-fail-load', () => {
expect.fail('did-fail-load should not emit on media file loads');
});
const mediaStarted = once(w.webContents, 'media-started-playing');
w.loadFile(path.join(fixtures, 'cat-spin.mp4'));
await mediaStarted;
});
it('should set `mainFrame = false` on did-fail-load events in iframes', async () => {
const didFailLoad = once(w.webContents, 'did-fail-load');
w.loadFile(path.join(fixtures, 'api', 'did-fail-load-iframe.html'));

BIN
spec/fixtures/cat-spin.mp4 vendored Normal file

Binary file not shown.