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

Added import of links and text content to ipfs #8422

Merged
merged 2 commits into from
Apr 16, 2021
Merged

Conversation

spylogsster
Copy link
Contributor

@spylogsster spylogsster commented Apr 2, 2021

Resolves brave/brave-browser#14769
Resolves brave/brave-browser#15176

  • Added submenu to render context menu
  • Added base import worker which implements importing flow for ipfs: add/mkdir/cp apis should be called sequentially
  • Added http{s} links importer which downloads a link content to file and uploads it to ipfs
  • Added text importer that puts to ipfs a file with passed text, an index for file calculated based on content hash, same text will have same index.
  • Launch ipfs daemon if import called and daemon is turned off
  • Open of ipfs webui page with imported folder
  • Copy to clipboard of shareable link for uploaded content
  • Import calls are proxied through tab helper to have access to chrome/ for opening new tabs when import is finished
  • Pre warm request for shareable link
  • Added notifications, if import successful it opens shareable link, otherwise brave://ipfs

image

image

image

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally: npm run test -- brave_browser_tests, npm run test -- brave_unit_tests, npm run lint, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

  • Import different objects on pages as described in ticket
  • for each imported object should be opened web page from local node webui in case of success with brave import directory
  • for each imported object should be copied shareable link to clipboard which allows to access imported content via public gateway from any other computer
  • please pay attention that if you import different selected texts from same page they should be imported all to different text files with indexes
  • if you import same selected text it should not add new text file to import folder
  • Make sure imported content (link or text) is same as original, try to download file by shareable link it should be same without additional bytes
  • If import successful by click on notification should be opened shareable link, otherwise brave://ipfs-internal

@spylogsster spylogsster requested a review from a team as a code owner April 2, 2021 16:36
@spylogsster spylogsster self-assigned this Apr 2, 2021
@spylogsster spylogsster force-pushed the import-to-ipfs branch 4 times, most recently from b48bbef to 15b1010 Compare April 2, 2021 17:58
@spylogsster spylogsster requested a review from bbondy April 2, 2021 18:06
@spylogsster spylogsster force-pushed the import-to-ipfs branch 10 times, most recently from d9016a4 to 4b10ce9 Compare April 6, 2021 12:10
@spylogsster spylogsster requested a review from bridiver as a code owner April 6, 2021 12:10
@spylogsster spylogsster force-pushed the import-to-ipfs branch 6 times, most recently from 87d09d8 to 78f5840 Compare April 7, 2021 12:33
@spylogsster spylogsster force-pushed the import-to-ipfs branch 4 times, most recently from 80f1769 to e6c64d0 Compare April 8, 2021 21:31
@spylogsster spylogsster force-pushed the import-to-ipfs branch 5 times, most recently from ad4ea71 to 087cb33 Compare April 13, 2021 12:52
@yrliou
Copy link
Member

yrliou commented Apr 14, 2021

@spylogsster Please don't force-push and replace the commit directly during review, I can't see the interdiff using github.
Please push new commits when addressing comments so I could see what has been changed from the previous review round easily, thanks.

@spylogsster spylogsster force-pushed the import-to-ipfs branch 3 times, most recently from 8afe5d7 to e9e28e3 Compare April 15, 2021 11:03
Copy link
Member

@yrliou yrliou left a comment

Choose a reason for hiding this comment

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

LGTM

}

bool IsIpfsMenuEnabled(content::BrowserContext* browser_context) {
return ipfs::IsIpfsEnabled(browser_context) &&
Copy link
Member

Choose a reason for hiding this comment

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

nit: You can just use IsIpfsEnabled(browser_context) && IsLocalGatewayConfigured(browser_context) here.

@bbondy bbondy merged commit 9303c55 into master Apr 16, 2021
@bbondy bbondy deleted the import-to-ipfs branch April 16, 2021 14:36
@bbondy bbondy added this to the 1.25.x - Nightly milestone Apr 16, 2021
base::PostTaskAndReplyWithResult(
io_task_runner_.get(), FROM_HERE,
base::BindOnce(&IpfsImportWorkerBase::CreateResourceRequest,
base::Unretained(this), std::move(blob_builder_callback),
Copy link
Contributor

Choose a reason for hiding this comment

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

Passing Unretained pointers like this is not safe. Fortunately, this function doesn't really need this, so I'd suggest we make it a free function instead of a class method

auto blob_storage_context_getter =
content::BrowserContext::GetBlobStorageContext(browser_context_);
base::PostTaskAndReplyWithResult(
io_task_runner_.get(), FROM_HERE,
Copy link
Contributor

Choose a reason for hiding this comment

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

you can simply do io_task_runner_->PostTaskAndReply...

url_loader_->DownloadToStringOfUnboundedSizeUntilCrashAndDie(
url_loader_factory_.get(),
base::BindOnce(&IpfsImportWorkerBase::OnImportAddComplete,
weak_factory_.GetWeakPtr()));
Copy link
Contributor

Choose a reason for hiding this comment

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

in this case it is safe to use Unretained

io_task_runner_(base::CreateSequencedTaskRunner(
{base::MayBlock(), content::BrowserThread::IO,
base::TaskPriority::BEST_EFFORT,
base::TaskShutdownBehavior::BLOCK_SHUTDOWN})),
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure it really should block the shutdown

auto import_completed_callback =
base::BindOnce(&IpfsService::OnImportFinished, weak_factory_.GetWeakPtr(),
std::move(callback), key);
importers_[key] = std::make_unique<IpfsTextImportWorker>(
Copy link
Contributor

Choose a reason for hiding this comment

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

if IpfsTextImportWorker::StartImportText early returns in case text or host is empty, it will synchronously call the callback, that won't erase the failed importer from the map (because it is not inserted yet), correct? After that it will be inserted and will live in the map forever. So maybe we'd better avoid running complex logic that involves chains of callbacks in constructors

kylehickinson added a commit that referenced this pull request Jan 4, 2024
On iOS 17 rotating the device with a full screen modal presented (e.g. Playlist, Tab Tray) to landscape then back to portrait does not trigger `traitCollectionDidChange`/`willTransition`/etc calls and so the toolbar remains in the wrong state.
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.

Add notifications to imports Add import to IPFS context menu which pins content
6 participants