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

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

Issue 2017303002: Revert of Remove StringBuilder::appendLiteral. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months 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) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 ASSERT(!mimeType.isEmpty()); 98 ASSERT(!mimeType.isEmpty());
99 99
100 DateComponents now; 100 DateComponents now;
101 now.setMillisecondsSinceEpochForDateTime(currentTimeMS()); 101 now.setMillisecondsSinceEpochForDateTime(currentTimeMS());
102 // TODO(lukasza): Passing individual date/time components seems fragile. 102 // TODO(lukasza): Passing individual date/time components seems fragile.
103 String dateString = makeRFC2822DateString( 103 String dateString = makeRFC2822DateString(
104 now.weekDay(), now.monthDay(), now.month(), now.fullYear(), 104 now.weekDay(), now.monthDay(), now.month(), now.fullYear(),
105 now.hour(), now.minute(), now.second(), 0); 105 now.hour(), now.minute(), now.second(), 0);
106 106
107 StringBuilder stringBuilder; 107 StringBuilder stringBuilder;
108 stringBuilder.append("From: <Saved by Blink>\r\n"); 108 stringBuilder.appendLiteral("From: <Saved by Blink>\r\n");
109 stringBuilder.append("Subject: "); 109 stringBuilder.appendLiteral("Subject: ");
110 // We replace non ASCII characters with '?' characters to match IE's behavio r. 110 // We replace non ASCII characters with '?' characters to match IE's behavio r.
111 stringBuilder.append(replaceNonPrintableCharacters(title)); 111 stringBuilder.append(replaceNonPrintableCharacters(title));
112 stringBuilder.append("\r\nDate: "); 112 stringBuilder.appendLiteral("\r\nDate: ");
113 stringBuilder.append(dateString); 113 stringBuilder.append(dateString);
114 stringBuilder.append("\r\nMIME-Version: 1.0\r\n"); 114 stringBuilder.appendLiteral("\r\nMIME-Version: 1.0\r\n");
115 stringBuilder.append("Content-Type: multipart/related;\r\n"); 115 stringBuilder.appendLiteral("Content-Type: multipart/related;\r\n");
116 stringBuilder.append("\ttype=\""); 116 stringBuilder.appendLiteral("\ttype=\"");
117 stringBuilder.append(mimeType); 117 stringBuilder.append(mimeType);
118 stringBuilder.append("\";\r\n"); 118 stringBuilder.appendLiteral("\";\r\n");
119 stringBuilder.append("\tboundary=\""); 119 stringBuilder.appendLiteral("\tboundary=\"");
120 stringBuilder.append(boundary); 120 stringBuilder.append(boundary);
121 stringBuilder.append("\"\r\n\r\n"); 121 stringBuilder.appendLiteral("\"\r\n\r\n");
122 122
123 // We use utf8() below instead of ascii() as ascii() replaces CRLFs with ?? 123 // We use utf8() below instead of ascii() as ascii() replaces CRLFs with ??
124 // (we still only have put ASCII characters in it). 124 // (we still only have put ASCII characters in it).
125 ASSERT(stringBuilder.toString().containsOnlyASCII()); 125 ASSERT(stringBuilder.toString().containsOnlyASCII());
126 CString asciiString = stringBuilder.toString().utf8(); 126 CString asciiString = stringBuilder.toString().utf8();
127 127
128 outputBuffer.append(asciiString.data(), asciiString.length()); 128 outputBuffer.append(asciiString.data(), asciiString.length());
129 } 129 }
130 130
131 void MHTMLArchive::generateMHTMLPart( 131 void MHTMLArchive::generateMHTMLPart(
132 const String& boundary, 132 const String& boundary,
133 const String& contentID, 133 const String& contentID,
134 EncodingPolicy encodingPolicy, 134 EncodingPolicy encodingPolicy,
135 const SerializedResource& resource, 135 const SerializedResource& resource,
136 SharedBuffer& outputBuffer) 136 SharedBuffer& outputBuffer)
137 { 137 {
138 ASSERT(!boundary.isEmpty()); 138 ASSERT(!boundary.isEmpty());
139 ASSERT(contentID.isEmpty() || contentID[0] == '<'); 139 ASSERT(contentID.isEmpty() || contentID[0] == '<');
140 140
141 StringBuilder stringBuilder; 141 StringBuilder stringBuilder;
142 stringBuilder.append("--"); 142 stringBuilder.append("--");
143 stringBuilder.append(boundary); 143 stringBuilder.append(boundary);
144 stringBuilder.append("\r\n"); 144 stringBuilder.append("\r\n");
145 145
146 stringBuilder.append("Content-Type: "); 146 stringBuilder.appendLiteral("Content-Type: ");
147 stringBuilder.append(resource.mimeType); 147 stringBuilder.append(resource.mimeType);
148 stringBuilder.append("\r\n"); 148 stringBuilder.appendLiteral("\r\n");
149 149
150 if (!contentID.isEmpty()) { 150 if (!contentID.isEmpty()) {
151 stringBuilder.append("Content-ID: "); 151 stringBuilder.appendLiteral("Content-ID: ");
152 stringBuilder.append(contentID); 152 stringBuilder.append(contentID);
153 stringBuilder.append("\r\n"); 153 stringBuilder.appendLiteral("\r\n");
154 } 154 }
155 155
156 const char* contentEncoding = 0; 156 const char* contentEncoding = 0;
157 if (encodingPolicy == UseBinaryEncoding) 157 if (encodingPolicy == UseBinaryEncoding)
158 contentEncoding = binary; 158 contentEncoding = binary;
159 else if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(resource.mimeType) || MIMETypeRegistry::isSupportedNonImageMIMEType(resource.mimeType)) 159 else if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(resource.mimeType) || MIMETypeRegistry::isSupportedNonImageMIMEType(resource.mimeType))
160 contentEncoding = quotedPrintable; 160 contentEncoding = quotedPrintable;
161 else 161 else
162 contentEncoding = base64; 162 contentEncoding = base64;
163 163
164 stringBuilder.append("Content-Transfer-Encoding: "); 164 stringBuilder.appendLiteral("Content-Transfer-Encoding: ");
165 stringBuilder.append(contentEncoding); 165 stringBuilder.append(contentEncoding);
166 stringBuilder.append("\r\n"); 166 stringBuilder.appendLiteral("\r\n");
167 167
168 if (!resource.url.protocolIsAbout()) { 168 if (!resource.url.protocolIsAbout()) {
169 stringBuilder.append("Content-Location: "); 169 stringBuilder.appendLiteral("Content-Location: ");
170 stringBuilder.append(resource.url.getString()); 170 stringBuilder.append(resource.url.getString());
171 stringBuilder.append("\r\n"); 171 stringBuilder.appendLiteral("\r\n");
172 } 172 }
173 173
174 stringBuilder.append("\r\n"); 174 stringBuilder.appendLiteral("\r\n");
175 175
176 CString asciiString = stringBuilder.toString().utf8(); 176 CString asciiString = stringBuilder.toString().utf8();
177 outputBuffer.append(asciiString.data(), asciiString.length()); 177 outputBuffer.append(asciiString.data(), asciiString.length());
178 178
179 if (!strcmp(contentEncoding, binary)) { 179 if (!strcmp(contentEncoding, binary)) {
180 const char* data; 180 const char* data;
181 size_t position = 0; 181 size_t position = 0;
182 while (size_t length = resource.data->getSomeData(data, position)) { 182 while (size_t length = resource.data->getSomeData(data, position)) {
183 outputBuffer.append(data, length); 183 outputBuffer.append(data, length);
184 position += length; 184 position += length;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 return m_subresources.get(url.getString()); 237 return m_subresources.get(url.getString());
238 } 238 }
239 239
240 DEFINE_TRACE(MHTMLArchive) 240 DEFINE_TRACE(MHTMLArchive)
241 { 241 {
242 visitor->trace(m_mainResource); 242 visitor->trace(m_mainResource);
243 visitor->trace(m_subresources); 243 visitor->trace(m_subresources);
244 } 244 }
245 245
246 } // namespace blink 246 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/Color.cpp ('k') | third_party/WebKit/Source/platform/text/DateTimeFormat.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698