Chromium Code Reviews| 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 26 matching lines...) Expand all Loading... | |
| 37 #include "wtf/text/StringBuilder.h" | 37 #include "wtf/text/StringBuilder.h" |
| 38 #include "wtf/text/StringHash.h" | 38 #include "wtf/text/StringHash.h" |
| 39 #include "wtf/text/WTFString.h" | 39 #include "wtf/text/WTFString.h" |
| 40 | 40 |
| 41 #include "public/platform/WebString.h" | 41 #include "public/platform/WebString.h" |
| 42 #include "public/platform/WebURL.h" | 42 #include "public/platform/WebURL.h" |
| 43 #include "public/web/WebPageSerializer.h" | 43 #include "public/web/WebPageSerializer.h" |
| 44 #include "public/web/WebPageSerializerClient.h" | 44 #include "public/web/WebPageSerializerClient.h" |
| 45 #include "web/WebEntities.h" | 45 #include "web/WebEntities.h" |
| 46 | 46 |
| 47 #include <utility> | |
|
Łukasz Anforowicz
2015/12/16 21:39:02
I think I should have added this include earlier -
| |
| 48 | |
| 47 namespace WTF { | 49 namespace WTF { |
| 48 class TextEncoding; | 50 class TextEncoding; |
| 49 } | 51 } |
| 50 | 52 |
| 51 namespace blink { | 53 namespace blink { |
| 52 | 54 |
| 53 class Document; | 55 class Document; |
| 54 class Element; | 56 class Element; |
| 57 class Frame; | |
| 55 class Node; | 58 class Node; |
| 59 class WebFrame; | |
| 56 class WebLocalFrame; | 60 class WebLocalFrame; |
| 57 class WebLocalFrameImpl; | 61 class WebLocalFrameImpl; |
| 58 | 62 |
| 59 // Responsible for serializing the specified frame into html | 63 // Responsible for serializing the specified frame into html |
| 60 // (replacing links with paths to local files). | 64 // (replacing links with paths to local files). |
| 61 class WebPageSerializerImpl { | 65 class WebPageSerializerImpl { |
| 62 STACK_ALLOCATED(); | 66 STACK_ALLOCATED(); |
| 63 public: | 67 public: |
| 64 // Do serialization action. | 68 // Do serialization action. |
| 65 // | 69 // |
| 66 // Returns false to indicate that no data has been serialized (i.e. because | 70 // Returns false to indicate that no data has been serialized (i.e. because |
| 67 // the target frame didn't have a valid url). | 71 // the target frame didn't have a valid url). |
| 68 // | 72 // |
| 69 // Synchronously calls WebPageSerializerClient methods to report | 73 // Synchronously calls WebPageSerializerClient methods to report |
| 70 // serialization results. See WebPageSerializerClient comments for more | 74 // serialization results. See WebPageSerializerClient comments for more |
| 71 // details. | 75 // details. |
| 72 bool serialize(); | 76 bool serialize(); |
| 73 | 77 |
| 74 // The parameter specifies which frame need to be serialized. | 78 // The parameter specifies which frame need to be serialized. |
| 75 // The parameter delegate specifies the pointer of interface | 79 // The parameter delegate specifies the pointer of interface |
| 76 // DomSerializerDelegate provide sink interface which can receive the | 80 // DomSerializerDelegate provide sink interface which can receive the |
| 77 // individual chunks of data to be saved. | 81 // individual chunks of data to be saved. |
| 78 // The parameter urlsToLocalPaths contains a mapping between original URLs | 82 // The parameter urlsToLocalPaths contains a mapping between original URLs |
| 79 // of saved resources and corresponding local file paths. | 83 // of saved resources and corresponding local file paths. |
| 80 WebPageSerializerImpl( | 84 WebPageSerializerImpl( |
| 81 WebLocalFrame*, | 85 WebLocalFrame*, |
| 82 WebPageSerializerClient*, | 86 WebPageSerializerClient*, |
| 83 const WebVector<std::pair<WebURL, WebString>>& urlsToLocalPaths); | 87 const WebVector<std::pair<WebURL, WebString>>& urlsToLocalPaths, |
| 88 const WebVector<std::pair<WebFrame*, WebString>>& framesToLocalPaths); | |
| 84 | 89 |
| 85 private: | 90 private: |
| 86 // Specified frame which need to be serialized; | 91 // Specified frame which need to be serialized; |
| 87 RawPtrWillBeMember<WebLocalFrameImpl> m_specifiedWebLocalFrameImpl; | 92 RawPtrWillBeMember<WebLocalFrameImpl> m_specifiedWebLocalFrameImpl; |
| 88 // Pointer of WebPageSerializerClient | 93 // Pointer of WebPageSerializerClient |
| 89 WebPageSerializerClient* m_client; | 94 WebPageSerializerClient* m_client; |
| 90 // This hash map is used to map resource URL of original link to its local | 95 // Map from URL of a savable resource (i.e. URL of an image) to a local path |
| 91 // file path. | 96 // that the link should be replaced with. |
| 92 typedef HashMap<WTF::String, WTF::String> LinkLocalPathMap; | 97 HashMap<WTF::String, WTF::String> m_urlToLocalPath; |
| 93 // local_links_ include all pair of local resource path and corresponding | 98 // Map from frame to a local path that the frame's src attribute should be |
| 94 // original link. | 99 // replaced with. |
| 95 LinkLocalPathMap m_localLinks; | 100 HashMap<Frame*, WTF::String> m_frameToLocalPath; |
| 96 // Data buffer for saving result of serialized DOM data. | 101 // Data buffer for saving result of serialized DOM data. |
| 97 StringBuilder m_dataBuffer; | 102 StringBuilder m_dataBuffer; |
| 98 | 103 |
| 99 // Web entities conversion maps. | 104 // Web entities conversion maps. |
| 100 WebEntities m_htmlEntities; | 105 WebEntities m_htmlEntities; |
| 101 WebEntities m_xmlEntities; | 106 WebEntities m_xmlEntities; |
| 102 | 107 |
| 103 class SerializeDomParam { | 108 class SerializeDomParam { |
| 104 STACK_ALLOCATED(); | 109 STACK_ALLOCATED(); |
| 105 public: | 110 public: |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 FlushOption); | 164 FlushOption); |
| 160 // Serialize open tag of an specified element. | 165 // Serialize open tag of an specified element. |
| 161 void openTagToString(Element*, | 166 void openTagToString(Element*, |
| 162 SerializeDomParam* param); | 167 SerializeDomParam* param); |
| 163 // Serialize end tag of an specified element. | 168 // Serialize end tag of an specified element. |
| 164 void endTagToString(Element*, | 169 void endTagToString(Element*, |
| 165 SerializeDomParam* param); | 170 SerializeDomParam* param); |
| 166 // Build content for a specified node | 171 // Build content for a specified node |
| 167 void buildContentForNode(Node*, | 172 void buildContentForNode(Node*, |
| 168 SerializeDomParam* param); | 173 SerializeDomParam* param); |
| 174 | |
| 175 // Appends attrName="escapedAttrValue" to result. | |
| 176 void appendAttribute( | |
| 177 StringBuilder& result, | |
| 178 bool isHTMLDocument, | |
| 179 const String& attrName, | |
| 180 const String& attrValue); | |
| 169 }; | 181 }; |
| 170 | 182 |
| 171 } // namespace blink | 183 } // namespace blink |
| 172 | 184 |
| 173 #endif | 185 #endif |
| OLD | NEW |