Changeset 87788 in webkit
- Timestamp:
- Jun 1, 2011 2:17:53 AM (13 years ago)
- Location:
- trunk/Source
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r87771 r87788 1 2011-06-01 Jay Civelli <jcivelli@chromium.org> 2 3 Reviewed by Adam Barth. 4 5 Added a method to generate RFC 2822 compliant date strings. 6 https://bugs.webkit.org/show_bug.cgi?id=7169 7 8 * wtf/DateMath.cpp: 9 (WTF::twoDigitStringFromNumber): 10 (WTF::makeRFC2822DateString): 11 * wtf/DateMath.h: 12 1 13 2011-05-31 Yong Li <yoli@rim.com> 2 14 -
trunk/Source/JavaScriptCore/wtf/DateMath.cpp
r81040 r87788 91 91 #include <stdint.h> 92 92 #include <time.h> 93 93 #include <wtf/text/StringBuilder.h> 94 94 95 95 #if HAVE(ERRNO_H) … … 179 179 { 180 180 return floor(ms / msPerDay); 181 } 182 183 static String twoDigitStringFromNumber(int number) 184 { 185 ASSERT(number >= 0 && number < 100); 186 if (number > 9) 187 return String::number(number); 188 return makeString("0", String::number(number)); 181 189 } 182 190 … … 1028 1036 return NaN; 1029 1037 return trunc(t); 1038 } 1039 1040 // See http://tools.ietf.org/html/rfc2822#section-3.3 for more information. 1041 String makeRFC2822DateString(unsigned dayOfWeek, unsigned day, unsigned month, unsigned year, unsigned hours, unsigned minutes, unsigned seconds, int utcOffset) 1042 { 1043 StringBuilder stringBuilder; 1044 stringBuilder.append(weekdayName[dayOfWeek]); 1045 stringBuilder.append(", "); 1046 stringBuilder.append(String::number(day)); 1047 stringBuilder.append(" "); 1048 stringBuilder.append(monthName[month]); 1049 stringBuilder.append(" "); 1050 stringBuilder.append(String::number(year)); 1051 stringBuilder.append(" "); 1052 1053 stringBuilder.append(twoDigitStringFromNumber(hours)); 1054 stringBuilder.append(':'); 1055 stringBuilder.append(twoDigitStringFromNumber(minutes)); 1056 stringBuilder.append(':'); 1057 stringBuilder.append(twoDigitStringFromNumber(seconds)); 1058 stringBuilder.append(' '); 1059 1060 stringBuilder.append(utcOffset > 0 ? "+" : "-"); 1061 int absoluteUTCOffset = abs(utcOffset); 1062 stringBuilder.append(twoDigitStringFromNumber(absoluteUTCOffset / 60)); 1063 stringBuilder.append(twoDigitStringFromNumber(absoluteUTCOffset % 60)); 1064 1065 return stringBuilder.toString(); 1030 1066 } 1031 1067 } // namespace WTF -
trunk/Source/JavaScriptCore/wtf/DateMath.h
r77785 r87788 52 52 #include <wtf/OwnArrayPtr.h> 53 53 #include <wtf/PassOwnArrayPtr.h> 54 #include <wtf/text/WTFString.h> 54 55 #include <wtf/UnusedParam.h> 55 56 … … 62 63 double parseDateFromNullTerminatedCharacters(const char* dateString); 63 64 double timeClip(double); 65 // dayOfWeek: [0, 6] 0 being Monday, day: [1, 31], month: [0, 11], year: ex: 2011, hours: [0, 23], minutes: [0, 59], seconds: [0, 59], utcOffset: [-720,720]. 66 String makeRFC2822DateString(unsigned dayOfWeek, unsigned day, unsigned month, unsigned year, unsigned hours, unsigned minutes, unsigned seconds, int utcOffset); 64 67 65 68 inline double jsCurrentTime() … … 107 110 using WTF::secondsPerMinute; 108 111 using WTF::parseDateFromNullTerminatedCharacters; 112 using WTF::makeRFC2822DateString; 109 113 using WTF::calculateUTCOffset; 110 114 using WTF::calculateDSTOffset; -
trunk/Source/WebCore/ChangeLog
r87780 r87788 1 2011-06-01 Jay Civelli <jcivelli@chromium.org> 2 3 Reviewed by Adam Barth. 4 5 Adding MHTML generation support to MHTMLArchive. 6 https://bugs.webkit.org/show_bug.cgi?id=7169 7 8 * loader/archive/mhtml/MHTMLArchive.cpp: 9 (WebCore::generateRandomBoundary): 10 (WebCore::replaceNonPrintableCharacters): 11 (WebCore::MHTMLArchive::generateMHTMLData): 12 * loader/archive/mhtml/MHTMLArchive.h: 13 * page/PageSerializer.cpp: 14 (WebCore::PageSerializer::serializeFrame): 15 (WebCore::PageSerializer::serializeCSSStyleSheet): 16 * platform/SharedBuffer.cpp: 17 (WebCore::SharedBuffer::append): 18 * platform/SharedBuffer.h: 19 1 20 2011-06-01 Dimitri Glazkov <dglazkov@chromium.org> 2 21 -
trunk/Source/WebCore/loader/archive/mhtml/MHTMLArchive.cpp
r87266 r87788 34 34 #include "MHTMLArchive.h" 35 35 36 #include "Base64.h" 37 #include "CryptographicallyRandomNumber.h" 38 #include "DateMath.h" 39 #include "Document.h" 40 #include "Frame.h" 36 41 #include "MHTMLParser.h" 37 #include "MIMEHeader.h" 42 #include "MIMETypeRegistry.h" 43 #include "Page.h" 44 #include "PageSerializer.h" 45 #include "QuotedPrintable.h" 46 #include "SharedBuffer.h" 47 #include <sys/time.h> 48 #include <wtf/StdLibExtras.h> 49 #include <wtf/text/StringBuilder.h> 38 50 39 51 namespace WebCore { 52 53 const char* const quotedPrintable = "quoted-printable"; 54 const char* const base64 = "base64"; 55 56 static String generateRandomBoundary() 57 { 58 // Trying to generate random boundaries similar to IE/UnMHT (ex: ----=_NextPart_000_001B_01CC157B.96F808A0). 59 const size_t randomValuesLength = 10; 60 char randomValues[randomValuesLength]; 61 cryptographicallyRandomValues(&randomValues, randomValuesLength); 62 StringBuilder stringBuilder; 63 stringBuilder.append("----=_NextPart_000_"); 64 for (size_t i = 0; i < randomValuesLength; ++i) { 65 if (i == 2) 66 stringBuilder.append('_'); 67 else if (i == 6) 68 stringBuilder.append('.'); 69 stringBuilder.append(lowerNibbleToASCIIHexDigit(randomValues[i])); 70 stringBuilder.append(upperNibbleToASCIIHexDigit(randomValues[i])); 71 } 72 return stringBuilder.toString(); 73 } 74 75 static String replaceNonPrintableCharacters(const String& text) 76 { 77 StringBuilder stringBuilder; 78 for (size_t i = 0; i < text.length(); ++i) { 79 if (isASCIIPrintable(text[i])) 80 stringBuilder.append(text[i]); 81 else 82 stringBuilder.append('?'); 83 } 84 return stringBuilder.toString(); 85 } 40 86 41 87 MHTMLArchive::MHTMLArchive() … … 72 118 } 73 119 120 PassRefPtr<SharedBuffer> MHTMLArchive::generateMHTMLData(Page* page) 121 { 122 Vector<PageSerializer::Resource> resources; 123 PageSerializer pageSerializer(&resources); 124 pageSerializer.serialize(page); 125 126 String boundary = generateRandomBoundary(); 127 String endOfResourceBoundary = makeString("--", boundary, "\r\n"); 128 129 String dateString; 130 timeval timeValue = { 0 }; 131 if (!gettimeofday(&timeValue, 0)) { 132 tm timeAndDate = { 0 }; 133 if (localtime_r(&(timeValue.tv_sec), &timeAndDate)) 134 dateString = makeRFC2822DateString(timeAndDate.tm_wday, timeAndDate.tm_mday, timeAndDate.tm_mon, 1900 + timeAndDate.tm_year, timeAndDate.tm_hour, timeAndDate.tm_min, timeAndDate.tm_sec, calculateUTCOffset() / (1000 * 60)); 135 else 136 ASSERT_NOT_REACHED(); 137 } else 138 ASSERT_NOT_REACHED(); 139 140 StringBuilder stringBuilder; 141 stringBuilder.append("From: <Saved by WebKit>\r\n"); 142 stringBuilder.append("Subject: "); 143 // We replace non ASCII characters with '?' characters to match IE's behavior. 144 stringBuilder.append(replaceNonPrintableCharacters(page->mainFrame()->document()->title())); 145 if (!dateString.isEmpty()) { 146 stringBuilder.append("\r\nDate: "); 147 stringBuilder.append(dateString); 148 } 149 stringBuilder.append("\r\nMIME-Version: 1.0\r\n"); 150 stringBuilder.append("Content-Type: multipart/related;\r\n"); 151 stringBuilder.append("\ttype=\""); 152 stringBuilder.append(page->mainFrame()->document()->suggestedMIMEType()); 153 stringBuilder.append("\";\r\n"); 154 stringBuilder.append("\tboundary=\""); 155 stringBuilder.append(boundary); 156 stringBuilder.append("\"\r\n\r\n"); 157 158 // We use utf8() below instead of ascii() as ascii() replaces CRLFs with ?? (we still only have put ASCII characters in it). 159 ASSERT(stringBuilder.toString().containsOnlyASCII()); 160 CString asciiString = stringBuilder.toString().utf8(); 161 RefPtr<SharedBuffer> mhtmlData = SharedBuffer::create(); 162 mhtmlData->append(asciiString.data(), asciiString.length()); 163 164 for (size_t i = 0; i < resources.size(); ++i) { 165 const PageSerializer::Resource& resource = resources[i]; 166 167 stringBuilder.clear(); 168 stringBuilder.append(endOfResourceBoundary); 169 stringBuilder.append("Content-Type: "); 170 stringBuilder.append(resource.mimeType); 171 172 const char* contentEncoding = MIMETypeRegistry::isSupportedJavaScriptMIMEType(resource.mimeType) || MIMETypeRegistry::isSupportedNonImageMIMEType(resource.mimeType) ? quotedPrintable : base64; 173 stringBuilder.append("\r\nContent-Transfer-Encoding: "); 174 stringBuilder.append(contentEncoding); 175 stringBuilder.append("\r\nContent-Location: "); 176 stringBuilder.append(resource.url); 177 stringBuilder.append("\r\n\r\n"); 178 179 asciiString = stringBuilder.toString().utf8(); 180 mhtmlData->append(asciiString.data(), asciiString.length()); 181 182 // FIXME: ideally we would encode the content as a stream without having to fetch it all. 183 const char* data = resource.data->data(); 184 size_t dataLength = resource.data->size(); 185 Vector<char> encodedData; 186 if (!strcmp(contentEncoding, quotedPrintable)) { 187 quotedPrintableEncode(data, dataLength, encodedData); 188 mhtmlData->append(encodedData.data(), encodedData.size()); 189 mhtmlData->append("\r\n", 2); 190 } else { 191 ASSERT(!strcmp(contentEncoding, base64)); 192 // We are not specifying insertLFs = true below as it would cut the lines with LFs and MHTML requires CRLFs. 193 base64Encode(data, dataLength, encodedData); 194 const size_t maximumLineLength = 76; 195 size_t index = 0; 196 size_t encodedDataLength = encodedData.size(); 197 do { 198 size_t lineLength = std::min(encodedDataLength - index, maximumLineLength); 199 mhtmlData->append(encodedData.data() + index, lineLength); 200 mhtmlData->append("\r\n", 2); 201 index += maximumLineLength; 202 } while (index < encodedDataLength); 203 } 204 } 205 206 asciiString = makeString("--", boundary, "--\r\n").utf8(); 207 mhtmlData->append(asciiString.data(), asciiString.length()); 208 209 return mhtmlData.release(); 210 } 211 74 212 } 75 213 #endif -
trunk/Source/WebCore/loader/archive/mhtml/MHTMLArchive.h
r87189 r87788 39 39 40 40 class MHTMLParser; 41 class Page; 42 class SharedBuffer; 41 43 42 44 class MHTMLArchive : public Archive { … … 46 48 static PassRefPtr<MHTMLArchive> create(); 47 49 static PassRefPtr<MHTMLArchive> create(const KURL&, SharedBuffer*); 50 51 static PassRefPtr<SharedBuffer> generateMHTMLData(Page*); 48 52 49 53 private: -
trunk/Source/WebCore/page/PageSerializer.cpp
r86949 r87788 207 207 Vector<Node*> nodes; 208 208 SerializerMarkupAccumulator accumulator(this, document, &nodes); 209 TextEncoding textEncoding(TextEncoding(document->charset())); 210 ASSERT(textEncoding.isValid()); 209 TextEncoding textEncoding(document->charset()); 210 CString data; 211 if (!textEncoding.isValid()) { 212 // FIXME: iframes used as images trigger this. We should deal with them correctly. 213 return; 214 } 211 215 String text = accumulator.serializeNodes(document->documentElement(), 0, IncludeNode); 212 216 CString frameHTML = textEncoding.encode(text.characters(), text.length(), EntitiesForUnencodables); … … 275 279 if (url.isValid() && !m_resourceURLs.contains(url)) { 276 280 // FIXME: We should check whether a charset has been specified and if none was found add one. 277 TextEncoding textEncoding = TextEncoding(styleSheet->charset());281 TextEncoding textEncoding(styleSheet->charset()); 278 282 ASSERT(textEncoding.isValid()); 279 283 String textString = cssText.toString(); -
trunk/Source/WebCore/platform/SharedBuffer.cpp
r81710 r87788 118 118 } 119 119 120 void SharedBuffer::append(SharedBuffer* data) 121 { 122 const char* segment; 123 size_t position = 0; 124 while (size_t length = data->getSomeData(segment, position)) { 125 append(segment, length); 126 position += length; 127 } 128 } 129 120 130 void SharedBuffer::append(const char* data, unsigned length) 121 131 { -
trunk/Source/WebCore/platform/SharedBuffer.h
r87312 r87788 85 85 bool isEmpty() const { return !size(); } 86 86 87 void append(SharedBuffer*); 87 88 void append(const char*, unsigned); 88 89 void clear(); -
trunk/Source/WebKit/chromium/ChangeLog
r87786 r87788 1 2011-06-01 Jay Civelli <jcivelli@chromium.org> 2 3 Reviewed by Adam Barth. 4 5 Adding MHTML generation support to MHTMLArchive. 6 https://bugs.webkit.org/show_bug.cgi?id=7169 7 8 * public/WebPageSerializer.h: 9 * src/WebPageSerializer.cpp: 10 (WebKit::WebPageSerializer::serializeToMHTML): 11 1 12 2011-06-01 Mikhail Naganov <mnaganov@chromium.org> 2 13 -
trunk/Source/WebKit/chromium/public/WebPageSerializer.h
r85244 r87788 59 59 WEBKIT_API static void serialize(WebView*, WebVector<Resource>*); 60 60 61 // Serializes the WebView contents to a MHTML representation. 62 WEBKIT_API static WebCString serializeToMHTML(WebView*); 63 61 64 // IMPORTANT: 62 65 // The API below is an older implementation of a pageserialization that -
trunk/Source/WebKit/chromium/src/WebPageSerializer.cpp
r85244 r87788 40 40 #include "HTMLNames.h" 41 41 #include "KURL.h" 42 #include "MHTMLArchive.h" 42 43 #include "PageSerializer.h" 43 44 #include "Vector.h" … … 201 202 } 202 203 204 WebCString WebPageSerializer::serializeToMHTML(WebView* view) 205 { 206 RefPtr<SharedBuffer> mhtml = MHTMLArchive::generateMHTMLData(static_cast<WebViewImpl*>(view)->page()); 207 // FIXME: we are copying all the data here. Idealy we would have a WebSharedData(). 208 return WebCString(mhtml->data(), mhtml->size()); 209 } 210 203 211 bool WebPageSerializer::serialize(WebFrame* frame, 204 212 bool recursive,
Note: See TracChangeset
for help on using the changeset viewer.