Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(335)

Side by Side Diff: third_party/WebKit/Source/core/page/PageSerializer.h

Issue 1441553002: Generating CIDs in Blink during MHTML serialization. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mhtml-per-frame-page-serializer-only
Patch Set: Rebasing... Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 17 matching lines...) Expand all
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef PageSerializer_h 31 #ifndef PageSerializer_h
32 #define PageSerializer_h 32 #define PageSerializer_h
33 33
34 #include "core/CoreExport.h" 34 #include "core/CoreExport.h"
35 #include "platform/heap/Handle.h" 35 #include "platform/heap/Handle.h"
36 #include "platform/weborigin/KURL.h" 36 #include "platform/weborigin/KURL.h"
37 #include "platform/weborigin/KURLHash.h" 37 #include "platform/weborigin/KURLHash.h"
38 #include "wtf/HashMap.h"
39 #include "wtf/ListHashSet.h" 38 #include "wtf/ListHashSet.h"
40 #include "wtf/PassOwnPtr.h" 39 #include "wtf/PassOwnPtr.h"
41 #include "wtf/Vector.h" 40 #include "wtf/Vector.h"
41 #include "wtf/text/WTFString.h"
42 42
43 namespace blink { 43 namespace blink {
44 44
45 class Attribute; 45 class Attribute;
46 class FontResource;
47 class ImageResource;
48 class CSSRule; 46 class CSSRule;
49 class CSSStyleSheet; 47 class CSSStyleSheet;
50 class CSSValue; 48 class CSSValue;
51 class Document; 49 class Document;
50 class Element;
51 class FontResource;
52 class ImageResource;
52 class LocalFrame; 53 class LocalFrame;
53 class Node; 54 class Node;
54 class Page; 55 class Page;
55 class LayoutObject; 56 class LayoutObject;
56 class Resource; 57 class Resource;
57 class SharedBuffer; 58 class SharedBuffer;
58 class StylePropertySet; 59 class StylePropertySet;
59 60
60 struct SerializedResource; 61 struct SerializedResource;
61 62
62 // This class is used to serialize frame's contents back to text (typically HTML ). 63 // This class is used to serialize frame's contents back to text (typically HTML ).
63 // It serializes frame's document and resources such as images and CSS styleshee ts. 64 // It serializes frame's document and resources such as images and CSS styleshee ts.
64 // TODO(lukasza): Rename this class to FrameSerializer. 65 // TODO(lukasza): Rename this class to FrameSerializer.
65 class CORE_EXPORT PageSerializer final { 66 class CORE_EXPORT PageSerializer final {
66 STACK_ALLOCATED(); 67 STACK_ALLOCATED();
67 public: 68 public:
68 class Delegate { 69 class Delegate {
69 USING_FAST_MALLOC(Delegate); 70 USING_FAST_MALLOC(Delegate);
70 public: 71 public:
71 virtual ~Delegate() { } 72 virtual ~Delegate() { }
72 virtual bool shouldIgnoreAttribute(const Attribute&) = 0; 73 virtual bool shouldIgnoreAttribute(const Attribute&) = 0;
74
75 // Method allowing the Delegate control which URLs are written into the
76 // generated html document.
77 //
78 // When URL of the element needs to be rewritten, this method should
79 // return true and populate |rewrittenLink| with a desired value of the
80 // html attribute value to be used in place of the original link.
81 // (i.e. in place of img.src or iframe.src or object.data).
82 //
83 // If no link rewriting is desired, this method should return false.
84 virtual bool rewriteLink(const Element&, String& rewrittenLink) = 0;
73 }; 85 };
74 86
75 PageSerializer(Vector<SerializedResource>*, PassOwnPtr<Delegate>); 87 // Constructs a serializer that will write output to the given vector of
88 // SerializedResources and use the optional Delegate for controlling some
89 // serialization aspects. Callers need to ensure that the Delegate stays
90 // alive until the PageSerializer gets destroyed.
91 PageSerializer(
yosin_UTC9 2015/12/02 05:25:12 nit: We can put both parameter in same line.
Łukasz Anforowicz 2015/12/02 15:12:34 Done.
92 Vector<SerializedResource>&,
93 Delegate*);
76 94
77 // Initiates the serialization of the frame. All serialized content and 95 // Initiates the serialization of the frame. All serialized content and
78 // retrieved resources are added to the Vector passed to the constructor. 96 // retrieved resources are added to the Vector passed to the constructor.
79 // The first resource in that vector is the frame's serialized content. 97 // The first resource in that vector is the frame's serialized content.
80 // Subsequent resources are images, css, etc. 98 // Subsequent resources are images, css, etc.
81 void serializeFrame(const LocalFrame&); 99 void serializeFrame(const LocalFrame&);
82 100
83 void registerRewriteURL(const String& from, const String& to);
84 void setRewriteURLFolder(const String&);
85
86 KURL urlForBlankFrame(const LocalFrame&);
87
88 Delegate* delegate(); 101 Delegate* delegate();
89 102
90 static String markOfTheWebDeclaration(const KURL&); 103 static String markOfTheWebDeclaration(const KURL&);
91 104
92 private: 105 private:
93 // Serializes the stylesheet back to text and adds it to the resources if UR L is not-empty. 106 // Serializes the stylesheet back to text and adds it to the resources if UR L is not-empty.
94 // It also adds any resources included in that stylesheet (including any imp orted stylesheets and their own resources). 107 // It also adds any resources included in that stylesheet (including any imp orted stylesheets and their own resources).
95 void serializeCSSStyleSheet(CSSStyleSheet&, const KURL&); 108 void serializeCSSStyleSheet(CSSStyleSheet&, const KURL&);
96 109
97 // Serializes the css rule (including any imported stylesheets), adding refe renced resources. 110 // Serializes the css rule (including any imported stylesheets), adding refe renced resources.
98 void serializeCSSRule(CSSRule*); 111 void serializeCSSRule(CSSRule*);
99 112
100 bool shouldAddURL(const KURL&); 113 bool shouldAddURL(const KURL&);
101 114
102 void addToResources(Resource *, PassRefPtr<SharedBuffer>, const KURL&); 115 void addToResources(Resource *, PassRefPtr<SharedBuffer>, const KURL&);
103 void addImageToResources(ImageResource*, const KURL&); 116 void addImageToResources(ImageResource*, const KURL&);
104 void addFontToResources(FontResource*); 117 void addFontToResources(FontResource*);
105 118
106 void retrieveResourcesForProperties(const StylePropertySet*, Document&); 119 void retrieveResourcesForProperties(const StylePropertySet*, Document&);
107 void retrieveResourcesForCSSValue(CSSValue*, Document&); 120 void retrieveResourcesForCSSValue(CSSValue*, Document&);
108 121
109 Vector<SerializedResource>* m_resources; 122 Vector<SerializedResource>* m_resources;
110 ListHashSet<KURL> m_resourceURLs; 123 ListHashSet<KURL> m_resourceURLs;
111 124
112 using BlankFrameURLMap = WillBeHeapHashMap<RawPtrWillBeMember<const LocalFra me>, KURL>; 125 Delegate* m_delegate;
113 BlankFrameURLMap m_blankFrameURLs;
114 HashMap<String, String> m_rewriteURLs;
115 String m_rewriteFolder;
116 unsigned m_blankFrameCounter;
117
118 OwnPtr<Delegate> m_delegate;
119 }; 126 };
120 127
121 // TODO(lukasza): Stop exposing this implementation detail once the serializers 128 // TODO(lukasza): Stop exposing this implementation detail once the serializers
122 // are merged. 129 // are merged.
123 CORE_EXPORT bool isCharsetSpecifyingNode(const Node&); 130 CORE_EXPORT bool isCharsetSpecifyingNode(const Node&);
124 131
125 } // namespace blink 132 } // namespace blink
126 133
127 #endif // PageSerializer_h 134 #endif // PageSerializer_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698