2
* Copyright 2010 Google Inc.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
// Author: jmaessen@google.com (Jan Maessen)
19
// An input resource representing a data: url. This is uncommon in web
20
// pages, but we generate these urls as a result of image inlining and
21
// this confuses subsequent filters in certain cases.
23
#include "net/instaweb/http/public/request_context.h"
24
#include "net/instaweb/rewriter/public/resource.h"
25
#include "net/instaweb/util/public/basictypes.h"
26
#include "net/instaweb/util/public/data_url.h"
27
#include "net/instaweb/util/public/scoped_ptr.h"
28
#include "net/instaweb/util/public/string.h"
29
#include "net/instaweb/util/public/string_util.h"
31
#ifndef NET_INSTAWEB_REWRITER_PUBLIC_DATA_URL_INPUT_RESOURCE_H_
32
#define NET_INSTAWEB_REWRITER_PUBLIC_DATA_URL_INPUT_RESOURCE_H_
34
namespace net_instaweb {
42
class DataUrlInputResource : public Resource {
44
// We expose a factory; parse failure returns NULL.
45
static ResourcePtr Make(const StringPiece& url, const RewriteDriver* driver) {
47
const ContentType* type;
49
StringPiece encoded_contents;
50
// We create the local copy of the url early, because
51
// encoded_contents will in general be a substring of this
52
// local copy and must have the same lifetime.
53
GoogleString* url_copy = new GoogleString();
54
url.CopyToString(url_copy);
55
if (ParseDataUrl(*url_copy, &type, &encoding, &encoded_contents)) {
56
resource.reset(new DataUrlInputResource(url_copy, encoding, type,
57
encoded_contents, driver));
62
virtual ~DataUrlInputResource();
64
virtual bool IsValidAndCacheable() const;
66
// Set OutputPartition's input info used for expiration validation.
67
virtual void FillInPartitionInputInfo(HashHint include_content_hash,
70
virtual GoogleString url() const { return *url_.get(); }
72
virtual bool UseHttpCache() const { return false; }
75
virtual void LoadAndCallback(NotCacheablePolicy not_cacheable_policy,
76
const RequestContextPtr& request_context,
77
AsyncCallback* callback);
80
DataUrlInputResource(const GoogleString* url,
82
const ContentType* type,
83
const StringPiece& encoded_contents,
84
const RewriteDriver* driver);
86
scoped_ptr<const GoogleString> url_;
87
const Encoding encoding_;
88
const StringPiece encoded_contents_; // substring of url.
89
GoogleString decoded_contents_;
91
DISALLOW_COPY_AND_ASSIGN(DataUrlInputResource);
94
} // namespace net_instaweb
96
#endif // NET_INSTAWEB_REWRITER_PUBLIC_DATA_URL_INPUT_RESOURCE_H_