Skip to content
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

WebTorrent Support #356

Merged
merged 6 commits into from
Aug 31, 2018
Merged

WebTorrent Support #356

merged 6 commits into from
Aug 31, 2018

Conversation

yrliou
Copy link
Member

@yrliou yrliou commented Aug 23, 2018

Fix brave/brave-browser#289.

What's included in this PR:

  • WebTorrent support of magnet links

What's not included in this PR:

Submitter Checklist:

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Ran git rebase -i to squash commits (if needed).
  • Tagged reviewers and labelled the pull request as needed.
  • Request a security/privacy review as needed.
  • Add appropriate QA labels (QA/Needed or QA/No-QA-Needed) to include the closed issue in milestone

Test Plan:

Manual Test:

  1. Open a new tab and visit https://webtorrent.io/free-torrents, click magnet link of Big Buck Bunny should leads to a torrent viewer page without start downloading
  2. Click start download, torrent should start to be downloading
  3. Click any link under save file should be able to download that specific file
  4. Click on poster.jpg, should open a tab and show the image directly
  5. Go back to the torrent downloading page and click on Big Buck Bunny.mp4, should open a tab to stream the media
    (Note: It might take a while for the media to be ready to play.)
  6. Close the media streaming tab and go back to the torrent downloading page
  7. Go back to https://webtorrent.io/free-torrents tab and see if it also works by right click the magnet link to open it in a new tab

Automation Test:
npm run test -- brave_browser_tests --filter=BraveContentBrowserClientTest.RewriteMagnetURL*
npm run test-unit

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Request a security/privacy review as needed.
  • Adequate test coverage exists to prevent regressions
  • Verify test plan is specified in PR before merging to source

@yrliou yrliou self-assigned this Aug 23, 2018
@yrliou yrliou requested review from bridiver and bbondy August 23, 2018 20:39
}
#endif // !BUILDFLAG(DISABLE_FTP_SUPPORT)

+ job_factory->SetProtocolHandler("magnet", std::make_unique<MagnetProtocolHandler>());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#353 (review)
This review comment is not yet addressed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bridiver Addressed by 3ee9fa7

