00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00022
00023 #include "base/scoped_ptr.h"
00024 #include "base/logging.h"
00025 #include "net/instaweb/rewriter/public/resource.h"
00026 #include "net/instaweb/rewriter/public/resource_manager.h"
00027 #include "net/instaweb/util/public/basictypes.h"
00028 #include "net/instaweb/util/public/data_url.h"
00029 #include "net/instaweb/util/public/string.h"
00030 #include "net/instaweb/util/public/string_util.h"
00031
00032 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_DATA_URL_INPUT_RESOURCE_H_
00033 #define NET_INSTAWEB_REWRITER_PUBLIC_DATA_URL_INPUT_RESOURCE_H_
00034
00035 namespace net_instaweb {
00036
00037 class ContentType;
00038 class InputInfo;
00039 class MessageHandler;
00040 class RewriteOptions;
00041 enum Encoding;
00042
00043 class DataUrlInputResource : public Resource {
00044 public:
00046 static ResourcePtr Make(const StringPiece& url,
00047 ResourceManager* resource_manager) {
00048 ResourcePtr resource;
00049 const ContentType* type;
00050 Encoding encoding;
00051 StringPiece encoded_contents;
00055 GoogleString* url_copy = new GoogleString();
00056 url.CopyToString(url_copy);
00057 if (ParseDataUrl(*url_copy, &type, &encoding, &encoded_contents)) {
00058 resource.reset(new DataUrlInputResource(url_copy, encoding, type,
00059 encoded_contents,
00060 resource_manager));
00061 }
00062 return resource;
00063 }
00064
00065 virtual ~DataUrlInputResource();
00066
00067 virtual bool IsValidAndCacheable() const;
00068
00070 virtual void FillInPartitionInputInfo(HashHint include_content_hash,
00071 InputInfo* input);
00072
00073 virtual GoogleString url() const { return *url_.get(); }
00074 virtual const RewriteOptions* rewrite_options() const {
00075 LOG(DFATAL) << "Unexpected call to DataUrlInputResource::rewrite_options()";
00076 return NULL;
00077 }
00078
00079 protected:
00080 virtual bool Load(MessageHandler* message_handler);
00081 virtual bool IsCacheable() const;
00082
00083 private:
00084 DataUrlInputResource(const GoogleString* url,
00085 Encoding encoding,
00086 const ContentType* type,
00087 const StringPiece& encoded_contents,
00088 ResourceManager* resource_manager)
00089 : Resource(resource_manager, type),
00090 url_(url),
00091 encoding_(encoding),
00092 encoded_contents_(encoded_contents) {
00094 Load(resource_manager->message_handler());
00095 }
00096
00097 scoped_ptr<const GoogleString> url_;
00098 const Encoding encoding_;
00099 const StringPiece encoded_contents_;
00100 GoogleString decoded_contents_;
00101
00102 DISALLOW_COPY_AND_ASSIGN(DataUrlInputResource);
00103 };
00104
00105 }
00106
00107 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_DATA_URL_INPUT_RESOURCE_H_