[Webkit-unassigned] [Bug 148128] Decode data URLs in web process
bugzilla-daemon at webkit.org
bugzilla-daemon at webkit.org
Fri Aug 21 09:42:27 PDT 2015
https://bugs.webkit.org/show_bug.cgi?id=148128
Darin Adler <darin at apple.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #259618|review? |review+
Flags| |
--- Comment #35 from Darin Adler <darin at apple.com> ---
Comment on attachment 259618
--> https://bugs.webkit.org/attachment.cgi?id=259618
patch
View in context: https://bugs.webkit.org/attachment.cgi?id=259618&action=review
Looks good to me.
> Source/WebCore/loader/ResourceLoader.cpp:210
> + if (url.protocolIsData()) {
I think the code inside this if statement is long enough that it could be clearer if factored into a separate private named member function, perhaps named loadDataURL or startLoadingDataURL or something.
> Source/WebCore/loader/ResourceLoader.cpp:222
> + ResourceResponse dataResponse { url, result.mimeType, dataSize, result.charset };
If we had the right kind of constructor for ResourceResponse we could use WTF::move on all the arguments here to avoid a little bit of reference count churn.
> Source/WebCore/platform/network/DataURLDecoder.cpp:53
> + DecodeTask(const String& urlString, StringView encodedData, bool isBase64, DecodeCompletionHandler completionHandler)
> + : urlString(urlString)
> + , encodedData(encodedData)
> + , isBase64(isBase64)
> + , completionHandler(completionHandler)
> + { }
I donât think we need this constructor. We should just be able to write:
std::make_unique<DecodeTask>({ ... });
below without using a constructor.
> Source/WebCore/platform/network/DataURLDecoder.cpp:68
> + ASSERT(urlString.startsWith(dataString));
This check needs to ignore ASCII case.
> Source/WebCore/platform/network/DataURLDecoder.cpp:72
> + if (headerEnd == notFound)
> + return nullptr;
Do we have a test case that covers this?
> Source/WebCore/platform/network/DataURLDecoder.cpp:87
> + mimeType = "text/plain";
I think ASCIILiteral("text/plain") will be slightly more efficient.
> Source/WebCore/platform/network/DataURLDecoder.cpp:89
> + charset = "US-ASCII";
I think ASCIILiteral("US-ASCII") will be slightly more efficient.
> Source/WebCore/platform/network/DataURLDecoder.cpp:92
> + decodeTask->result.mimeType = mimeType;
Please consider using WTF::move here to get rid of a tiny bit of reference count churn.
> Source/WebCore/platform/network/DataURLDecoder.cpp:93
> + decodeTask->result.charset = charset;
Please consider using WTF::move here to get rid of a tiny bit of reference count churn.
> Source/WebCore/platform/network/DataURLDecoder.cpp:104
> + if (!base64URLDecode(task.encodedData.toStringWithoutCopying(), buffer)) {
> + // Didn't work, try unescaping and decoding as base64.
> + auto unescapedString = decodeURLEscapeSequences(task.encodedData.toStringWithoutCopying());
This toStringWithoutCopying thing seems a bit ugly, and could be avoided if the functions took StringView instead of const String& arguments.
> Source/WebCore/platform/network/DataURLDecoder.cpp:116
> + auto buffer = decodeURLEscapeSequencesAsData(task.encodedData.toStringWithoutCopying(), encoding);
Same thought about toStringWithoutCopying.
> Source/WebCore/platform/network/DataURLDecoder.cpp:117
> + task.result.data = SharedBuffer::create(buffer.data(), buffer.size());
Why not use SharedBuffer::adoptVector here?
Stray space here, after the "=".
> Source/WebCore/platform/network/DataURLDecoder.cpp:147
> + decodeTask->completionHandler(decodeTask->result);
Please consider using WTF::move here to get rid of a tiny bit of reference count churn.
> Source/WebCore/platform/network/DataURLDecoder.h:49
> +void decode(const URL&, DecodeCompletionHandler);
Donât functions sometimes have state and are thus expensive to copy? If so, it might be nicer to take ownership of the completion handler rather than passing it by value.
> Source/WebCore/platform/text/DecodeEscapeSequences.h:158
> +inline Vector<char> decodeURLEscapeSequencesAsData(const String& string, const TextEncoding& encoding)
I think it would be better to have this take a StringView instead of a String. Should be a simple matter of changing the URLEscapeSequence functions to work on StringView.
> Source/WebCore/platform/text/DecodeEscapeSequences.h:170
> + encodedRunPosition = length;
Iâm not sure this line of code is needed. We intentionally made encodedRunPosition a very large value so it doesnât need to be explicitly checked for. Using StringView::substring with it should work because it clamps its arguments down to the length of the string. Itâs even possible, depending on how URLEscapeSequence::findEndOfRun is written, that we could remove the if statement entirely.
Maybe you donât want to write code that relies on that. Maybe some day weâll change the return values to be Optional<size_t> instead to make things like that more clear.
> Source/WebCore/platform/text/DecodeEscapeSequences.h:181
> + auto stringFragment = StringView(string).substring(decodedPosition, encodedRunPosition - decodedPosition);
> + auto encodedStringFragment = encoding.encode(StringView(string).substring(decodedPosition, encodedRunPosition - decodedPosition), URLEncodedEntitiesForUnencodables);
Looks like when refactoring this you forgot to use the stringFragment local. I suggest either getting rid of it or using it.
> Source/WebCore/platform/text/DecodeEscapeSequences.h:184
> + if (encodedRunPosition == length)
If you make the change I suggested above this would be encodedRunPosition == notFound.
> Source/WebCore/platform/text/DecodeEscapeSequences.h:185
> + return result;
Should this be doing some kind of âshrink to fitâ thing?
> Source/WebCore/platform/text/DecodeEscapeSequences.h:195
> + ASSERT_NOT_REACHED();
> + return { };
Iâm surprised this is needed. Donât our compilers recognize the infinite loop?
> Source/WebKit2/WebProcess/Network/WebResourceLoadScheduler.cpp:155
> + resourceLoader->start();
> m_webResourceLoaders.set(identifier, WebResourceLoader::create(resourceLoader));
I know itâs only one or two lines of code, but I think a helper function might be nice for the m_webResourceLoaders thing thatâs now repeated four times.
--
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/webkit-unassigned/attachments/20150821/10df3cd8/attachment.html>
More information about the webkit-unassigned
mailing list