Add isMainFrame as last argument to WebContents did-fail-load event.

Fixes #5013.
This commit is contained in:
Rob Brackett 2016-04-04 19:24:58 -07:00
parent fa27120429
commit f12f87d6f0
4 changed files with 32 additions and 6 deletions

View file

@ -541,7 +541,12 @@ void WebContents::DidFailProvisionalLoad(
int error_code, int error_code,
const base::string16& error_description, const base::string16& error_description,
bool was_ignored_by_handler) { bool was_ignored_by_handler) {
Emit("did-fail-provisional-load", error_code, error_description, url); bool is_main_frame = !render_frame_host->GetParent();
Emit("did-fail-provisional-load",
error_code,
error_description,
url,
is_main_frame);
} }
void WebContents::DidFailLoad(content::RenderFrameHost* render_frame_host, void WebContents::DidFailLoad(content::RenderFrameHost* render_frame_host,
@ -549,7 +554,12 @@ void WebContents::DidFailLoad(content::RenderFrameHost* render_frame_host,
int error_code, int error_code,
const base::string16& error_description, const base::string16& error_description,
bool was_ignored_by_handler) { bool was_ignored_by_handler) {
Emit("did-fail-load", error_code, error_description, validated_url); bool is_main_frame = !render_frame_host->GetParent();
Emit("did-fail-load",
error_code,
error_description,
validated_url,
is_main_frame);
} }
void WebContents::DidStartLoading() { void WebContents::DidStartLoading() {
@ -705,7 +715,8 @@ void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) {
Emit("did-fail-load", Emit("did-fail-load",
static_cast<int>(net::ERR_INVALID_URL), static_cast<int>(net::ERR_INVALID_URL),
net::ErrorToShortString(net::ERR_INVALID_URL), net::ErrorToShortString(net::ERR_INVALID_URL),
url.possibly_invalid_spec()); url.possibly_invalid_spec(),
true);
return; return;
} }

View file

@ -8,7 +8,7 @@ var requestId = 0
var WEB_VIEW_EVENTS = { var WEB_VIEW_EVENTS = {
'load-commit': ['url', 'isMainFrame'], 'load-commit': ['url', 'isMainFrame'],
'did-finish-load': [], 'did-finish-load': [],
'did-fail-load': ['errorCode', 'errorDescription', 'validatedURL'], 'did-fail-load': ['errorCode', 'errorDescription', 'validatedURL', 'isMainFrame'],
'did-frame-finish-load': ['isMainFrame'], 'did-frame-finish-load': ['isMainFrame'],
'did-start-loading': [], 'did-start-loading': [],
'did-stop-loading': [], 'did-stop-loading': [],

View file

@ -102,21 +102,31 @@ describe('browser-window module', function () {
}) })
it('should emit did-fail-load event for files that do not exist', function (done) { it('should emit did-fail-load event for files that do not exist', function (done) {
w.webContents.on('did-fail-load', function (event, code) { w.webContents.on('did-fail-load', function (event, code, desc, url, isMainFrame) {
assert.equal(code, -6) assert.equal(code, -6)
assert.equal(isMainFrame, true)
done() done()
}) })
w.loadURL('file://a.txt') w.loadURL('file://a.txt')
}) })
it('should emit did-fail-load event for invalid URL', function (done) { it('should emit did-fail-load event for invalid URL', function (done) {
w.webContents.on('did-fail-load', function (event, code, desc) { w.webContents.on('did-fail-load', function (event, code, desc, url, isMainFrame) {
assert.equal(desc, 'ERR_INVALID_URL') assert.equal(desc, 'ERR_INVALID_URL')
assert.equal(code, -300) assert.equal(code, -300)
assert.equal(isMainFrame, true)
done() done()
}) })
w.loadURL('http://example:port') w.loadURL('http://example:port')
}) })
it('should set `mainFrame = false` on did-fail-load events in iframes', function (done) {
w.webContents.on('did-fail-load', function (event, code, desc, url, isMainFrame) {
assert.equal(isMainFrame, false)
done()
})
w.loadURL('file://' + path.join(fixtures, 'api', 'did-fail-load-iframe.html'))
})
}) })
describe('BrowserWindow.show()', function () { describe('BrowserWindow.show()', function () {

View file

@ -0,0 +1,5 @@
<html>
<body>
<iframe src="file://a.txt"></iframe>
</body>
</html>