@yrliou yrliou force-pushed the webtorrent_ext branch 4 times, most recently from b486a2f to a846eae Compare August 26, 2018 19:33
// TODO(devlin): Should we do this for all callbacks?
+ if (!connect_callback_.is_null()) {
+ base::ResetAndReturn(&connect_callback_)
+ .Run(net::ERR_CONNECTION_CLOSED);
Copy link
Member Author

@yrliou yrliou Aug 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solve DCHECK erorr at https://cs.chromium.org/chromium/src/extensions/browser/extension_function.cc?sq=package:chromium&g=0&l=504.
Webtorrent hit the DCHECK where SocketsTcpConnectFunction is destructed before any responses are made.
It happens because it is possible for the application to make a request to destroy the socket while previous connect request is still in progress.
This DCHECK is introduced by https://codereview.chromium.org/2017113002, in the same changeset, read_callback is reset and return immediately here.

@yrliou
Copy link
Member Author

yrliou commented Aug 27, 2018

I'm rebasing on C70, hit a new DCHECK in CreateTCPConnectedSocketCallback, related change: https://chromium.googlesource.com/chromium/src/+/bff8e3ea6d0d7c1f1fe045f595ffaeaf64ff41f9

@yrliou
Copy link
Member Author

yrliou commented Aug 27, 2018

DCHECK for CreateTCPConnectedSocketCallback has been fixed in chromium master, I'll pull it in first. https://chromium.googlesource.com/chromium/src/+/602a66794ef884ce0f961e9c625c649704cfcb83%5E%21/

+ if (connect_callback_) {
+ std::move(connect_callback_)
+ .Run(net::ERR_CONNECTION_CLOSED);
+ }
Copy link
Member Author

@yrliou yrliou Aug 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solve DCHECK erorr at https://cs.chromium.org/chromium/src/extensions/browser/extension_function.cc?sq=package:chromium&g=0&l=504.
Webtorrent hit the DCHECK where SocketsTcpConnectFunction is destructed before any responses are made.
It happens because it is possible for the application to make a request to destroy the socket while the connect request is still in progress.
This DCHECK is introduced by https://codereview.chromium.org/2017113002, in the same changeset, read_callback is reset and return immediately here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is causing SocketsTcpConnectFunction to be destroyed early?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add for accept_callback_ as well as discussed and please submit to upstream

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 360746b


-TCPConnectedSocket::~TCPConnectedSocket() {}
+TCPConnectedSocket::~TCPConnectedSocket() {
+ if (connect_callback_) {
Copy link
Member Author

@yrliou yrliou Aug 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pulling from https://chromium.googlesource.com/chromium/src/+/602a66794ef884ce0f961e9c625c649704cfcb83%5E%21/
This patch should be able to be removed in the next chromium upgrade.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with the upstream patch, but odd that this doesn't call Disconnect?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for CreateTCPConnectedSocketCallback introduced in C70 but not the extension function itself.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this, we'll still hit DCHECK in src/out/Debug/gen/services/network/public/mojom/network_context.mojom.cc,
which checks if CreateTCPConnectedSocketCallback is destructed without respond.

@yrliou yrliou changed the title [WIP] WebTorrent Support WebTorrent Support Aug 27, 2018
@@ -126,7 +127,8 @@ bool BraveExtensionProvider::UserMayLoad(const Extension* extension,

bool BraveExtensionProvider::MustRemainInstalled(const Extension* extension,
base::string16* error) const {
return extension->id() == brave_extension_id;
return extension->id() == brave_extension_id ||
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be here? Do we want it always loaded by default or on user activation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer loaded by default for now if that's OK.
And address it in a follow-up issue to make it able to be turned on and off by user at anytime.

AFAIK, if we want to disable a component extension from UI, it should probably go through chrome://extensions.
First, to see component extensions listed, we'll need to pass --show-component-extension-options when run it.
But it seems I can't toggle the on&off switch even if the component extension is shown for our current version.
I would like to address this in a separate issue.
@bridiver wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, it seems it is still loaded by default even when I remove this line.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't affect default loading, it only affects the ability to uninstall

Copy link
Collaborator

@bridiver bridiver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c++ stuff looks good

Copy link
Contributor

@cezaraugusto cezaraugusto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code comments left, mostly nit. No show-stoppers. Unable to test it manually ATM as I'm still compiling


require('./background/store')
require('./background/events/tabsEvents')
require('./background/events/windowsEvents')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: don't import './background/events/windowsEvents' do the job as well? also init() could go at the bottom

components/brave_webtorrent/extension/manifest.json Outdated Show resolved Hide resolved
@yrliou
Copy link
Member Author

yrliou commented Aug 30, 2018

@cezaraugusto Please review 970343f and a0bb5ec.
I'll do a final rebase tomorrow, and will test builds on all platforms again before merging.
Please leave merge to me, thanks!

cezaraugusto
cezaraugusto previously approved these changes Aug 30, 2018
Copy link
Contributor

@cezaraugusto cezaraugusto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+++++++ for the front-end

@yrliou
Copy link
Member Author

yrliou commented Aug 30, 2018

@bridiver @cezaraugusto Thanks a lot for the review, I'll squash some commits together and merge this PR after I finish testing it on all platforms.

yrliou added 5 commits August 30, 2018 14:20
…onnected.

Solve DCHECK erorr in ~UIThreadExtensionFunction where
SocketsTcpConnectFunction is destructed before any responses were made.
…e run.

This patch is pulling in the solution from https://chromium.googlesource.com/chromium/src/+/602a66794ef884ce0f961e9c625c649704cfcb83%5E%21/
Should be removed when this changeset is pulled in next chromium upgrade.
@yrliou
Copy link
Member Author

yrliou commented Aug 30, 2018

Seems fine on Mac and Linux, waiting on windows build.

@yrliou
Copy link
Member Author

yrliou commented Aug 31, 2018

Run manual and browser tests on all platforms, seems fine, merging.

@yrliou yrliou merged commit e5e2c89 into master Aug 31, 2018
@bbondy
Copy link
Member

bbondy commented Aug 31, 2018

WOOoooo 🎉 and :party_parrot:

@bsclifton bsclifton deleted the webtorrent_ext branch September 1, 2018 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Webtorrent support
4 participants