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

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: Using references for out parameters in Blink. 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 Page; 54 class Page;
54 class LayoutObject; 55 class LayoutObject;
55 class Resource; 56 class Resource;
56 class SharedBuffer; 57 class SharedBuffer;
57 class StylePropertySet; 58 class StylePropertySet;
58 59
59 struct SerializedResource; 60 struct SerializedResource;
60 61
61 // This class is used to serialize frame's contents back to text (typically HTML ). 62 // This class is used to serialize frame's contents back to text (typically HTML ).
62 // It serializes frame's document and resources such as images and CSS styleshee ts. 63 // It serializes frame's document and resources such as images and CSS styleshee ts.
63 // TODO(lukasza): Rename this class to FrameSerializer. 64 // TODO(lukasza): Rename this class to FrameSerializer.
64 class CORE_EXPORT PageSerializer final { 65 class CORE_EXPORT PageSerializer final {
65 STACK_ALLOCATED(); 66 STACK_ALLOCATED();
66 public: 67 public:
67 class Delegate { 68 class Delegate {
68 USING_FAST_MALLOC(Delegate); 69 USING_FAST_MALLOC(Delegate);
69 public: 70 public:
70 virtual ~Delegate() { } 71 virtual ~Delegate() { }
71 virtual bool shouldIgnoreAttribute(const Attribute&) = 0; 72 virtual bool shouldIgnoreAttribute(const Attribute&) = 0;
73
74 // Method allowing the Delegate control which URLs are written into the
75 // generated html document.
76 //
77 // When URL of the element needs to be rewritten, this method should
78 // return true and populate |desiredLink| with a desired value of the
tkent 2015/12/02 00:59:59 desiredLink -> rewrittenLink ?
Łukasz Anforowicz 2015/12/02 02:57:08 Done. Thanks for catching this.
79 // html attribute value to be used in place of the original link.
80 // (i.e. in place of img.src or iframe.src or object.data).
81 //
82 // If no link rewriting is desired, this method should return false.
83 virtual bool rewriteLink(const Element&, String& rewrittenLink) = 0;
72 }; 84 };
73 85
74 PageSerializer(Vector<SerializedResource>*, PassOwnPtr<Delegate>); 86 // Constructs a serializer that will write output to the given vector of
87 // SerializedResources and use the optional Delegate for controlling some
88 // serialization aspects.
tkent 2015/12/02 00:59:59 nit: We should note ownership/lifetime of Delegate
Łukasz Anforowicz 2015/12/02 02:57:08 Done. Good point.
89 PageSerializer(
90 Vector<SerializedResource>&,
91 Delegate*);
75 92
76 // Initiates the serialization of the frame. All serialized content and 93 // Initiates the serialization of the frame. All serialized content and
77 // retrieved resources are added to the Vector passed to the constructor. 94 // retrieved resources are added to the Vector passed to the constructor.
78 // The first resource in that vector is the frame's serialized content. 95 // The first resource in that vector is the frame's serialized content.
79 // Subsequent resources are images, css, etc. 96 // Subsequent resources are images, css, etc.
80 void serializeFrame(const LocalFrame&); 97 void serializeFrame(const LocalFrame&);
81 98
82 void registerRewriteURL(const String& from, const String& to);
83 void setRewriteURLFolder(const String&);
84
85 KURL urlForBlankFrame(const LocalFrame&);
86
87 Delegate* delegate(); 99 Delegate* delegate();
88 100
89 static String markOfTheWebDeclaration(const KURL&); 101 static String markOfTheWebDeclaration(const KURL&);
90 102
91 private: 103 private:
92 // Serializes the stylesheet back to text and adds it to the resources if UR L is not-empty. 104 // Serializes the stylesheet back to text and adds it to the resources if UR L is not-empty.
93 // It also adds any resources included in that stylesheet (including any imp orted stylesheets and their own resources). 105 // It also adds any resources included in that stylesheet (including any imp orted stylesheets and their own resources).
94 void serializeCSSStyleSheet(CSSStyleSheet&, const KURL&); 106 void serializeCSSStyleSheet(CSSStyleSheet&, const KURL&);
95 107
96 // Serializes the css rule (including any imported stylesheets), adding refe renced resources. 108 // Serializes the css rule (including any imported stylesheets), adding refe renced resources.
97 void serializeCSSRule(CSSRule*); 109 void serializeCSSRule(CSSRule*);
98 110
99 bool shouldAddURL(const KURL&); 111 bool shouldAddURL(const KURL&);
100 112
101 void addToResources(Resource *, PassRefPtr<SharedBuffer>, const KURL&); 113 void addToResources(Resource *, PassRefPtr<SharedBuffer>, const KURL&);
102 void addImageToResources(ImageResource*, const KURL&); 114 void addImageToResources(ImageResource*, const KURL&);
103 void addFontToResources(FontResource*); 115 void addFontToResources(FontResource*);
104 116
105 void retrieveResourcesForProperties(const StylePropertySet*, Document&); 117 void retrieveResourcesForProperties(const StylePropertySet*, Document&);
106 void retrieveResourcesForCSSValue(CSSValue*, Document&); 118 void retrieveResourcesForCSSValue(CSSValue*, Document&);
107 119
108 Vector<SerializedResource>* m_resources; 120 Vector<SerializedResource>* m_resources;
109 ListHashSet<KURL> m_resourceURLs; 121 ListHashSet<KURL> m_resourceURLs;
110 122
111 using BlankFrameURLMap = WillBeHeapHashMap<RawPtrWillBeMember<const LocalFra me>, KURL>; 123 Delegate* m_delegate;
112 BlankFrameURLMap m_blankFrameURLs;
113 HashMap<String, String> m_rewriteURLs;
114 String m_rewriteFolder;
115 unsigned m_blankFrameCounter;
116
117 OwnPtr<Delegate> m_delegate;
118 }; 124 };
119 125
120 } // namespace blink 126 } // namespace blink
121 127
122 #endif // PageSerializer_h 128 #endif // PageSerializer_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698