Changeset 116591 in webkit
- Timestamp:
- May 9, 2012 6:13:35 PM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r116587 r116591 1 2012-05-09 Charles Wei <charles.wei@torchmobile.com.cn> 2 3 [BlackBerry] Refactor data scheme support 4 https://bugs.webkit.org/show_bug.cgi?id=85938 5 6 Reviewed by Rob Buis. 7 8 We will create a DataStream in our platform repository, 9 so that can be wrapped up by NetworkJob for webkit rendering, 10 and by DownloadStream for downloading. 11 12 Refactor, no new tests. 13 14 * platform/network/blackberry/NetworkJob.cpp: 15 (WebCore::NetworkJob::NetworkJob): 16 (WebCore::NetworkJob::initialize): 17 (WebCore::NetworkJob::cancelJob): 18 (WebCore::NetworkJob::sendResponseIfNeeded): 19 * platform/network/blackberry/NetworkJob.h: 20 (NetworkJob): 21 * platform/network/blackberry/NetworkManager.cpp: 22 (WebCore::NetworkManager::startJob): 23 1 24 2012-05-09 Dana Jansens <danakj@chromium.org> 2 25 -
trunk/Source/WebCore/platform/network/blackberry/NetworkJob.cpp
r116308 r116591 21 21 22 22 #include "AboutData.h" 23 #include "Base64.h"24 23 #include "Chrome.h" 25 24 #include "ChromeClient.h" … … 42 41 #include <BlackBerryPlatformWebKitCredits.h> 43 42 #include <BuildInformation.h> 43 #include <LocalizeResource.h> 44 44 #include <network/MultipartStream.h> 45 #include <network/NetworkRequest.h>46 45 #include <network/NetworkStreamFactory.h> 47 #include <wtf/ASCIICType.h>48 46 49 47 namespace WebCore { … … 64 62 { 65 63 return statusCode == 401; 66 }67 68 static void escapeDecode(const char* src, int length, Vector<char>& out)69 {70 out.resize(length);71 const char* const srcEnd = src + length;72 char* dst = out.data();73 for (; src < srcEnd; ) {74 char inputChar = *src++;75 if (inputChar == '%' && src + 2 <= srcEnd) {76 int digit1 = 0;77 char character = *src++;78 if (isASCIIHexDigit(character))79 digit1 = toASCIIHexValue(character);80 81 int digit2 = 0;82 character = *src++;83 if (isASCIIHexDigit(character))84 digit2 = toASCIIHexValue(character);85 86 *dst++ = (digit1 << 4) | digit2;87 } else88 *dst++ = inputChar;89 }90 out.resize(dst - out.data());91 64 } 92 65 93 66 NetworkJob::NetworkJob() 94 67 : m_playerId(0) 95 , m_loadDataTimer(this, &NetworkJob::fireLoadDataTimer)96 68 , m_loadAboutTimer(this, &NetworkJob::fireLoadAboutTimer) 97 69 , m_deleteJobTimer(this, &NetworkJob::fireDeleteJobTimer) 98 70 , m_streamFactory(0) 99 71 , m_isFile(false) 100 , m_isData(false)101 72 , m_isAbout(false) 102 73 , m_isFTP(false) … … 135 106 m_response.setURL(url); 136 107 m_isFile = url.protocolIs("file") || url.protocolIs("local"); 137 m_isData = url.protocolIs("data");138 108 m_isAbout = url.protocolIs("about"); 139 109 m_isFTP = url.protocolIs("ftp"); … … 161 131 } 162 132 163 // No need to create the streams for data andabout.164 if (m_is Data || m_isAbout)133 // No need to create the streams for about. 134 if (m_isAbout) 165 135 return true; 166 136 … … 189 159 // Cancel jobs loading local data by killing the timer, and jobs 190 160 // getting data from the network by calling the inherited URLStream::cancel. 191 if (m_loadDataTimer.isActive()) {192 m_loadDataTimer.stop();193 notifyClose(BlackBerry::Platform::FilterStream::StatusCancelled);194 return 0;195 }196 161 197 162 if (m_loadAboutTimer.isActive()) { … … 613 578 return; 614 579 615 String urlFilename = m_response.url().lastPathComponent(); 580 String urlFilename; 581 if (!m_response.url().protocolIsData() && !m_response.url().protocolIs("about")) 582 urlFilename = m_response.url().lastPathComponent(); 616 583 617 584 // Get the MIME type that was set by the content sniffer … … 636 603 637 604 // Set suggested filename for downloads from the Content-Disposition header; if this fails, 638 // fill it in from the url and sniffed mime type;Skip this for data andabout URLs,605 // fill it in from the url and sniffed mime type;Skip this for about URLs, 639 606 // because they have no Content-Disposition header and the format is wrong to be a filename. 640 if (!m_is Data && !m_isAbout) {607 if (!m_isAbout) { 641 608 String suggestedFilename = filenameFromHTTPContentDisposition(m_contentDisposition); 642 609 if (suggestedFilename.isEmpty()) { … … 645 612 if (urlFilename.isEmpty()) { 646 613 if (mimeExtension.isEmpty()) // No extension found for the mimeType. 647 suggestedFilename = String( "Untitled");614 suggestedFilename = String(BlackBerry::Platform::LocalizeResource::getString(BlackBerry::Platform::FILENAME_UNTITLED)); 648 615 else 649 suggestedFilename = String( "Untitled") + "." + mimeExtension;616 suggestedFilename = String(BlackBerry::Platform::LocalizeResource::getString(BlackBerry::Platform::FILENAME_UNTITLED)) + "." + mimeExtension; 650 617 } else { 651 618 if (urlFilename.reverseFind('.') == notFound && !mimeExtension.isEmpty()) … … 674 641 m_multipartResponse = nullptr; 675 642 } 676 }677 678 void NetworkJob::parseData()679 {680 Vector<char> result;681 682 String contentType("text/plain;charset=US-ASCII");683 684 String data(m_response.url().string().substring(5));685 Vector<String> hparts;686 bool isBase64 = false;687 688 size_t index = data.find(',');689 if (index != notFound && index > 0) {690 contentType = data.left(index).lower();691 data = data.substring(index + 1);692 693 contentType.split(';', hparts);694 Vector<String>::iterator i;695 for (i = hparts.begin(); i != hparts.end(); ++i) {696 if (i->stripWhiteSpace().lower() == "base64") {697 isBase64 = true;698 String value = *i;699 do {700 if (*i == value) {701 int position = i - hparts.begin();702 hparts.remove(position);703 i = hparts.begin() + position;704 } else705 ++i;706 } while (i != hparts.end());707 break;708 }709 }710 contentType = String();711 for (i = hparts.begin(); i != hparts.end(); ++i) {712 if (i > hparts.begin())713 contentType += ",";714 715 contentType += *i;716 }717 } else if (!index)718 data = data.substring(1); // Broken header.719 720 {721 CString latin = data.latin1();722 escapeDecode(latin.data(), latin.length(), result);723 }724 725 if (isBase64) {726 String s(result.data(), result.size());727 CString latin = s.removeCharacters(isSpaceOrNewline).latin1();728 result.clear();729 result.append(latin.data(), latin.length());730 Vector<char> bytesOut;731 if (base64Decode(result, bytesOut))732 result.swap(bytesOut);733 else734 result.clear();735 }736 737 notifyStatusReceived(result.isEmpty() ? 404 : 200, 0);738 notifyStringHeaderReceived("Content-Type", contentType);739 notifyStringHeaderReceived("Content-Length", String::number(result.size()));740 notifyDataReceivedPlain(result.data(), result.size());741 notifyClose(BlackBerry::Platform::FilterStream::StatusSuccess);742 643 } 743 644 -
trunk/Source/WebCore/platform/network/blackberry/NetworkJob.h
r112092 r116591 61 61 #endif 62 62 bool isCancelled() const { return m_cancelled; } 63 void loadDataURL() { m_loadDataTimer.startOneShot(0); }64 63 void loadAboutURL(); 65 64 int cancelJob(); … … 114 113 void sendMultipartResponseIfNeeded(); 115 114 116 void fireLoadDataTimer(Timer<NetworkJob>*)117 {118 parseData();119 }120 121 115 void fireLoadAboutTimer(Timer<NetworkJob>*) 122 116 { … … 125 119 126 120 void fireDeleteJobTimer(Timer<NetworkJob>*); 127 128 void parseData();129 121 130 122 void handleAbout(); … … 152 144 RefPtr<ResourceHandle> m_handle; 153 145 ResourceResponse m_response; 154 Timer<NetworkJob> m_loadDataTimer;155 146 Timer<NetworkJob> m_loadAboutTimer; 156 147 OwnPtr<ResourceResponse> m_multipartResponse; … … 161 152 BlackBerry::Platform::NetworkStreamFactory* m_streamFactory; 162 153 bool m_isFile; 163 bool m_isData;164 154 bool m_isAbout; 165 155 bool m_isFTP; -
trunk/Source/WebCore/platform/network/blackberry/NetworkManager.cpp
r112766 r116591 137 137 m_jobs.append(networkJob); 138 138 139 if (url.protocolIs("data")) {140 networkJob->loadDataURL();141 return true;142 }143 144 139 if (url.protocolIs("about")) { 145 140 // If the protocol matches "about", loadAboutURL should recognize and handle it.
Note: See TracChangeset
for help on using the changeset viewer.