blob: 4afcf8a03c6905b2023356f40eed8f1b1f600064 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "webkit/blob/blob_data.h"
#include "base/logging.h"
#include "base/time.h"
#include "third_party/WebKit/WebKit/chromium/public/WebBlobData.h"
#include "third_party/WebKit/WebKit/chromium/public/WebCString.h"
#include "third_party/WebKit/WebKit/chromium/public/WebData.h"
#include "webkit/glue/webkit_glue.h"
using WebKit::WebBlobData;
using WebKit::WebData;
using WebKit::WebString;
namespace {
// Time::FromDoubleT() does not return empty Time object when dt is 0.
// We have to work around this problem here.
base::Time DoubleTToTime(double dt) {
return dt ? base::Time::FromDoubleT(dt) : base::Time();
}
}
namespace webkit_blob {
BlobData::BlobData(const WebBlobData& data) {
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);
AppendData(item.data);
}
break;
case WebBlobData::Item::TypeFile:
AppendFile(
webkit_glue::WebStringToFilePath(item.filePath),
static_cast<uint64>(item.offset),
static_cast<uint64>(item.length),
DoubleTToTime(item.expectedModificationTime));
break;
case WebBlobData::Item::TypeBlob:
if (item.length) {
AppendBlob(
item.blobURL,
static_cast<uint64>(item.offset),
static_cast<uint64>(item.length));
}
break;
default:
NOTREACHED();
}
}
content_type_= data.contentType().utf8().data();
content_disposition_ = data.contentDisposition().utf8().data();
}
} // namespace webkit_blob
|