protocol: provide blob uuid with uploadData #6941

Merged
merged 7 commits into from Sep 16, 2016

Projects

None yet

2 participants

@deepak1556
Member

Also adds a generic way to access blob data in the main process from either public blob url or uuid.

Fixes #6894

@zcbenz zcbenz commented on an outdated diff Aug 24, 2016
docs/api/session.md
@@ -504,6 +512,7 @@ The `uploadData` is an array of `data` objects:
* `data` Object
* `bytes` Buffer - Content being sent.
* `file` String - Path of file being uploaded.
+ * `blobUUID` String - UUID of blob data.
@zcbenz
zcbenz Aug 24, 2016 edited Contributor

It can probably be a blob object that has a method to get length and read the data.

EDIT: Due to how the webRequest API is implemented by sending objects through threads, we think it does not worth the efforts.

@zcbenz zcbenz commented on an outdated diff Aug 29, 2016
atom/browser/api/atom_api_session.h
enum class CacheAction {
CLEAR,
STATS,
};
+ enum class BlobIdType {
+ PUBLIC_URL,
@zcbenz
zcbenz Aug 29, 2016 Contributor

Only supporting UUID should be enough, I don't think users would use the API to read from a blob URL.

@zcbenz zcbenz commented on an outdated diff Aug 29, 2016
atom/browser/api/atom_api_session.cc
@@ -504,6 +594,38 @@ std::string Session::GetUserAgent() {
return browser_context_->GetUserAgent();
}
+void Session::GetBlobData(mate::Arguments* args) {
+ std::string identifier;
+ BlobDataCallback callback;
+ BlobIdType type = BlobIdType::UUID;
+ if (!args->GetNext(&identifier)) {
+ args->ThrowError("Must pass uuid or public url");
@zcbenz
zcbenz Aug 29, 2016 Contributor

Errors should be passed in callback since the API requires passing a callback.

@zcbenz zcbenz commented on an outdated diff Aug 29, 2016
atom/browser/api/atom_api_session.cc
@@ -330,6 +341,85 @@ void OnClearStorageDataDone(const base::Closure& callback) {
callback.Run();
}
+void DidReadBlobData(const scoped_refptr<net::IOBuffer>& blob_data,
+ const Session::BlobDataCallback& completion_callback,
+ int bytes_read) {
+ std::unique_ptr<base::BinaryValue> result(
@zcbenz
zcbenz Aug 29, 2016 Contributor

Converting BinaryValue to Buffer will trigger a copy of the data, which is unnecessary since the data is already copied here. A more efficient way is to use the copied data to construct Buffer directly.

An example can be found at chromium_src/chrome/browser/printing/print_preview_message_handler.cc.

@zcbenz zcbenz commented on an outdated diff Aug 29, 2016
atom/browser/api/atom_api_session.cc
+ blob_context->context()->GetBlobDataFromUUID(identifier);
+ }
+
+ if (!blob_data_handle) {
+ std::unique_ptr<base::BinaryValue> dummy(new base::BinaryValue());
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ base::Bind(&RunBlobDataCallback,
+ completion_callback,
+ base::Passed(&dummy)));
+ return;
+ }
+
+ auto blob_reader = blob_data_handle->CreateReader(
+ file_system_context,
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE).get());
+ std::shared_ptr<storage::BlobReader>
@zcbenz
zcbenz Aug 29, 2016 Contributor

Moving the pointer from unique_ptr to shared_ptr usually means a bad design, you can add a helper class to put all blob reading methods there.

@deepak1556
Member

Have made the changes, thanks!

@zcbenz
Contributor
zcbenz commented Sep 16, 2016

👍

@zcbenz zcbenz merged commit 9714348 into electron:master Sep 16, 2016

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@aluxian-huginn aluxian-huginn referenced this pull request in Aluxian/Messenger-for-Desktop Sep 22, 2016
Closed

Update dependency: electron v1.4.1 #648

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment