protocol: provide blob uuid with uploadData #6941

merged 7 commits into from Sep 16, 2016


None yet

2 participants


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
@@ -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 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
enum class CacheAction {
+ enum class BlobIdType {
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
@@ -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 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
@@ -330,6 +341,85 @@ void OnClearStorageDataDone(const base::Closure& callback) {
+void DidReadBlobData(const scoped_refptr<net::IOBuffer>& blob_data,
+ const Session::BlobDataCallback& completion_callback,
+ int bytes_read) {
+ std::unique_ptr<base::BinaryValue> result(
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/

@zcbenz zcbenz commented on an outdated diff Aug 29, 2016
+ 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 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.


Have made the changes, thanks!

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
continuous-integration/travis-ci/pr The Travis CI build passed
@aluxian-huginn aluxian-huginn referenced this pull request in Aluxian/Messenger-for-Desktop Sep 22, 2016

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