Page Speed Optimization Libraries  1.2.24.1
net/instaweb/rewriter/public/association_transformer.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2012 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 
00018 
00019 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_ASSOCIATION_TRANSFORMER_H_
00020 #define NET_INSTAWEB_REWRITER_PUBLIC_ASSOCIATION_TRANSFORMER_H_
00021 
00022 #include <map>
00023 
00024 #include "net/instaweb/rewriter/public/css_tag_scanner.h"
00025 #include "net/instaweb/rewriter/public/resource.h"
00026 #include "net/instaweb/rewriter/public/resource_slot.h"
00027 #include "net/instaweb/util/public/basictypes.h"
00028 #include "net/instaweb/util/public/gtest_prod.h"
00029 #include "net/instaweb/util/public/string.h"
00030 #include "net/instaweb/util/public/string_util.h"
00031 
00032 namespace net_instaweb {
00033 
00034 class GoogleUrl;
00035 class MessageHandler;
00036 
00041 class AssociationTransformer : public CssTagScanner::Transformer {
00042  public:
00051   AssociationTransformer(const GoogleUrl* base_url,
00052                          CssTagScanner::Transformer* backup_transformer,
00053                          MessageHandler* handler)
00054       : base_url_(base_url), backup_transformer_(backup_transformer),
00055         handler_(handler) {}
00056   virtual ~AssociationTransformer();
00057 
00061   StringStringMap* map() { return &map_; }
00062 
00067   virtual TransformStatus Transform(const StringPiece& in, GoogleString* out);
00068 
00069  private:
00071   StringStringMap map_;
00072 
00074   const GoogleUrl* base_url_;
00075 
00078   CssTagScanner::Transformer* backup_transformer_;
00079 
00080   MessageHandler* handler_;
00081 
00082   FRIEND_TEST(AssociationTransformerTest, TransformsCorrectly);
00083 
00084   DISALLOW_COPY_AND_ASSIGN(AssociationTransformer);
00085 };
00086 
00092 class AssociationSlot : public ResourceSlot {
00093  public:
00095   AssociationSlot(ResourcePtr resource,
00096                   StringStringMap* map, const StringPiece& key)
00097       : ResourceSlot(resource), map_(map) {
00098     key.CopyToString(&key_);
00099   }
00100   virtual ~AssociationSlot();
00101 
00104   virtual void Render() {
00105     if (!disable_rendering()) {
00106       (*map_)[key_] = resource()->url();
00107     }
00108   }
00109 
00110   virtual void DirectSetUrl(const StringPiece& url) {
00111     url.CopyToString(&((*map_)[key_]));
00112   }
00113 
00114   virtual GoogleString LocationString() {
00117     return "Inside CSS";
00118   }
00119 
00120  private:
00121   StringStringMap* map_;
00122   GoogleString key_;
00123 
00124   DISALLOW_COPY_AND_ASSIGN(AssociationSlot);
00125 };
00126 
00127 }  
00128 
00129 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_ASSOCIATION_TRANSFORMER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines