~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/net/instaweb/rewriter/public/data_url_input_resource.h

  • Committer: Vivian
  • Date: 2015-12-04 18:20:11 UTC
  • Revision ID: git-v1:a36f2bc32e884f7473b3a47040e5411306144d7d
* Do not extract psol.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2010 Google Inc.
3
 
 *
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
7
 
 *
8
 
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 
 *
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.
15
 
 */
16
 
 
17
 
// Author: jmaessen@google.com (Jan Maessen)
18
 
//
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.
22
 
 
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"
30
 
 
31
 
#ifndef NET_INSTAWEB_REWRITER_PUBLIC_DATA_URL_INPUT_RESOURCE_H_
32
 
#define NET_INSTAWEB_REWRITER_PUBLIC_DATA_URL_INPUT_RESOURCE_H_
33
 
 
34
 
namespace net_instaweb {
35
 
 
36
 
class InputInfo;
37
 
class RewriteDriver;
38
 
struct ContentType;
39
 
 
40
 
enum Encoding;
41
 
 
42
 
class DataUrlInputResource : public Resource {
43
 
 public:
44
 
  // We expose a factory; parse failure returns NULL.
45
 
  static ResourcePtr Make(const StringPiece& url, const RewriteDriver* driver) {
46
 
    ResourcePtr resource;
47
 
    const ContentType* type;
48
 
    Encoding encoding;
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));
58
 
    }
59
 
    return resource;
60
 
  }
61
 
 
62
 
  virtual ~DataUrlInputResource();
63
 
 
64
 
  virtual bool IsValidAndCacheable() const;
65
 
 
66
 
  // Set OutputPartition's input info used for expiration validation.
67
 
  virtual void FillInPartitionInputInfo(HashHint include_content_hash,
68
 
                                        InputInfo* input);
69
 
 
70
 
  virtual GoogleString url() const { return *url_.get(); }
71
 
 
72
 
  virtual bool UseHttpCache() const { return false; }
73
 
 
74
 
 protected:
75
 
  virtual void LoadAndCallback(NotCacheablePolicy not_cacheable_policy,
76
 
                               const RequestContextPtr& request_context,
77
 
                               AsyncCallback* callback);
78
 
 
79
 
 private:
80
 
  DataUrlInputResource(const GoogleString* url,
81
 
                       Encoding encoding,
82
 
                       const ContentType* type,
83
 
                       const StringPiece& encoded_contents,
84
 
                       const RewriteDriver* driver);
85
 
 
86
 
  scoped_ptr<const GoogleString> url_;
87
 
  const Encoding encoding_;
88
 
  const StringPiece encoded_contents_;  // substring of url.
89
 
  GoogleString decoded_contents_;
90
 
 
91
 
  DISALLOW_COPY_AND_ASSIGN(DataUrlInputResource);
92
 
};
93
 
 
94
 
}  // namespace net_instaweb
95
 
 
96
 
#endif  // NET_INSTAWEB_REWRITER_PUBLIC_DATA_URL_INPUT_RESOURCE_H_