Bug 111700 - Rename 'KURL::elidedString' and inspector's 'String::trimMiddle' for clarity.
Summary: Rename 'KURL::elidedString' and inspector's 'String::trimMiddle' for clarity.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Mike West
URL:
Keywords:
Depends on:
Blocks: 116924
  Show dependency treegraph
 
Reported: 2013-03-07 02:02 PST by Mike West
Modified: 2013-05-30 05:08 PDT (History)
9 users (show)

See Also:


Attachments
Patch (35.12 KB, patch)
2013-03-07 02:28 PST, Mike West
no flags Details | Formatted Diff | Diff
Patch (35.28 KB, patch)
2013-05-30 03:18 PDT, Mike West
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mike West 2013-03-07 02:02:01 PST
In https://bugs.webkit.org/show_bug.cgi?id=111133#c21, Darin suggested that the current name for the process of shortening a URL's string representation was poorly chosen. We should rename it for clarity.

othermaciej suggested "centerEllipsizeToLength" or "centerTruncate".  dydx liked "ellipsize". I'll put something together here, and rename the various callsites.
Comment 1 Mike West 2013-03-07 02:10:51 PST
For consistency, I'll adjust the 'trimMiddle' method that the Inspector adds to the String prototype as well.
Comment 2 Mike West 2013-03-07 02:28:45 PST
Created attachment 191958 [details]
Patch
Comment 3 Alexey Proskuryakov 2013-03-07 10:45:54 PST
Comment on attachment 191958 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=191958&action=review

A few drive by comments below.

I'm unsure if trimming URLs at this level is the right approach. Ideally, Web Inspector would show a shorter URL, but still allow for copying the full one to pasteboard, or possibly expanding inline. Also, an ellipsis in the middle of a 1024 character string is extremely hard to spot, so it could be highlighted in the UI by using a prominent style.

> Source/WebCore/Modules/websockets/WebSocket.cpp:218
> +        scriptExecutionContext()->addConsoleMessage(JSMessageSource, ErrorMessageLevel, "Invalid url for WebSocket " + m_url.stringCenterEllipsizedToLength());

All these call sites look a bit weird without a length argument. But I don't have a better suggestion.

> Source/WebCore/platform/KURL.cpp:1928
> +String KURL::stringCenterEllipsizedToLength(unsigned length) const

Since the result of this function is for viewing only, perhaps we should convert IDNA host names?

> Source/WebCore/platform/KURL.cpp:1933
> +    return string().left(length / 2 - 1) + "..." + string().right(length / 2 - 2);

It would be nice to use an ellipsis (U+2026), not three periods.
Comment 4 Mike West 2013-03-07 10:55:34 PST
(In reply to comment #3)
> (From update of attachment 191958 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=191958&action=review
> 
> A few drive by comments below.

Thanks, much appreciated.

> I'm unsure if trimming URLs at this level is the right approach. Ideally, Web Inspector would show a shorter URL, but still allow for copying the full one to pasteboard, or possibly expanding inline. Also, an ellipsis in the middle of a 1024 character string is extremely hard to spot, so it could be highlighted in the UI by using a prominent style.

It's a little complex. Here's a bit of background for context:

Web Inspector does currently show a shorter, linkified URL for all those longer than ~150 characters. If the URL is shorter than 1k, the full URL is linked, and the short URL is displayed.

Eric noted in bug 111133 that we're potentially doing a _lot_ of copying in order to produce these strings, especially in the case of 'data:' URLs. These URLs especially cause problems when being dumped to the command line or to console.app.

That discussion lead to the patch in 111133 trimming the underlying string before passing it into the inspector.

> > Source/WebCore/Modules/websockets/WebSocket.cpp:218
> > +        scriptExecutionContext()->addConsoleMessage(JSMessageSource, ErrorMessageLevel, "Invalid url for WebSocket " + m_url.stringCenterEllipsizedToLength());
> 
> All these call sites look a bit weird without a length argument. But I don't have a better suggestion.

I considered adding a static property on Console to pass in here, but that seemed like pure overhead. I'd like to avoid boilerplate to the extent possible.

What might make more sense is to move the method to Console, and to do the trimming there. Something like 'Console::centerEllipsizeForConsole(const String&)'. Would that be more clear?
 
> > Source/WebCore/platform/KURL.cpp:1928
> > +String KURL::stringCenterEllipsizedToLength(unsigned length) const
> 
> Since the result of this function is for viewing only, perhaps we should convert IDNA host names?

I've no idea if we do anything useful with those, honestly. If we don't, it would be a good idea to teach the console about them when it goes through linkifying URLs.

> > Source/WebCore/platform/KURL.cpp:1933
> > +    return string().left(length / 2 - 1) + "..." + string().right(length / 2 - 2);
> 
> It would be nice to use an ellipsis (U+2026), not three periods.

I considered that; is it safe to throw unicode out to the console?
Comment 5 Mike West 2013-03-13 07:00:02 PDT
+jochen, eric: Since you reviewed the original patch, perhaps you have opinions about this renaming discussion? :)
Comment 6 Mike West 2013-05-30 03:18:00 PDT
Created attachment 203337 [details]
Patch
Comment 7 Mike West 2013-05-30 03:18:40 PDT
Thanks for the review, Darin. Apologies for the belated rebase/upload. Assuming this passes the bots, I'll land it tonight.
Comment 8 WebKit Commit Bot 2013-05-30 05:08:47 PDT
Comment on attachment 203337 [details]
Patch

Clearing flags on attachment: 203337

Committed r150957: <http://trac.webkit.org/changeset/150957>
Comment 9 WebKit Commit Bot 2013-05-30 05:08:51 PDT
All reviewed patches have been landed.  Closing bug.