| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 57 |
| 58 // Get html data by serializing all frames of current page with lists | 58 // Get html data by serializing all frames of current page with lists |
| 59 // which contain all resource links that have local copy. | 59 // which contain all resource links that have local copy. |
| 60 // contain all saved auxiliary files included all sub frames and resources. | 60 // contain all saved auxiliary files included all sub frames and resources. |
| 61 // This function will find out all frames and serialize them to HTML data. | 61 // This function will find out all frames and serialize them to HTML data. |
| 62 // We have a data buffer to temporary saving generated html data. We will | 62 // We have a data buffer to temporary saving generated html data. We will |
| 63 // sequentially call WebViewDelegate::SendSerializedHtmlData once the data | 63 // sequentially call WebViewDelegate::SendSerializedHtmlData once the data |
| 64 // buffer is full. See comments of WebViewDelegate::SendSerializedHtmlData | 64 // buffer is full. See comments of WebViewDelegate::SendSerializedHtmlData |
| 65 // for getting more information. | 65 // for getting more information. |
| 66 class WebPageSerializerImpl { | 66 class WebPageSerializerImpl { |
| 67 STACK_ALLOCATED(); |
| 67 public: | 68 public: |
| 68 // Do serialization action. Return false means no available frame has been | 69 // Do serialization action. Return false means no available frame has been |
| 69 // serialized, otherwise return true. | 70 // serialized, otherwise return true. |
| 70 bool serialize(); | 71 bool serialize(); |
| 71 | 72 |
| 72 // The parameter specifies which frame need to be serialized. | 73 // The parameter specifies which frame need to be serialized. |
| 73 // The parameter recursive_serialization specifies whether we need to | 74 // The parameter recursive_serialization specifies whether we need to |
| 74 // serialize all sub frames of the specified frame or not. | 75 // serialize all sub frames of the specified frame or not. |
| 75 // The parameter delegate specifies the pointer of interface | 76 // The parameter delegate specifies the pointer of interface |
| 76 // DomSerializerDelegate provide sink interface which can receive the | 77 // DomSerializerDelegate provide sink interface which can receive the |
| 77 // individual chunks of data to be saved. | 78 // individual chunks of data to be saved. |
| 78 // The parameter links contain original URLs of all saved links. | 79 // The parameter links contain original URLs of all saved links. |
| 79 // The parameter local_paths contain corresponding local file paths of all | 80 // The parameter local_paths contain corresponding local file paths of all |
| 80 // saved links, which matched with vector:links one by one. | 81 // saved links, which matched with vector:links one by one. |
| 81 // The parameter local_directory_name is relative path of directory which | 82 // The parameter local_directory_name is relative path of directory which |
| 82 // contain all saved auxiliary files included all sub frames and resources. | 83 // contain all saved auxiliary files included all sub frames and resources. |
| 83 WebPageSerializerImpl(WebFrame* frame, | 84 WebPageSerializerImpl(WebFrame* frame, |
| 84 bool recursive, | 85 bool recursive, |
| 85 WebPageSerializerClient* client, | 86 WebPageSerializerClient* client, |
| 86 const WebVector<WebURL>& links, | 87 const WebVector<WebURL>& links, |
| 87 const WebVector<WebString>& localPaths, | 88 const WebVector<WebString>& localPaths, |
| 88 const WebString& localDirectoryName); | 89 const WebString& localDirectoryName); |
| 89 | 90 |
| 90 private: | 91 private: |
| 91 // Specified frame which need to be serialized; | 92 // Specified frame which need to be serialized; |
| 92 WebLocalFrameImpl* m_specifiedWebLocalFrameImpl; | 93 RawPtrWillBeMember<WebLocalFrameImpl> m_specifiedWebLocalFrameImpl; |
| 93 // Pointer of WebPageSerializerClient | 94 // Pointer of WebPageSerializerClient |
| 94 WebPageSerializerClient* m_client; | 95 WebPageSerializerClient* m_client; |
| 95 // This hash map is used to map resource URL of original link to its local | 96 // This hash map is used to map resource URL of original link to its local |
| 96 // file path. | 97 // file path. |
| 97 typedef HashMap<WTF::String, WTF::String> LinkLocalPathMap; | 98 typedef HashMap<WTF::String, WTF::String> LinkLocalPathMap; |
| 98 // local_links_ include all pair of local resource path and corresponding | 99 // local_links_ include all pair of local resource path and corresponding |
| 99 // original link. | 100 // original link. |
| 100 LinkLocalPathMap m_localLinks; | 101 LinkLocalPathMap m_localLinks; |
| 101 // Data buffer for saving result of serialized DOM data. | 102 // Data buffer for saving result of serialized DOM data. |
| 102 StringBuilder m_dataBuffer; | 103 StringBuilder m_dataBuffer; |
| 103 // Passing true to recursive_serialization_ indicates we will serialize not | 104 // Passing true to recursive_serialization_ indicates we will serialize not |
| 104 // only the specified frame but also all sub-frames in the specific frame. | 105 // only the specified frame but also all sub-frames in the specific frame. |
| 105 // Otherwise we only serialize the specified frame excluded all sub-frames. | 106 // Otherwise we only serialize the specified frame excluded all sub-frames. |
| 106 bool m_recursiveSerialization; | 107 bool m_recursiveSerialization; |
| 107 // Flag indicates whether we have collected all frames which need to be | 108 // Flag indicates whether we have collected all frames which need to be |
| 108 // serialized or not; | 109 // serialized or not; |
| 109 bool m_framesCollected; | 110 bool m_framesCollected; |
| 110 // Local directory name of all local resource files. | 111 // Local directory name of all local resource files. |
| 111 WTF::String m_localDirectoryName; | 112 WTF::String m_localDirectoryName; |
| 112 // Vector for saving all frames which need to be serialized. | 113 // Vector for saving all frames which need to be serialized. |
| 113 Vector<WebLocalFrameImpl*> m_frames; | 114 WillBeHeapVector<RawPtrWillBeMember<WebLocalFrameImpl>> m_frames; |
| 114 | 115 |
| 115 // Web entities conversion maps. | 116 // Web entities conversion maps. |
| 116 WebEntities m_htmlEntities; | 117 WebEntities m_htmlEntities; |
| 117 WebEntities m_xmlEntities; | 118 WebEntities m_xmlEntities; |
| 118 | 119 |
| 119 struct SerializeDomParam { | 120 class SerializeDomParam { |
| 121 STACK_ALLOCATED(); |
| 122 public: |
| 123 SerializeDomParam(const KURL&, const WTF::TextEncoding&, Document*, cons
t WTF::String& directoryName); |
| 124 |
| 120 const KURL& url; | 125 const KURL& url; |
| 121 const WTF::TextEncoding& textEncoding; | 126 const WTF::TextEncoding& textEncoding; |
| 122 Document* document; | 127 RawPtrWillBeMember<Document> document; |
| 123 const WTF::String& directoryName; | 128 const WTF::String& directoryName; |
| 124 bool isHTMLDocument; // document.isHTMLDocument() | 129 bool isHTMLDocument; // document.isHTMLDocument() |
| 125 bool haveSeenDocType; | 130 bool haveSeenDocType; |
| 126 bool haveAddedCharsetDeclaration; | 131 bool haveAddedCharsetDeclaration; |
| 127 // This meta element need to be skipped when serializing DOM. | 132 // This meta element need to be skipped when serializing DOM. |
| 128 const Element* skipMetaElement; | 133 RawPtrWillBeMember<const Element> skipMetaElement; |
| 129 // Flag indicates we are in script or style tag. | 134 // Flag indicates we are in script or style tag. |
| 130 bool isInScriptOrStyleTag; | 135 bool isInScriptOrStyleTag; |
| 131 bool haveAddedXMLProcessingDirective; | 136 bool haveAddedXMLProcessingDirective; |
| 132 // Flag indicates whether we have added additional contents before end t
ag. | 137 // Flag indicates whether we have added additional contents before end t
ag. |
| 133 // This flag will be re-assigned in each call of function | 138 // This flag will be re-assigned in each call of function |
| 134 // PostActionAfterSerializeOpenTag and it could be changed in function | 139 // PostActionAfterSerializeOpenTag and it could be changed in function |
| 135 // PreActionBeforeSerializeEndTag if the function adds new contents into | 140 // PreActionBeforeSerializeEndTag if the function adds new contents into |
| 136 // serialization stream. | 141 // serialization stream. |
| 137 bool haveAddedContentsBeforeEnd; | 142 bool haveAddedContentsBeforeEnd; |
| 138 | |
| 139 SerializeDomParam(const KURL&, const WTF::TextEncoding&, Document*, cons
t WTF::String& directoryName); | |
| 140 }; | 143 }; |
| 141 | 144 |
| 142 // Collect all target frames which need to be serialized. | 145 // Collect all target frames which need to be serialized. |
| 143 void collectTargetFrames(); | 146 void collectTargetFrames(); |
| 144 // Before we begin serializing open tag of a element, we give the target | 147 // Before we begin serializing open tag of a element, we give the target |
| 145 // element a chance to do some work prior to add some additional data. | 148 // element a chance to do some work prior to add some additional data. |
| 146 WTF::String preActionBeforeSerializeOpenTag(const Element*, | 149 WTF::String preActionBeforeSerializeOpenTag(const Element*, |
| 147 SerializeDomParam* param, | 150 SerializeDomParam* param, |
| 148 bool* needSkip); | 151 bool* needSkip); |
| 149 // After we finish serializing open tag of a element, we give the target | 152 // After we finish serializing open tag of a element, we give the target |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 void endTagToString(Element*, | 184 void endTagToString(Element*, |
| 182 SerializeDomParam* param); | 185 SerializeDomParam* param); |
| 183 // Build content for a specified node | 186 // Build content for a specified node |
| 184 void buildContentForNode(Node*, | 187 void buildContentForNode(Node*, |
| 185 SerializeDomParam* param); | 188 SerializeDomParam* param); |
| 186 }; | 189 }; |
| 187 | 190 |
| 188 } // namespace blink | 191 } // namespace blink |
| 189 | 192 |
| 190 #endif | 193 #endif |
| OLD | NEW |