Bug 100667 - [EFL][WK2] Avoid useless assignment in EwkViewImpl::setCustomTextEncodingName()
Summary: [EFL][WK2] Avoid useless assignment in EwkViewImpl::setCustomTextEncodingName()
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit EFL (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-10-29 06:25 PDT by Chris Dumez
Modified: 2012-10-29 10:00 PDT (History)
7 users (show)

See Also:


Attachments
Patch (3.15 KB, patch)
2012-10-29 06:28 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2012-10-29 06:25:14 PDT
We currently do the following in EwkViewImpl::setCustomTextEncodingName(encoding):
      m_customEncoding = encoding;
      m_pageProxy->setCustomTextEncodingName(encoding);

Then, we assign again m_customEncoding in EwkViewImpl::customTextEncodingName():

    String customEncoding = m_pageProxy->customTextEncodingName();
    if (customEncoding.isEmpty())
        return 0;
    m_customEncoding = customEncoding.utf8().data();
    return m_customEncoding;

The assignment in EwkViewImpl::setCustomTextEncodingName() is useless since the value is anyway set when calling EwkViewImpl::setCustomTextEncodingName(encoding). We can therefore get rid of it.
Comment 1 Chris Dumez 2012-10-29 06:28:51 PDT
Created attachment 171226 [details]
Patch
Comment 2 Mikhail Pozdnyakov 2012-10-29 06:37:56 PDT
Comment on attachment 171226 [details]
Patch

LGTM
Comment 3 Gyuyoung Kim 2012-10-29 06:56:49 PDT
Comment on attachment 171226 [details]
Patch

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

> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:817
> +    impl->setCustomTextEncodingName(encoding ? encoding : String());

I think you need to use String::fromUTF8(encoding).
Comment 4 Chris Dumez 2012-10-29 07:02:12 PDT
(In reply to comment #3)
> (From update of attachment 171226 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=171226&action=review
> 
> > Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:817
> > +    impl->setCustomTextEncodingName(encoding ? encoding : String());
> 
> I think you need to use String::fromUTF8(encoding).

Can we really have non-ASCII characters in the encoding name? I don't think so.
Comment 5 WebKit Review Bot 2012-10-29 07:37:40 PDT
Comment on attachment 171226 [details]
Patch

Clearing flags on attachment: 171226

Committed r132800: <http://trac.webkit.org/changeset/132800>
Comment 6 WebKit Review Bot 2012-10-29 07:37:44 PDT
All reviewed patches have been landed.  Closing bug.
Comment 7 Gyuyoung Kim 2012-10-29 08:54:41 PDT
Comment on attachment 171226 [details]
Patch

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

>>> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:817
>>> +    impl->setCustomTextEncodingName(encoding ? encoding : String());
>> 
>> I think you need to use String::fromUTF8(encoding).
> 
> Can we really have non-ASCII characters in the encoding name? I don't think so.

I think this is not related to set non-ASCII character as encoding name. This is to check if const char* is valid utf8 or not, and to convert from utf8() to utf16(). If we use encoding name without converting, encoding name might to be broken when it is converted to String implicitly.  I think setCustomTextEncodingName(() will check if encoding character can be adjusted or not. GTK port also uses String::fromUTF8()
Comment 8 Chris Dumez 2012-10-29 10:00:33 PDT
(In reply to comment #7)
> (From update of attachment 171226 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=171226&action=review
> 
> >>> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:817
> >>> +    impl->setCustomTextEncodingName(encoding ? encoding : String());
> >> 
> >> I think you need to use String::fromUTF8(encoding).
> > 
> > Can we really have non-ASCII characters in the encoding name? I don't think so.
> 
> I think this is not related to set non-ASCII character as encoding name. This is to check if const char* is valid utf8 or not, and to convert from utf8() to utf16(). If we use encoding name without converting, encoding name might to be broken when it is converted to String implicitly.  I think setCustomTextEncodingName(() will check if encoding character can be adjusted or not. GTK port also uses String::fromUTF8()

If we don't call String::fromUTF8() then the input string is treated as ASCII. This is safe (and likely faster) as long as the input string only contains ASCII characters. Since I don't think it is valid to have non-ASCII characters in an encoding name, I think my code is correct.