void WebContentsAdapter::stop()
{
    content::NavigationController& controller = webContents()->GetController();

    int index = controller.GetPendingEntryIndex();
    if (index != -1)
        controller.RemoveEntryAtIndex(index);

    webContents()->GetView()->Focus();
}
void WebContentsAdapter::download(const QUrl &url, const QString &suggestedFileName)
{
    content::BrowserContext *bctx = webContents()->GetBrowserContext();
    content::DownloadManager *dlm =  content::BrowserContext::GetDownloadManager(bctx);
    if (!dlm)
        return;

    scoped_ptr<content::DownloadUrlParameters> params(
            content::DownloadUrlParameters::FromWebContents(webContents(), toGurl(url)));
    params->set_suggested_name(toString16(suggestedFileName));
    dlm->DownloadUrl(params.Pass());
}
void WebContentsAdapter::load(const QUrl &url)
{
    QString urlString = url.toString();
    GURL gurl(urlString.toStdString());
    if (!gurl.has_scheme())
        gurl = GURL(std::string("http://") + urlString.toStdString());

    content::NavigationController::LoadURLParams params(gurl);
    params.transition_type = content::PageTransitionFromInt(content::PAGE_TRANSITION_TYPED | content::PAGE_TRANSITION_FROM_ADDRESS_BAR);
    webContents()->GetController().LoadURLWithParams(params);
    webContents()->GetView()->Focus();
}
QString WebContentsAdapter::pageTitle() const
{
    content::NavigationEntry* entry = webContents()->GetController().GetVisibleEntry();
    if (!entry)
        return QString();
    return QString::fromUtf16(entry->GetTitle().data());
}
void WebContentsAdapter::navigateHistory(int offset)
{
    webContents()->GetController().GoToOffset(offset);
    webContents()->GetView()->Focus();
}
bool WebContentsAdapter::isLoading() const
{
    return webContents()->IsLoading();
}
bool WebContentsAdapter::canGoForward() const
{
    return webContents()->GetController().CanGoForward();
}
QUrl WebContentsAdapter::activeUrl() const
{
    GURL gurl = webContents()->GetVisibleURL();
    return QUrl(QString::fromStdString(gurl.spec()));
}
void WebContentsAdapter::reload()
{
    webContents()->GetController().Reload(/*checkRepost = */false);
    webContents()->GetView()->Focus();
}