OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 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 20 matching lines...) Expand all Loading... |
31 #ifndef WebFrameSerializer_h | 31 #ifndef WebFrameSerializer_h |
32 #define WebFrameSerializer_h | 32 #define WebFrameSerializer_h |
33 | 33 |
34 #include "../platform/WebCString.h" | 34 #include "../platform/WebCString.h" |
35 #include "../platform/WebCommon.h" | 35 #include "../platform/WebCommon.h" |
36 #include "../platform/WebData.h" | 36 #include "../platform/WebData.h" |
37 #include "../platform/WebString.h" | 37 #include "../platform/WebString.h" |
38 #include "../platform/WebURL.h" | 38 #include "../platform/WebURL.h" |
39 #include "../platform/WebVector.h" | 39 #include "../platform/WebVector.h" |
40 | 40 |
41 #include <utility> | |
42 | |
43 namespace blink { | 41 namespace blink { |
44 | 42 |
45 class WebFrameSerializerClient; | 43 class WebFrameSerializerClient; |
46 class WebFrame; | 44 class WebFrame; |
47 class WebLocalFrame; | 45 class WebLocalFrame; |
48 template <typename T> class WebVector; | 46 template <typename T> class WebVector; |
49 | 47 |
50 // Serialization of frame contents into html or mhtml. | 48 // Serialization of frame contents into html or mhtml. |
51 class WebFrameSerializer { | 49 class WebFrameSerializer { |
52 public: | 50 public: |
(...skipping 14 matching lines...) Expand all Loading... |
67 public: | 65 public: |
68 // Tells whether to skip serialization of a subresource with a given URI
. | 66 // Tells whether to skip serialization of a subresource with a given URI
. |
69 // Used to deduplicate resources across multiple frames. | 67 // Used to deduplicate resources across multiple frames. |
70 virtual bool shouldSkipResource(const WebURL&) = 0; | 68 virtual bool shouldSkipResource(const WebURL&) = 0; |
71 | 69 |
72 // Returns a Content-ID to be used for the given frame. | 70 // Returns a Content-ID to be used for the given frame. |
73 // See rfc2557 - section 8.3 - "Use of the Content-ID header and CID URL
s". | 71 // See rfc2557 - section 8.3 - "Use of the Content-ID header and CID URL
s". |
74 // Format note - the returned string should be of the form "<foo@bar.com
>" | 72 // Format note - the returned string should be of the form "<foo@bar.com
>" |
75 // (i.e. the strings should include the angle brackets). The method | 73 // (i.e. the strings should include the angle brackets). The method |
76 // should return null WebString if the frame doesn't have a content-id. | 74 // should return null WebString if the frame doesn't have a content-id. |
77 virtual WebString getContentID(const WebFrame&) = 0; | 75 virtual WebString getContentID(WebFrame*) = 0; |
78 }; | 76 }; |
79 | 77 |
80 // Generates and returns MHTML parts for the given frame and the | 78 // Generates and returns MHTML parts for the given frame and the |
81 // savable resources underneath. | 79 // savable resources underneath. |
82 // | 80 // |
83 // Same |boundary| needs to used for all generateMHTMLHeader and | 81 // Same |boundary| needs to used for all generateMHTMLHeader and |
84 // generateMHTMLParts and generateMHTMLFooter calls that belong to the same | 82 // generateMHTMLParts and generateMHTMLFooter calls that belong to the same |
85 // MHTML document (see also rfc1341, section 7.2.1, "boundary" description). | 83 // MHTML document (see also rfc1341, section 7.2.1, "boundary" description). |
86 BLINK_EXPORT static WebData generateMHTMLParts( | 84 BLINK_EXPORT static WebData generateMHTMLParts( |
87 const WebString& boundary, WebLocalFrame*, bool useBinaryEncoding, | 85 const WebString& boundary, WebLocalFrame*, bool useBinaryEncoding, |
88 MHTMLPartsGenerationDelegate*); | 86 MHTMLPartsGenerationDelegate*); |
89 | 87 |
90 // Generates and returns an MHTML footer. | 88 // Generates and returns an MHTML footer. |
91 // | 89 // |
92 // Same |boundary| needs to used for all generateMHTMLHeader and | 90 // Same |boundary| needs to used for all generateMHTMLHeader and |
93 // generateMHTMLParts and generateMHTMLFooter calls that belong to the same | 91 // generateMHTMLParts and generateMHTMLFooter calls that belong to the same |
94 // MHTML document (see also rfc1341, section 7.2.1, "boundary" description). | 92 // MHTML document (see also rfc1341, section 7.2.1, "boundary" description). |
95 BLINK_EXPORT static WebData generateMHTMLFooter(const WebString& boundary); | 93 BLINK_EXPORT static WebData generateMHTMLFooter(const WebString& boundary); |
96 | 94 |
97 // IMPORTANT: | 95 // IMPORTANT: |
98 // The API below is an older implementation of frame serialization that | 96 // The API below is an older implementation of frame serialization that |
99 // will be removed soon. | 97 // will be removed soon. |
100 | 98 |
| 99 class LinkRewritingDelegate { |
| 100 public: |
| 101 // Method allowing the delegate control which URLs are written into the |
| 102 // generated html document. |
| 103 // |
| 104 // When URL of the given frame needs to be rewritten, this method should |
| 105 // return true and populate |rewrittenLink| with a desired value of the |
| 106 // html attribute value to be used in place of the original link (i.e. |
| 107 // in place of the original iframe.src or object.data attribute value). |
| 108 // |
| 109 // If no link rewriting is desired, this method should return false. |
| 110 virtual bool rewriteFrameSource(WebFrame*, WebString* rewrittenLink) = 0
; |
| 111 |
| 112 // Method allowing the delegate control which URLs are written into the |
| 113 // generated html document. |
| 114 // |
| 115 // When the given URL needs to be rewritten, this method should |
| 116 // return true and populate |rewrittenLink| with a desired value of the |
| 117 // html attribute value to be used in place of the original link (i.e. |
| 118 // in place of the original img.src or blockquote.cite attribute value). |
| 119 // |
| 120 // If no link rewriting is desired, this method should return false. |
| 121 virtual bool rewriteLink(const WebURL&, WebString* rewrittenLink) = 0; |
| 122 }; |
| 123 |
101 // This function will serialize the specified frame to HTML data. | 124 // This function will serialize the specified frame to HTML data. |
102 // We have a data buffer to temporary saving generated html data. We will | 125 // We have a data buffer to temporary saving generated html data. We will |
103 // sequentially call WebFrameSerializerClient once the data buffer is full. | 126 // sequentially call WebFrameSerializerClient once the data buffer is full. |
104 // | 127 // |
105 // Return false means if no data has been serialized (i.e. because | 128 // False is returned if no data has been serialized (i.e. because |
106 // the target frame didn't have a valid url). | 129 // the target frame didn't have a valid url). |
107 // | |
108 // The parameter frame specifies which frame need to be serialized. | |
109 // The parameter client specifies the pointer of interface | |
110 // WebFrameSerializerClient providing a sink interface to receive the | |
111 // individual chunks of data to be saved. | |
112 // The parameter urlsToLocalPaths contains a mapping between original URLs | |
113 // of saved resources and corresponding local file paths. | |
114 BLINK_EXPORT static bool serialize( | 130 BLINK_EXPORT static bool serialize( |
115 WebLocalFrame*, | 131 WebLocalFrame*, |
116 WebFrameSerializerClient*, | 132 WebFrameSerializerClient*, |
117 const WebVector<std::pair<WebURL, WebString>>& urlsToLocalPaths); | 133 LinkRewritingDelegate*); |
118 | 134 |
119 // FIXME: The following are here for unit testing purposes. Consider | 135 // FIXME: The following are here for unit testing purposes. Consider |
120 // changing the unit tests instead. | 136 // changing the unit tests instead. |
121 | 137 |
122 // Generate the META for charset declaration. | 138 // Generate the META for charset declaration. |
123 BLINK_EXPORT static WebString generateMetaCharsetDeclaration(const WebString
& charset); | 139 BLINK_EXPORT static WebString generateMetaCharsetDeclaration(const WebString
& charset); |
124 // Generate the MOTW declaration. | 140 // Generate the MOTW declaration. |
125 BLINK_EXPORT static WebString generateMarkOfTheWebDeclaration(const WebURL&)
; | 141 BLINK_EXPORT static WebString generateMarkOfTheWebDeclaration(const WebURL&)
; |
126 // Generate the default base tag declaration. | 142 // Generate the default base tag declaration. |
127 BLINK_EXPORT static WebString generateBaseTagDeclaration(const WebString& ba
seTarget); | 143 BLINK_EXPORT static WebString generateBaseTagDeclaration(const WebString& ba
seTarget); |
128 }; | 144 }; |
129 | 145 |
130 } // namespace blink | 146 } // namespace blink |
131 | 147 |
132 #endif | 148 #endif |
OLD | NEW |