update api to work on public url and uuid
This commit is contained in:
parent
a23e7ecf8f
commit
d2e40d4fc1
2 changed files with 49 additions and 13 deletions
|
@ -354,7 +354,6 @@ void DidReadBlobData(const scoped_refptr<net::IOBuffer>& blob_data,
|
||||||
}
|
}
|
||||||
|
|
||||||
void DidCalculateBlobSize(
|
void DidCalculateBlobSize(
|
||||||
std::unique_ptr<storage::BlobDataHandle> blob_data_handle,
|
|
||||||
std::shared_ptr<storage::BlobReader> blob_reader,
|
std::shared_ptr<storage::BlobReader> blob_reader,
|
||||||
const Session::BlobDataCallback& completion_callback,
|
const Session::BlobDataCallback& completion_callback,
|
||||||
int result) {
|
int result) {
|
||||||
|
@ -383,19 +382,36 @@ void DidCalculateBlobSize(
|
||||||
callback.Run(bytes_read);
|
callback.Run(bytes_read);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetBlobDataForUUIDInIO(
|
void GetBlobDataInIO(
|
||||||
const std::string& uuid,
|
const std::string& identifier,
|
||||||
|
Session::BlobIdType type,
|
||||||
content::ChromeBlobStorageContext* blob_context,
|
content::ChromeBlobStorageContext* blob_context,
|
||||||
storage::FileSystemContext* file_system_context,
|
storage::FileSystemContext* file_system_context,
|
||||||
const Session::BlobDataCallback& completion_callback) {
|
const Session::BlobDataCallback& completion_callback) {
|
||||||
auto blob_data_handle = blob_context->context()->GetBlobDataFromUUID(uuid);
|
std::unique_ptr<storage::BlobDataHandle> blob_data_handle;
|
||||||
|
if (type == Session::BlobIdType::PUBLIC_URL) {
|
||||||
|
blob_data_handle =
|
||||||
|
blob_context->context()->GetBlobDataFromPublicURL(GURL(identifier));
|
||||||
|
} else if (type == Session::BlobIdType::UUID) {
|
||||||
|
blob_data_handle =
|
||||||
|
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(
|
auto blob_reader = blob_data_handle->CreateReader(
|
||||||
file_system_context,
|
file_system_context,
|
||||||
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE).get());
|
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE).get());
|
||||||
std::shared_ptr<storage::BlobReader>
|
std::shared_ptr<storage::BlobReader>
|
||||||
shared_blob_reader(blob_reader.release());
|
shared_blob_reader(blob_reader.release());
|
||||||
auto callback = base::Bind(&DidCalculateBlobSize,
|
auto callback = base::Bind(&DidCalculateBlobSize,
|
||||||
base::Passed(&blob_data_handle),
|
|
||||||
shared_blob_reader,
|
shared_blob_reader,
|
||||||
completion_callback);
|
completion_callback);
|
||||||
storage::BlobReader::Status size_status =
|
storage::BlobReader::Status size_status =
|
||||||
|
@ -578,17 +594,33 @@ std::string Session::GetUserAgent() {
|
||||||
return browser_context_->GetUserAgent();
|
return browser_context_->GetUserAgent();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::GetBlobDataForUUID(
|
void Session::GetBlobData(mate::Arguments* args) {
|
||||||
const std::string& uuid,
|
std::string identifier;
|
||||||
const BlobDataCallback& callback) {
|
BlobDataCallback callback;
|
||||||
|
BlobIdType type = BlobIdType::UUID;
|
||||||
|
if (!args->GetNext(&identifier)) {
|
||||||
|
args->ThrowError("Must pass uuid or public url");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GURL public_url(identifier);
|
||||||
|
if (public_url.is_valid())
|
||||||
|
type = BlobIdType::PUBLIC_URL;
|
||||||
|
|
||||||
|
if (!args->GetNext(&callback)) {
|
||||||
|
args->ThrowError("Must pass Function");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
content::ChromeBlobStorageContext* blob_context =
|
content::ChromeBlobStorageContext* blob_context =
|
||||||
content::ChromeBlobStorageContext::GetFor(browser_context());
|
content::ChromeBlobStorageContext::GetFor(browser_context());
|
||||||
storage::FileSystemContext* file_system_context =
|
storage::FileSystemContext* file_system_context =
|
||||||
content::BrowserContext::GetStoragePartition(
|
content::BrowserContext::GetStoragePartition(
|
||||||
browser_context(), nullptr)->GetFileSystemContext();
|
browser_context(), nullptr)->GetFileSystemContext();
|
||||||
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
||||||
base::Bind(&GetBlobDataForUUIDInIO,
|
base::Bind(&GetBlobDataInIO,
|
||||||
uuid,
|
identifier,
|
||||||
|
type,
|
||||||
blob_context,
|
blob_context,
|
||||||
file_system_context,
|
file_system_context,
|
||||||
callback));
|
callback));
|
||||||
|
@ -676,7 +708,7 @@ void Session::BuildPrototype(v8::Isolate* isolate,
|
||||||
&Session::AllowNTLMCredentialsForDomains)
|
&Session::AllowNTLMCredentialsForDomains)
|
||||||
.SetMethod("setUserAgent", &Session::SetUserAgent)
|
.SetMethod("setUserAgent", &Session::SetUserAgent)
|
||||||
.SetMethod("getUserAgent", &Session::GetUserAgent)
|
.SetMethod("getUserAgent", &Session::GetUserAgent)
|
||||||
.SetMethod("getBlobDataForUUID", &Session::GetBlobDataForUUID)
|
.SetMethod("getBlobData", &Session::GetBlobData)
|
||||||
.SetProperty("cookies", &Session::Cookies)
|
.SetProperty("cookies", &Session::Cookies)
|
||||||
.SetProperty("protocol", &Session::Protocol)
|
.SetProperty("protocol", &Session::Protocol)
|
||||||
.SetProperty("webRequest", &Session::WebRequest);
|
.SetProperty("webRequest", &Session::WebRequest);
|
||||||
|
|
|
@ -45,6 +45,11 @@ class Session: public mate::TrackableObject<Session>,
|
||||||
STATS,
|
STATS,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class BlobIdType {
|
||||||
|
PUBLIC_URL,
|
||||||
|
UUID,
|
||||||
|
};
|
||||||
|
|
||||||
// Gets or creates Session from the |browser_context|.
|
// Gets or creates Session from the |browser_context|.
|
||||||
static mate::Handle<Session> CreateFrom(
|
static mate::Handle<Session> CreateFrom(
|
||||||
v8::Isolate* isolate, AtomBrowserContext* browser_context);
|
v8::Isolate* isolate, AtomBrowserContext* browser_context);
|
||||||
|
@ -77,8 +82,7 @@ class Session: public mate::TrackableObject<Session>,
|
||||||
void AllowNTLMCredentialsForDomains(const std::string& domains);
|
void AllowNTLMCredentialsForDomains(const std::string& domains);
|
||||||
void SetUserAgent(const std::string& user_agent, mate::Arguments* args);
|
void SetUserAgent(const std::string& user_agent, mate::Arguments* args);
|
||||||
std::string GetUserAgent();
|
std::string GetUserAgent();
|
||||||
void GetBlobDataForUUID(const std::string& uuid,
|
void GetBlobData(mate::Arguments* args);
|
||||||
const BlobDataCallback& calback);
|
|
||||||
v8::Local<v8::Value> Cookies(v8::Isolate* isolate);
|
v8::Local<v8::Value> Cookies(v8::Isolate* isolate);
|
||||||
v8::Local<v8::Value> Protocol(v8::Isolate* isolate);
|
v8::Local<v8::Value> Protocol(v8::Isolate* isolate);
|
||||||
v8::Local<v8::Value> WebRequest(v8::Isolate* isolate);
|
v8::Local<v8::Value> WebRequest(v8::Isolate* isolate);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue