Skip to content

Commit

Permalink
Convert IDNA domains back to UTF-8 for display.
Browse files Browse the repository at this point in the history
WebKit URLs get converted to Punycode when doing a request, so we have
to convert the host part back to UTF-8 when showing them in the URL bar.
  • Loading branch information
pulkomandy committed Jan 13, 2014
1 parent aa592b8 commit 3a14597
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
27 changes: 24 additions & 3 deletions Source/WebKit/haiku/WebCoreSupport/FrameLoaderClientHaiku.cpp
Expand Up @@ -80,6 +80,7 @@
#include <Message.h>
#include <MimeType.h>
#include <String.h>
#include <Url.h>
#include <assert.h>
#include <debugger.h>

Expand All @@ -98,8 +99,9 @@ FrameLoaderClientHaiku::FrameLoaderClientHaiku(BWebPage* webPage)
: m_webPage(webPage)
, m_messenger()
, m_loadingErrorPage(false)
, m_pluginView(0)
, m_pluginView(nullptr)
, m_hasSentResponseToPlugin(false)
, m_uidna_context(nullptr)
{
CALLED("BWebPage: %p", webPage);
ASSERT(m_webPage);
Expand All @@ -118,6 +120,9 @@ BWebPage* FrameLoaderClientHaiku::page() const
void FrameLoaderClientHaiku::frameLoaderDestroyed()
{
CALLED();

uidna_close(m_uidna_context);

// No one else feels responsible for the BWebFrame instance that created us.
// Through Shutdown(), we initiate the deletion sequence, after this method returns,
// this object will be gone.
Expand Down Expand Up @@ -391,7 +396,23 @@ void FrameLoaderClientHaiku::dispatchDidCommitLoad()
}

BMessage message(LOAD_COMMITTED);
message.AddString("url", m_webFrame->Frame()->loader().documentLoader()->request().url().string());
URL url = m_webFrame->Frame()->loader().documentLoader()->request().url();
BUrl decoded(url);

// In WebKit URL, the host may be IDN-encoded. Decode it for displaying.
char dest[2048];
UErrorCode error = U_ZERO_ERROR;
if (!m_uidna_context)
m_uidna_context = uidna_openUTS46(UIDNA_DEFAULT, &error);
UIDNAInfo info = UIDNA_INFO_INITIALIZER;

uidna_nameToUnicodeUTF8(m_uidna_context, url.host().utf8().data(),
-1 /* NULL-terminated */, dest, sizeof(dest), &info, &error);

if (U_SUCCESS(error) && info.errors == 0)
decoded.SetHost(dest);

message.AddString("url", decoded);
dispatchMessage(message);

// We should assume first the frame has no title. If it has, then the above
Expand Down Expand Up @@ -451,7 +472,7 @@ void FrameLoaderClientHaiku::dispatchDidFinishLoad()
BMessage message(LOAD_FINISHED);
message.AddPointer("frame", m_webFrame);
message.AddString("url", m_webFrame->Frame()->document()->url().string());
status_t err = dispatchMessage(message);
dispatchMessage(message);
}

void FrameLoaderClientHaiku::dispatchDidFirstLayout()
Expand Down
4 changes: 4 additions & 0 deletions Source/WebKit/haiku/WebCoreSupport/FrameLoaderClientHaiku.h
Expand Up @@ -36,6 +36,7 @@
#include "URL.h"
#include "ResourceResponse.h"
#include <Messenger.h>
#include <unicode/uidna.h>
#include <wtf/Forward.h>

class BWebFrame;
Expand Down Expand Up @@ -251,6 +252,9 @@ class FrameLoaderClientHaiku : public FrameLoaderClient {
// Plugin view to redirect data to
PluginView* m_pluginView;
bool m_hasSentResponseToPlugin;

// IDNA domain encoding and decoding.
UIDNA* m_uidna_context;
};

} // namespace WebCore
Expand Down

0 comments on commit 3a14597

Please sign in to comment.