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

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

Issue 2846303002: Replace ASSERT with DCHECK in platform/ (Closed)
Patch Set: rebase Created 3 years, 7 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 if (url.ProtocolIs("content")) 122 if (url.ProtocolIs("content"))
123 return true; 123 return true;
124 #endif 124 #endif
125 return false; 125 return false;
126 } 126 }
127 127
128 void MHTMLArchive::GenerateMHTMLHeader(const String& boundary, 128 void MHTMLArchive::GenerateMHTMLHeader(const String& boundary,
129 const String& title, 129 const String& title,
130 const String& mime_type, 130 const String& mime_type,
131 Vector<char>& output_buffer) { 131 Vector<char>& output_buffer) {
132 ASSERT(!boundary.IsEmpty()); 132 DCHECK(!boundary.IsEmpty());
133 ASSERT(!mime_type.IsEmpty()); 133 DCHECK(!mime_type.IsEmpty());
134 134
135 DateComponents now; 135 DateComponents now;
136 now.SetMillisecondsSinceEpochForDateTime(CurrentTimeMS()); 136 now.SetMillisecondsSinceEpochForDateTime(CurrentTimeMS());
137 // TODO(lukasza): Passing individual date/time components seems fragile. 137 // TODO(lukasza): Passing individual date/time components seems fragile.
138 String date_string = MakeRFC2822DateString( 138 String date_string = MakeRFC2822DateString(
139 now.WeekDay(), now.MonthDay(), now.Month(), now.FullYear(), now.Hour(), 139 now.WeekDay(), now.MonthDay(), now.Month(), now.FullYear(), now.Hour(),
140 now.Minute(), now.Second(), 0); 140 now.Minute(), now.Second(), 0);
141 141
142 StringBuilder string_builder; 142 StringBuilder string_builder;
143 string_builder.Append("From: <Saved by Blink>\r\n"); 143 string_builder.Append("From: <Saved by Blink>\r\n");
144 string_builder.Append("Subject: "); 144 string_builder.Append("Subject: ");
145 // We replace non ASCII characters with '?' characters to match IE's behavior. 145 // We replace non ASCII characters with '?' characters to match IE's behavior.
146 string_builder.Append(ReplaceNonPrintableCharacters(title)); 146 string_builder.Append(ReplaceNonPrintableCharacters(title));
147 string_builder.Append("\r\nDate: "); 147 string_builder.Append("\r\nDate: ");
148 string_builder.Append(date_string); 148 string_builder.Append(date_string);
149 string_builder.Append("\r\nMIME-Version: 1.0\r\n"); 149 string_builder.Append("\r\nMIME-Version: 1.0\r\n");
150 string_builder.Append("Content-Type: multipart/related;\r\n"); 150 string_builder.Append("Content-Type: multipart/related;\r\n");
151 string_builder.Append("\ttype=\""); 151 string_builder.Append("\ttype=\"");
152 string_builder.Append(mime_type); 152 string_builder.Append(mime_type);
153 string_builder.Append("\";\r\n"); 153 string_builder.Append("\";\r\n");
154 string_builder.Append("\tboundary=\""); 154 string_builder.Append("\tboundary=\"");
155 string_builder.Append(boundary); 155 string_builder.Append(boundary);
156 string_builder.Append("\"\r\n\r\n"); 156 string_builder.Append("\"\r\n\r\n");
157 157
158 // We use utf8() below instead of ascii() as ascii() replaces CRLFs with ?? 158 // We use utf8() below instead of ascii() as ascii() replaces CRLFs with ??
159 // (we still only have put ASCII characters in it). 159 // (we still only have put ASCII characters in it).
160 ASSERT(string_builder.ToString().ContainsOnlyASCII()); 160 DCHECK(string_builder.ToString().ContainsOnlyASCII());
161 CString ascii_string = string_builder.ToString().Utf8(); 161 CString ascii_string = string_builder.ToString().Utf8();
162 162
163 output_buffer.Append(ascii_string.data(), ascii_string.length()); 163 output_buffer.Append(ascii_string.data(), ascii_string.length());
164 } 164 }
165 165
166 void MHTMLArchive::GenerateMHTMLPart(const String& boundary, 166 void MHTMLArchive::GenerateMHTMLPart(const String& boundary,
167 const String& content_id, 167 const String& content_id,
168 EncodingPolicy encoding_policy, 168 EncodingPolicy encoding_policy,
169 const SerializedResource& resource, 169 const SerializedResource& resource,
170 Vector<char>& output_buffer) { 170 Vector<char>& output_buffer) {
171 ASSERT(!boundary.IsEmpty()); 171 DCHECK(!boundary.IsEmpty());
172 ASSERT(content_id.IsEmpty() || content_id[0] == '<'); 172 ASSERT(content_id.IsEmpty() || content_id[0] == '<');
173 173
174 StringBuilder string_builder; 174 StringBuilder string_builder;
175 string_builder.Append("--"); 175 string_builder.Append("--");
176 string_builder.Append(boundary); 176 string_builder.Append(boundary);
177 string_builder.Append("\r\n"); 177 string_builder.Append("\r\n");
178 178
179 string_builder.Append("Content-Type: "); 179 string_builder.Append("Content-Type: ");
180 string_builder.Append(resource.mime_type); 180 string_builder.Append(resource.mime_type);
181 string_builder.Append("\r\n"); 181 string_builder.Append("\r\n");
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 output_buffer.Append(encoded_data.data() + index, line_length); 242 output_buffer.Append(encoded_data.data() + index, line_length);
243 output_buffer.Append("\r\n", 2u); 243 output_buffer.Append("\r\n", 2u);
244 index += kMaximumLineLength; 244 index += kMaximumLineLength;
245 } while (index < encoded_data_length); 245 } while (index < encoded_data_length);
246 } 246 }
247 } 247 }
248 } 248 }
249 249
250 void MHTMLArchive::GenerateMHTMLFooterForTesting(const String& boundary, 250 void MHTMLArchive::GenerateMHTMLFooterForTesting(const String& boundary,
251 Vector<char>& output_buffer) { 251 Vector<char>& output_buffer) {
252 ASSERT(!boundary.IsEmpty()); 252 DCHECK(!boundary.IsEmpty());
253 CString ascii_string = String("--" + boundary + "--\r\n").Utf8(); 253 CString ascii_string = String("--" + boundary + "--\r\n").Utf8();
254 output_buffer.Append(ascii_string.data(), ascii_string.length()); 254 output_buffer.Append(ascii_string.data(), ascii_string.length());
255 } 255 }
256 256
257 void MHTMLArchive::SetMainResource(ArchiveResource* main_resource) { 257 void MHTMLArchive::SetMainResource(ArchiveResource* main_resource) {
258 main_resource_ = main_resource; 258 main_resource_ = main_resource;
259 } 259 }
260 260
261 void MHTMLArchive::AddSubresource(ArchiveResource* resource) { 261 void MHTMLArchive::AddSubresource(ArchiveResource* resource) {
262 const KURL& url = resource->Url(); 262 const KURL& url = resource->Url();
263 subresources_.Set(url, resource); 263 subresources_.Set(url, resource);
264 KURL cid_uri = MHTMLParser::ConvertContentIDToURI(resource->ContentID()); 264 KURL cid_uri = MHTMLParser::ConvertContentIDToURI(resource->ContentID());
265 if (cid_uri.IsValid()) 265 if (cid_uri.IsValid())
266 subresources_.Set(cid_uri, resource); 266 subresources_.Set(cid_uri, resource);
267 } 267 }
268 268
269 ArchiveResource* MHTMLArchive::SubresourceForURL(const KURL& url) const { 269 ArchiveResource* MHTMLArchive::SubresourceForURL(const KURL& url) const {
270 return subresources_.at(url.GetString()); 270 return subresources_.at(url.GetString());
271 } 271 }
272 272
273 DEFINE_TRACE(MHTMLArchive) { 273 DEFINE_TRACE(MHTMLArchive) {
274 visitor->Trace(main_resource_); 274 visitor->Trace(main_resource_);
275 visitor->Trace(subresources_); 275 visitor->Trace(subresources_);
276 } 276 }
277 277
278 } // namespace blink 278 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698