New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: lost window.opener after cross-origin navigation #18173
Merged
MarshallOfSound
merged 7 commits into
electron:master
from
alexstrat:fix/window-opener-cross-site-navigation
Jun 3, 2019
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f3de585
Get a site instance related to current one instead of creation a new one
alexstrat e239973
Some relies on preloads in opened window
alexstrat 48b0c6c
Add a test on window.opener after cross-orgin navigation
alexstrat 9dbf9de
Make sure to unregisterProtocol in tests
alexstrat 4cbbc08
Introduc and use a NetworkSandbox for tests
alexstrat 1f6bae3
Modify tests about zoom persistence to properly simulate cross-origin…
alexstrat 6b2f4ca
Revert "Modify tests about zoom persistence to properly simulate cros…
alexstrat File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
const fs = require('fs') | ||
|
||
/** | ||
* Test sandbox environment used to fake network responses. | ||
*/ | ||
class NetworkSandbox { | ||
constructor (protocol) { | ||
this.protocol = protocol | ||
this._resetFns = [] | ||
} | ||
|
||
/** | ||
* Reset the sandbox. | ||
*/ | ||
async reset () { | ||
for (const resetFn of this._resetFns) { | ||
await resetFn() | ||
} | ||
this._resetFns = [] | ||
} | ||
|
||
/** | ||
* Will serve the content of file at `filePath` to network requests towards | ||
* `protocolName` scheme. | ||
* | ||
* Example: `sandbox.serveFileFromProtocol('foo', 'index.html')` will serve the content | ||
* of 'index.html' to `foo://page` requests. | ||
* | ||
* @param {string} protocolName | ||
* @param {string} filePath | ||
*/ | ||
serveFileFromProtocol (protocolName, filePath) { | ||
return new Promise((resolve, reject) => { | ||
this.protocol.registerBufferProtocol(protocolName, (request, callback) => { | ||
// Disabled due to false positive in StandardJS | ||
// eslint-disable-next-line standard/no-callback-literal | ||
callback({ | ||
mimeType: 'text/html', | ||
data: fs.readFileSync(filePath) | ||
}) | ||
}, (error) => { | ||
if (error != null) { | ||
reject(error) | ||
} else { | ||
this._resetFns.push(() => this.unregisterProtocol(protocolName)) | ||
resolve() | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
unregisterProtocol (protocolName) { | ||
return new Promise((resolve, reject) => { | ||
this.protocol.unregisterProtocol(protocolName, (error) => { | ||
if (error != null) { | ||
reject(error) | ||
} else { | ||
resolve() | ||
} | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
/** | ||
* Will create a NetworkSandbox that uses | ||
* `protocol` as `Electron.Protocol`. | ||
* | ||
* @param {Electron.Protocol} protocol | ||
*/ | ||
function createNetworkSandbox (protocol) { | ||
return new NetworkSandbox(protocol) | ||
} | ||
|
||
exports.createNetworkSandbox = createNetworkSandbox |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't this use
GetSiteInstanceForURL
in the existing browsing instance ?browsing_instance_->GetSiteInstanceForURL(url, false /* allow_default_instance */);
with the current implementation in the PR, any call to create the site instance for same url will go untracked by the site instance map maintained by browsing instance. I don't see an issue with reusing the site instance from the browsing instance, since we are maintaining a 1:1 relation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
browsing_instance_->GetSiteInstanceForURL
is equivalent to the first suggestion of this PR.As discussed earlier in the thread, it can't work because, for the same URL (during a reload for instance), we'll end up reusing the same
SiteInstance
, and, as a result, the render process won't be restarted — in opposition to what is expected.I'm not sure because in
CreateSiteInstanceForURL
, I callinstance->SetSite
that callsRegisterSiteInstance
which adds theSiteInstance
to thesite_instance_map_
of browsing instance.Even if we did not register it, I don't see any issue with that so far, since we want to use new SiteInstance every time.
As I understood with @zcbenz , reusing the site instance will not trigger render process restart which is an issue. Maybe I have not understood this last sentence @deepak1556 though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we need to restart process. Regarding the site instance map statement, when using
GetSiteInstanceForURL
it will either create a new instance for the url, add it to the map and return it, otherwise return an existing one from the map. With this PR implementation, a site instance is created and add to the map but when a new request is made for the same url, it will create the instance but will not add it to the map, check the condition inBrowsingInstance::RegisterSiteInstance
. I was concerned about this.But since we are using the same browser instance makes sense that
GetSiteInstanceForURL
can't be used to force restart the process.