| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 // Do serialization action. | 63 // Do serialization action. |
| 64 // | 64 // |
| 65 // Returns false to indicate that no data has been serialized (i.e. because | 65 // Returns false to indicate that no data has been serialized (i.e. because |
| 66 // the target frame didn't have a valid url). | 66 // the target frame didn't have a valid url). |
| 67 // | 67 // |
| 68 // Synchronously calls WebPageSerializerClient methods to report | 68 // Synchronously calls WebPageSerializerClient methods to report |
| 69 // serialization results. See WebPageSerializerClient comments for more | 69 // serialization results. See WebPageSerializerClient comments for more |
| 70 // details. | 70 // details. |
| 71 bool serialize(); | 71 bool serialize(); |
| 72 | 72 |
| 73 // The parameter specifies which frame need to be serialized. | 73 // Creates a serializer to serialize the given frame, sending the data to a |
| 74 // The parameter delegate specifies the pointer of interface | 74 // client sink interface to consume. |
| 75 // DomSerializerDelegate provide sink interface which can receive the | 75 WebPageSerializerImpl(WebFrame*, WebPageSerializerClient*); |
| 76 // individual chunks of data to be saved. | |
| 77 // The parameter links contain original URLs of all saved links. | |
| 78 // The parameter local_paths contain corresponding local file paths of all | |
| 79 // saved links, which matched with vector:links one by one. | |
| 80 // The parameter local_directory_name is relative path of directory which | |
| 81 // contain all saved auxiliary files included all sub frames and resources. | |
| 82 WebPageSerializerImpl(WebFrame* frame, | |
| 83 WebPageSerializerClient* client, | |
| 84 const WebVector<WebURL>& links, | |
| 85 const WebVector<WebString>& localPaths, | |
| 86 const WebString& localDirectoryName); | |
| 87 | 76 |
| 88 private: | 77 private: |
| 89 // Specified frame which need to be serialized; | 78 // Specified frame which need to be serialized; |
| 90 RawPtrWillBeMember<WebLocalFrameImpl> m_specifiedWebLocalFrameImpl; | 79 RawPtrWillBeMember<WebLocalFrameImpl> m_specifiedWebLocalFrameImpl; |
| 91 // Pointer of WebPageSerializerClient | 80 // Pointer of WebPageSerializerClient |
| 92 WebPageSerializerClient* m_client; | 81 WebPageSerializerClient* m_client; |
| 93 // This hash map is used to map resource URL of original link to its local | |
| 94 // file path. | |
| 95 typedef HashMap<WTF::String, WTF::String> LinkLocalPathMap; | |
| 96 // local_links_ include all pair of local resource path and corresponding | |
| 97 // original link. | |
| 98 LinkLocalPathMap m_localLinks; | |
| 99 // Data buffer for saving result of serialized DOM data. | 82 // Data buffer for saving result of serialized DOM data. |
| 100 StringBuilder m_dataBuffer; | 83 StringBuilder m_dataBuffer; |
| 101 // Local directory name of all local resource files. | |
| 102 WTF::String m_localDirectoryName; | |
| 103 | 84 |
| 104 // Web entities conversion maps. | 85 // Web entities conversion maps. |
| 105 WebEntities m_htmlEntities; | 86 WebEntities m_htmlEntities; |
| 106 WebEntities m_xmlEntities; | 87 WebEntities m_xmlEntities; |
| 107 | 88 |
| 108 class SerializeDomParam { | 89 class SerializeDomParam { |
| 109 STACK_ALLOCATED(); | 90 STACK_ALLOCATED(); |
| 110 public: | 91 public: |
| 111 SerializeDomParam(const KURL&, const WTF::TextEncoding&, Document*, cons
t WTF::String& directoryName); | 92 SerializeDomParam(const KURL&, const WTF::TextEncoding&, Document*); |
| 112 | 93 |
| 113 const KURL& url; | 94 const KURL& url; |
| 114 const WTF::TextEncoding& textEncoding; | 95 const WTF::TextEncoding& textEncoding; |
| 115 RawPtrWillBeMember<Document> document; | 96 RawPtrWillBeMember<Document> document; |
| 116 const WTF::String& directoryName; | |
| 117 bool isHTMLDocument; // document.isHTMLDocument() | 97 bool isHTMLDocument; // document.isHTMLDocument() |
| 118 bool haveSeenDocType; | 98 bool haveSeenDocType; |
| 119 bool haveAddedCharsetDeclaration; | 99 bool haveAddedCharsetDeclaration; |
| 120 // This meta element need to be skipped when serializing DOM. | 100 // This meta element need to be skipped when serializing DOM. |
| 121 RawPtrWillBeMember<const Element> skipMetaElement; | 101 RawPtrWillBeMember<const Element> skipMetaElement; |
| 122 // Flag indicates we are in script or style tag. | 102 // Flag indicates we are in script or style tag. |
| 123 bool isInScriptOrStyleTag; | 103 bool isInScriptOrStyleTag; |
| 124 bool haveAddedXMLProcessingDirective; | 104 bool haveAddedXMLProcessingDirective; |
| 125 // Flag indicates whether we have added additional contents before end t
ag. | 105 // Flag indicates whether we have added additional contents before end t
ag. |
| 126 // This flag will be re-assigned in each call of function | 106 // This flag will be re-assigned in each call of function |
| (...skipping 25 matching lines...) Expand all Loading... |
| 152 void saveHTMLContentToBuffer(const WTF::String& content, | 132 void saveHTMLContentToBuffer(const WTF::String& content, |
| 153 SerializeDomParam* param); | 133 SerializeDomParam* param); |
| 154 | 134 |
| 155 enum FlushOption { | 135 enum FlushOption { |
| 156 ForceFlush, | 136 ForceFlush, |
| 157 DoNotForceFlush, | 137 DoNotForceFlush, |
| 158 }; | 138 }; |
| 159 | 139 |
| 160 // Flushes the content buffer by encoding and sending the content to the | 140 // Flushes the content buffer by encoding and sending the content to the |
| 161 // WebPageSerializerClient. Content is not flushed if the buffer is not full | 141 // WebPageSerializerClient. Content is not flushed if the buffer is not full |
| 162 // unless force is 1. | 142 // unless FlushOption::ForceFlush is used. |
| 163 void encodeAndFlushBuffer(WebPageSerializerClient::PageSerializationStatus s
tatus, | 143 void encodeAndFlushBuffer(SerializeDomParam*, FlushOption); |
| 164 SerializeDomParam* param, | |
| 165 FlushOption); | |
| 166 // Serialize open tag of an specified element. | 144 // Serialize open tag of an specified element. |
| 167 void openTagToString(Element*, | 145 void handleOpenTag(Element*, SerializeDomParam*); |
| 168 SerializeDomParam* param); | 146 // Serialize value of URL-containing attribute of the specified element. |
| 147 void handleLinkAttr(Element*, SerializeDomParam*, const String& attrValue); |
| 169 // Serialize end tag of an specified element. | 148 // Serialize end tag of an specified element. |
| 170 void endTagToString(Element*, | 149 void handleEndTag(Element*, SerializeDomParam*); |
| 171 SerializeDomParam* param); | |
| 172 // Build content for a specified node | 150 // Build content for a specified node |
| 173 void buildContentForNode(Node*, | 151 void buildContentForNode(Node*, |
| 174 SerializeDomParam* param); | 152 SerializeDomParam* param); |
| 175 }; | 153 }; |
| 176 | 154 |
| 177 } // namespace blink | 155 } // namespace blink |
| 178 | 156 |
| 179 #endif | 157 #endif |
| OLD | NEW |