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

Side by Side Diff: third_party/WebKit/Source/platform/mhtml/ArchiveResourceCollection.cpp

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) 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2008 Apple 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 13 matching lines...) Expand all
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include "config.h" 29 #include "config.h"
30 #include "platform/mhtml/ArchiveResourceCollection.h" 30 #include "platform/mhtml/ArchiveResourceCollection.h"
31 31
32 #include "platform/mhtml/ArchiveResource.h" 32 #include "platform/mhtml/ArchiveResource.h"
33 #include "platform/mhtml/MHTMLArchive.h" 33 #include "platform/mhtml/MHTMLArchive.h"
34 #include "platform/mhtml/MHTMLParser.h"
34 #include "platform/weborigin/KURL.h" 35 #include "platform/weborigin/KURL.h"
35 #include "wtf/text/StringBuilder.h"
36 #include "wtf/text/WTFString.h" 36 #include "wtf/text/WTFString.h"
37 37
38 namespace blink { 38 namespace blink {
39 39
40 namespace {
41
42 // Converts |contentID| taken from a Content-ID MIME header
43 // into URI using "cid" scheme. Based primarily on an example
44 // from rfc2557 in section 9.5, but also based on more
45 // normative parts of specs like:
46 // - rfc2557 - MHTML - section 8.3 - "Use of the Content-ID header and CID URLs"
47 // - rfc1738 - URL - section 4 (reserved scheme names; includes "cid")
48 // - rfc2387 - multipart/related - section 3.4 - "Syntax" (cid := msg-id)
49 // - rfc0822 - msg-id = "<" addr-spec ">"; addr-spec = local-part "@" domain
50 KURL convertContentIDToURI(const String& contentID)
51 {
52 if (contentID.length() <= 2)
53 return KURL();
54
55 if (!contentID.startsWith('<') || !contentID.endsWith('>'))
56 return KURL();
57
58 StringBuilder uriBuilder;
59 uriBuilder.append("cid:");
60 uriBuilder.append(contentID, 1, contentID.length() - 2);
61 return KURL(KURL(), uriBuilder.toString());
62 }
63
64 }
65
66 ArchiveResourceCollection::ArchiveResourceCollection() 40 ArchiveResourceCollection::ArchiveResourceCollection()
67 { 41 {
68 } 42 }
69 43
70 ArchiveResourceCollection::~ArchiveResourceCollection() 44 ArchiveResourceCollection::~ArchiveResourceCollection()
71 { 45 {
72 } 46 }
73 47
74 void ArchiveResourceCollection::addAllResources(MHTMLArchive* archive) 48 void ArchiveResourceCollection::addAllResources(MHTMLArchive* archive)
75 { 49 {
(...skipping 11 matching lines...) Expand all
87 ASSERT(archive->mainResource()); 61 ASSERT(archive->mainResource());
88 62
89 const String& frameName = archive->mainResource()->frameName(); 63 const String& frameName = archive->mainResource()->frameName();
90 if (!frameName.isNull()) { 64 if (!frameName.isNull()) {
91 m_subframes.set(frameName, archive.get()); 65 m_subframes.set(frameName, archive.get());
92 } else { 66 } else {
93 // In the MHTML case, frames don't have a name so we use the URL ins tead. 67 // In the MHTML case, frames don't have a name so we use the URL ins tead.
94 m_subframes.set(archive->mainResource()->url().string(), archive.get ()); 68 m_subframes.set(archive->mainResource()->url().string(), archive.get ());
95 } 69 }
96 70
97 KURL cidURI = convertContentIDToURI(archive->mainResource()->contentID() ); 71 KURL cidURI = MHTMLParser::convertContentIDToURI(archive->mainResource() ->contentID());
98 if (cidURI.isValid()) 72 if (cidURI.isValid())
99 m_subframes.set(cidURI, archive.get()); 73 m_subframes.set(cidURI, archive.get());
100 } 74 }
101 } 75 }
102 76
103 // FIXME: Adding a resource directly to a DocumentLoader/ArchiveResourceCollecti on seems like bad design, but is API some apps rely on. 77 // FIXME: Adding a resource directly to a DocumentLoader/ArchiveResourceCollecti on seems like bad design, but is API some apps rely on.
104 // Can we change the design in a manner that will let us deprecate that API with out reducing functionality of those apps? 78 // Can we change the design in a manner that will let us deprecate that API with out reducing functionality of those apps?
105 void ArchiveResourceCollection::addResource(ArchiveResource& resource) 79 void ArchiveResourceCollection::addResource(ArchiveResource& resource)
106 { 80 {
107 const KURL& url = resource.url(); 81 const KURL& url = resource.url();
108 m_subresources.set(url, &resource); 82 m_subresources.set(url, &resource);
109 83
110 KURL cidURI = convertContentIDToURI(resource.contentID()); 84 KURL cidURI = MHTMLParser::convertContentIDToURI(resource.contentID());
111 if (cidURI.isValid()) 85 if (cidURI.isValid())
112 m_subresources.set(cidURI, &resource); 86 m_subresources.set(cidURI, &resource);
113 } 87 }
114 88
115 ArchiveResource* ArchiveResourceCollection::archiveResourceForURL(const KURL& ur l) 89 ArchiveResource* ArchiveResourceCollection::archiveResourceForURL(const KURL& ur l)
116 { 90 {
117 ArchiveResource* resource = m_subresources.get(url); 91 ArchiveResource* resource = m_subresources.get(url);
118 if (!resource) 92 if (!resource)
119 return 0; 93 return 0;
120 94
(...skipping 11 matching lines...) Expand all
132 106
133 DEFINE_TRACE(ArchiveResourceCollection) 107 DEFINE_TRACE(ArchiveResourceCollection)
134 { 108 {
135 #if ENABLE(OILPAN) 109 #if ENABLE(OILPAN)
136 visitor->trace(m_subresources); 110 visitor->trace(m_subresources);
137 visitor->trace(m_subframes); 111 visitor->trace(m_subframes);
138 #endif 112 #endif
139 } 113 }
140 114
141 } 115 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698