Bug 46091 - Add WebKit2 API to load a string as plain text
Summary: Add WebKit2 API to load a string as plain text
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC OS X 10.5
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-20 07:56 PDT by Sam Weinig
Modified: 2010-09-20 08:08 PDT (History)
0 users

See Also:


Attachments
Patch (7.34 KB, patch)
2010-09-20 07:57 PDT, Sam Weinig
aroben: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sam Weinig 2010-09-20 07:56:47 PDT
Add WebKit2 API to load a string as plain text
Comment 1 Sam Weinig 2010-09-20 07:57:57 PDT
Created attachment 68083 [details]
Patch
Comment 2 Adam Roben (:aroben) 2010-09-20 08:03:13 PDT
Comment on attachment 68083 [details]
Patch

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

> WebKit2/WebProcess/WebPage/WebPage.cpp:257
> +void WebPage::commonLoadData(PassRefPtr<SharedBuffer> sharedBuffer, const String& MIMEType, const String& encodingName, const KURL& baseURL, const KURL& failingURL)
> +{
> +    ResourceRequest request(baseURL);
> +    SubstituteData substituteData(sharedBuffer, MIMEType, encodingName, failingURL);
> +    m_mainFrame->coreFrame()->loader()->load(request, substituteData, false);
> +}

I don't think there's any need for "common" in this function name.

> WebKit2/WebProcess/WebPage/WebPage.cpp:270
>  void WebPage::loadHTMLString(const String& htmlString, const String& baseURLString)
>  {
>      RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(reinterpret_cast<const char*>(htmlString.characters()), htmlString.length() * sizeof(UChar));
> -    String MIMEType("text/html");
> -    String encodingName("utf-16");
>      KURL baseURL = baseURLString.isEmpty() ? blankURL() : KURL(KURL(), baseURLString);
> -    KURL failingURL;
> -
> -    ResourceRequest request(baseURL);
> -    SubstituteData substituteData(sharedBuffer.release(), MIMEType, encodingName, failingURL);
> +    commonLoadData(sharedBuffer, "text/html", "utf-16", baseURL, KURL());
> +}
>  
> -    m_mainFrame->coreFrame()->loader()->load(request, substituteData, false);
> +void WebPage::loadPlainTextString(const String& string)
> +{
> +    RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(reinterpret_cast<const char*>(string.characters()), string.length() * sizeof(UChar));
> +    commonLoadData(sharedBuffer, "text/plain", "utf-16", blankURL(), KURL());
>  }

Neither of these functions seems prepared to handle sharedBuffer outliving the string it's constructed from. Is that a problem?
Comment 3 Sam Weinig 2010-09-20 08:08:20 PDT
(In reply to comment #2)
> (From update of attachment 68083 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=68083&action=review
> 
> > WebKit2/WebProcess/WebPage/WebPage.cpp:257
> > +void WebPage::commonLoadData(PassRefPtr<SharedBuffer> sharedBuffer, const String& MIMEType, const String& encodingName, const KURL& baseURL, const KURL& failingURL)
> > +{
> > +    ResourceRequest request(baseURL);
> > +    SubstituteData substituteData(sharedBuffer, MIMEType, encodingName, failingURL);
> > +    m_mainFrame->coreFrame()->loader()->load(request, substituteData, false);
> > +}
> 
> I don't think there's any need for "common" in this function name.

Changed to loadData.

> 
> > WebKit2/WebProcess/WebPage/WebPage.cpp:270
> >  void WebPage::loadHTMLString(const String& htmlString, const String& baseURLString)
> >  {
> >      RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(reinterpret_cast<const char*>(htmlString.characters()), htmlString.length() * sizeof(UChar));
> > -    String MIMEType("text/html");
> > -    String encodingName("utf-16");
> >      KURL baseURL = baseURLString.isEmpty() ? blankURL() : KURL(KURL(), baseURLString);
> > -    KURL failingURL;
> > -
> > -    ResourceRequest request(baseURL);
> > -    SubstituteData substituteData(sharedBuffer.release(), MIMEType, encodingName, failingURL);
> > +    commonLoadData(sharedBuffer, "text/html", "utf-16", baseURL, KURL());
> > +}
> >  
> > -    m_mainFrame->coreFrame()->loader()->load(request, substituteData, false);
> > +void WebPage::loadPlainTextString(const String& string)
> > +{
> > +    RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(reinterpret_cast<const char*>(string.characters()), string.length() * sizeof(UChar));
> > +    commonLoadData(sharedBuffer, "text/plain", "utf-16", blankURL(), KURL());
> >  }
> 
> Neither of these functions seems prepared to handle sharedBuffer outliving the string it's constructed from. Is that a problem?

No, it is not a problem. SharedBuffer will copy the string. We should consider adding a way for the sharedBuffer to adopt an existing buffer (such as one released from a string) though,
Comment 4 Sam Weinig 2010-09-20 08:08:57 PDT
Landed in r67849.