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(
|
||||
std::unique_ptr<storage::BlobDataHandle> blob_data_handle,
|
||||
std::shared_ptr<storage::BlobReader> blob_reader,
|
||||
const Session::BlobDataCallback& completion_callback,
|
||||
int result) {
|
||||
|
@ -383,19 +382,36 @@ void DidCalculateBlobSize(
|
|||
callback.Run(bytes_read);
|
||||
}
|
||||
|
||||
void GetBlobDataForUUIDInIO(
|
||||
const std::string& uuid,
|
||||
void GetBlobDataInIO(
|
||||
const std::string& identifier,
|
||||
Session::BlobIdType type,
|
||||
content::ChromeBlobStorageContext* blob_context,
|
||||
storage::FileSystemContext* file_system_context,
|
||||
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(
|
||||
file_system_context,
|
||||
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE).get());
|
||||
std::shared_ptr<storage::BlobReader>
|
||||
shared_blob_reader(blob_reader.release());
|
||||
auto callback = base::Bind(&DidCalculateBlobSize,
|
||||
base::Passed(&blob_data_handle),
|
||||
shared_blob_reader,
|
||||
completion_callback);
|
||||
storage::BlobReader::Status size_status =
|
||||
|
@ -578,17 +594,33 @@ std::string Session::GetUserAgent() {
|
|||
return browser_context_->GetUserAgent();
|
||||
}
|
||||
|
||||
void Session::GetBlobDataForUUID(
|
||||
const std::string& uuid,
|
||||
const BlobDataCallback& callback) {
|
||||
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");
|
||||
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::GetFor(browser_context());
|
||||
storage::FileSystemContext* file_system_context =
|
||||
content::BrowserContext::GetStoragePartition(
|
||||
browser_context(), nullptr)->GetFileSystemContext();
|
||||
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
||||
base::Bind(&GetBlobDataForUUIDInIO,
|
||||
uuid,
|
||||
base::Bind(&GetBlobDataInIO,
|
||||
identifier,
|
||||
type,
|
||||
blob_context,
|
||||
file_system_context,
|
||||
callback));
|
||||
|
@ -676,7 +708,7 @@ void Session::BuildPrototype(v8::Isolate* isolate,
|
|||
&Session::AllowNTLMCredentialsForDomains)
|
||||
.SetMethod("setUserAgent", &Session::SetUserAgent)
|
||||
.SetMethod("getUserAgent", &Session::GetUserAgent)
|
||||
.SetMethod("getBlobDataForUUID", &Session::GetBlobDataForUUID)
|
||||
.SetMethod("getBlobData", &Session::GetBlobData)
|
||||
.SetProperty("cookies", &Session::Cookies)
|
||||
.SetProperty("protocol", &Session::Protocol)
|
||||
.SetProperty("webRequest", &Session::WebRequest);
|
||||
|
|
|
@ -45,6 +45,11 @@ class Session: public mate::TrackableObject<Session>,
|
|||
STATS,
|
||||
};
|
||||
|
||||
enum class BlobIdType {
|
||||
PUBLIC_URL,
|
||||
UUID,
|
||||
};
|
||||
|
||||
// Gets or creates Session from the |browser_context|.
|
||||
static mate::Handle<Session> CreateFrom(
|
||||
v8::Isolate* isolate, AtomBrowserContext* browser_context);
|
||||
|
@ -77,8 +82,7 @@ class Session: public mate::TrackableObject<Session>,
|
|||
void AllowNTLMCredentialsForDomains(const std::string& domains);
|
||||
void SetUserAgent(const std::string& user_agent, mate::Arguments* args);
|
||||
std::string GetUserAgent();
|
||||
void GetBlobDataForUUID(const std::string& uuid,
|
||||
const BlobDataCallback& calback);
|
||||
void GetBlobData(mate::Arguments* args);
|
||||
v8::Local<v8::Value> Cookies(v8::Isolate* isolate);
|
||||
v8::Local<v8::Value> Protocol(v8::Isolate* isolate);
|
||||
v8::Local<v8::Value> WebRequest(v8::Isolate* isolate);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue