2012-08-29 22:11:26 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
2010-09-13 03:59:43 +02:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
#include "libcef/browser_webblobregistry_impl.h"
|
2010-09-13 03:59:43 +02:00
|
|
|
|
2011-10-20 22:34:13 +02:00
|
|
|
#include "base/bind.h"
|
2010-09-13 03:59:43 +02:00
|
|
|
#include "base/message_loop.h"
|
|
|
|
#include "googleurl/src/gurl.h"
|
2011-12-21 19:35:55 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebBlobData.h"
|
2011-12-16 15:51:10 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
|
2012-11-06 18:13:58 +01:00
|
|
|
#include "webkit/base/file_path_string_conversions.h"
|
2010-09-13 03:59:43 +02:00
|
|
|
#include "webkit/blob/blob_data.h"
|
|
|
|
#include "webkit/blob/blob_storage_controller.h"
|
|
|
|
|
|
|
|
using WebKit::WebBlobData;
|
|
|
|
using WebKit::WebURL;
|
2011-10-20 22:34:13 +02:00
|
|
|
using webkit_blob::BlobData;
|
2010-09-13 03:59:43 +02:00
|
|
|
|
2010-10-15 20:37:25 +02:00
|
|
|
namespace {
|
|
|
|
|
2010-09-13 03:59:43 +02:00
|
|
|
MessageLoop* g_io_thread;
|
|
|
|
webkit_blob::BlobStorageController* g_blob_storage_controller;
|
|
|
|
|
2012-08-29 22:11:26 +02:00
|
|
|
// Creates a new BlobData from WebBlobData.
|
|
|
|
BlobData* NewBlobData(const WebBlobData& data) {
|
|
|
|
BlobData* blob = new BlobData;
|
|
|
|
size_t i = 0;
|
|
|
|
WebBlobData::Item item;
|
|
|
|
while (data.itemAt(i++, item)) {
|
|
|
|
switch (item.type) {
|
|
|
|
case WebBlobData::Item::TypeData:
|
|
|
|
if (!item.data.isEmpty()) {
|
|
|
|
// WebBlobData does not allow partial data.
|
|
|
|
DCHECK(!item.offset && item.length == -1);
|
|
|
|
blob->AppendData(item.data);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WebBlobData::Item::TypeFile:
|
|
|
|
if (item.length) {
|
|
|
|
blob->AppendFile(
|
2012-11-06 18:13:58 +01:00
|
|
|
webkit_base::WebStringToFilePath(item.filePath),
|
2012-08-29 22:11:26 +02:00
|
|
|
static_cast<uint64>(item.offset),
|
|
|
|
static_cast<uint64>(item.length),
|
|
|
|
base::Time::FromDoubleT(item.expectedModificationTime));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WebBlobData::Item::TypeBlob:
|
|
|
|
if (item.length) {
|
|
|
|
blob->AppendBlob(
|
|
|
|
item.blobURL,
|
|
|
|
static_cast<uint64>(item.offset),
|
|
|
|
static_cast<uint64>(item.length));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NOTREACHED();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
blob->set_content_type(data.contentType().utf8().data());
|
|
|
|
blob->set_content_disposition(data.contentDisposition().utf8().data());
|
|
|
|
return blob;
|
|
|
|
}
|
|
|
|
|
2010-10-15 20:37:25 +02:00
|
|
|
} // namespace
|
|
|
|
|
2010-09-13 03:59:43 +02:00
|
|
|
/* static */
|
|
|
|
void BrowserWebBlobRegistryImpl::InitializeOnIOThread(
|
|
|
|
webkit_blob::BlobStorageController* blob_storage_controller) {
|
|
|
|
g_io_thread = MessageLoop::current();
|
|
|
|
g_blob_storage_controller = blob_storage_controller;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
void BrowserWebBlobRegistryImpl::Cleanup() {
|
|
|
|
g_io_thread = NULL;
|
|
|
|
g_blob_storage_controller = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
BrowserWebBlobRegistryImpl::BrowserWebBlobRegistryImpl() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebBlobRegistryImpl::registerBlobURL(
|
|
|
|
const WebURL& url, WebBlobData& data) {
|
|
|
|
DCHECK(g_io_thread);
|
2011-10-20 22:34:13 +02:00
|
|
|
GURL thread_safe_url = url; // WebURL uses refcounted strings.
|
|
|
|
g_io_thread->PostTask(FROM_HERE, base::Bind(
|
|
|
|
&BrowserWebBlobRegistryImpl::AddFinishedBlob, this,
|
2012-08-29 22:11:26 +02:00
|
|
|
thread_safe_url, make_scoped_refptr(NewBlobData(data))));
|
2010-09-13 03:59:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebBlobRegistryImpl::registerBlobURL(
|
|
|
|
const WebURL& url, const WebURL& src_url) {
|
|
|
|
DCHECK(g_io_thread);
|
2011-10-20 22:34:13 +02:00
|
|
|
GURL thread_safe_url = url;
|
|
|
|
GURL thread_safe_src_url = src_url;
|
|
|
|
g_io_thread->PostTask(FROM_HERE, base::Bind(
|
|
|
|
&BrowserWebBlobRegistryImpl::CloneBlob, this,
|
|
|
|
thread_safe_url, thread_safe_src_url));
|
2010-09-13 03:59:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebBlobRegistryImpl::unregisterBlobURL(const WebURL& url) {
|
|
|
|
DCHECK(g_io_thread);
|
2011-10-20 22:34:13 +02:00
|
|
|
GURL thread_safe_url = url;
|
|
|
|
g_io_thread->PostTask(FROM_HERE, base::Bind(
|
|
|
|
&BrowserWebBlobRegistryImpl::RemoveBlob, this,
|
|
|
|
thread_safe_url));
|
2010-09-13 03:59:43 +02:00
|
|
|
}
|
|
|
|
|
2012-05-23 21:01:04 +02:00
|
|
|
BrowserWebBlobRegistryImpl::~BrowserWebBlobRegistryImpl() {
|
|
|
|
}
|
|
|
|
|
2011-10-20 22:34:13 +02:00
|
|
|
void BrowserWebBlobRegistryImpl::AddFinishedBlob(
|
|
|
|
const GURL& url, BlobData* blob_data) {
|
2010-09-13 03:59:43 +02:00
|
|
|
DCHECK(g_blob_storage_controller);
|
2011-10-20 22:34:13 +02:00
|
|
|
g_blob_storage_controller->AddFinishedBlob(url, blob_data);
|
2010-09-13 03:59:43 +02:00
|
|
|
}
|
|
|
|
|
2011-10-20 22:34:13 +02:00
|
|
|
void BrowserWebBlobRegistryImpl::CloneBlob(
|
2010-09-13 03:59:43 +02:00
|
|
|
const GURL& url, const GURL& src_url) {
|
|
|
|
DCHECK(g_blob_storage_controller);
|
2011-10-20 22:34:13 +02:00
|
|
|
g_blob_storage_controller->CloneBlob(url, src_url);
|
2010-09-13 03:59:43 +02:00
|
|
|
}
|
|
|
|
|
2011-10-20 22:34:13 +02:00
|
|
|
void BrowserWebBlobRegistryImpl::RemoveBlob(const GURL& url) {
|
2010-09-13 03:59:43 +02:00
|
|
|
DCHECK(g_blob_storage_controller);
|
2011-10-20 22:34:13 +02:00
|
|
|
g_blob_storage_controller->RemoveBlob(url);
|
2010-09-13 03:59:43 +02:00
|
|
|
}
|