Page Speed Optimization Libraries
1.7.30.4
|
00001 /* 00002 * Copyright 2010 Google Inc. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http:///www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00022 00023 #include "net/instaweb/http/public/request_context.h" 00024 #include "net/instaweb/rewriter/public/resource.h" 00025 #include "net/instaweb/util/public/basictypes.h" 00026 #include "net/instaweb/util/public/data_url.h" 00027 #include "net/instaweb/util/public/scoped_ptr.h" 00028 #include "net/instaweb/util/public/string.h" 00029 #include "net/instaweb/util/public/string_util.h" 00030 00031 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_DATA_URL_INPUT_RESOURCE_H_ 00032 #define NET_INSTAWEB_REWRITER_PUBLIC_DATA_URL_INPUT_RESOURCE_H_ 00033 00034 namespace net_instaweb { 00035 00036 class InputInfo; 00037 class ServerContext; 00038 struct ContentType; 00039 00040 enum Encoding; 00041 00042 class DataUrlInputResource : public Resource { 00043 public: 00045 static ResourcePtr Make(const StringPiece& url, 00046 ServerContext* server_context) { 00047 ResourcePtr resource; 00048 const ContentType* type; 00049 Encoding encoding; 00050 StringPiece encoded_contents; 00054 GoogleString* url_copy = new GoogleString(); 00055 url.CopyToString(url_copy); 00056 if (ParseDataUrl(*url_copy, &type, &encoding, &encoded_contents)) { 00057 resource.reset(new DataUrlInputResource(url_copy, encoding, type, 00058 encoded_contents, 00059 server_context)); 00060 } 00061 return resource; 00062 } 00063 00064 virtual ~DataUrlInputResource(); 00065 00066 virtual bool IsValidAndCacheable() const; 00067 00069 virtual void FillInPartitionInputInfo(HashHint include_content_hash, 00070 InputInfo* input); 00071 00072 virtual GoogleString url() const { return *url_.get(); } 00073 00074 virtual bool UseHttpCache() const { return false; } 00075 00076 protected: 00077 virtual void LoadAndCallback(NotCacheablePolicy not_cacheable_policy, 00078 const RequestContextPtr& request_context, 00079 AsyncCallback* callback); 00080 00081 private: 00082 DataUrlInputResource(const GoogleString* url, 00083 Encoding encoding, 00084 const ContentType* type, 00085 const StringPiece& encoded_contents, 00086 ServerContext* server_context); 00087 00088 scoped_ptr<const GoogleString> url_; 00089 const Encoding encoding_; 00090 const StringPiece encoded_contents_; 00091 GoogleString decoded_contents_; 00092 00093 DISALLOW_COPY_AND_ASSIGN(DataUrlInputResource); 00094 }; 00095 00096 } 00097 00098 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_DATA_URL_INPUT_RESOURCE_H_