void PermissionManagerQt::RequestPermission(content::PermissionType permission,
                                            content::RenderFrameHost *frameHost,
                                            int request_id,
                                            const GURL& requesting_origin,
                                            bool user_gesture,
                                            const base::Callback<void(content::PermissionStatus)>& callback)
{
    Q_UNUSED(user_gesture);
    BrowserContextAdapter::PermissionType permissionType = toQt(permission);
    if (permissionType == BrowserContextAdapter::UnsupportedPermission) {
        callback.Run(content::PERMISSION_STATUS_DENIED);
        return;
    }

    content::WebContents *webContents = frameHost->GetRenderViewHost()->GetDelegate()->GetAsWebContents();
    WebContentsDelegateQt* contentsDelegate = static_cast<WebContentsDelegateQt*>(webContents->GetDelegate());
    Q_ASSERT(contentsDelegate);
    Request request = {
        request_id,
        permissionType,
        toQt(requesting_origin),
        callback
    };
    m_requests.append(request);
    if (permissionType == BrowserContextAdapter::GeolocationPermission)
        contentsDelegate->requestGeolocationPermission(request.origin);
}
void WebContentsDelegateQt::DidFinishLoad(content::RenderFrameHost* render_frame_host, const GURL& validated_url)
{
    Q_ASSERT(validated_url.is_valid());
    if (validated_url.spec() == content::kUnreachableWebDataURL) {
        m_loadingErrorFrameList.removeOne(render_frame_host->GetRoutingID());
        m_viewClient->iconChanged(QUrl());

        // Trigger LoadFinished signal for main frame's error page only.
        if (!render_frame_host->GetParent())
            m_viewClient->loadFinished(true /* success */, toQt(validated_url), true /* isErrorPage */);

        return;
    }

    if (render_frame_host->GetParent())
        return;

    m_viewClient->loadFinished(true, toQt(validated_url));

    content::NavigationEntry *entry = web_contents()->GetController().GetActiveEntry();
    if (!entry)
        return;
    content::FaviconStatus &favicon = entry->GetFavicon();
    if (favicon.valid)
        m_viewClient->iconChanged(toQt(favicon.url));
    else
        m_viewClient->iconChanged(QUrl());
}
Beispiel #3
0
void PathResult::drawResult(Painter *p) const
{
	if (size() >= 2) {
		QPen pe = p->pen();
		QBrush br(Qt::SolidPattern);

		pe.setWidth(2);

		const_iterator prev = begin();
		const_iterator curr = begin() + 1;
		for (int i = 0; curr != end(); i++, curr++, prev++) {
			QColor c = QColor::fromHsl(360.0 / size() * i, 255, 128);

			pe.setColor(c);
			br.setColor(c);
			p->setPen(pe);
			p->setBrush(br);
			p->drawLine(toQt(*prev), toQt(*curr));
			p->drawEllipse(toQt(*curr), 1, 1);
		}

		p->drawMarker(toQt((Point2i) (Point2f) first()));
		p->drawMarker(toQt((Point2i) (Point2f) last()));
	}
}
static void serializeNavigationHistory(const content::NavigationController &controller, QDataStream &output)
{
    const int currentIndex = controller.GetCurrentEntryIndex();
    const int count = controller.GetEntryCount();
    const int pendingIndex = controller.GetPendingEntryIndex();

    output << kHistoryStreamVersion;
    output << count;
    output << currentIndex;

    // Logic taken from SerializedNavigationEntry::WriteToPickle.
    for (int i = 0; i < count; ++i) {
        const content::NavigationEntry* entry = (i == pendingIndex)
            ? controller.GetPendingEntry()
            : controller.GetEntryAtIndex(i);
        if (entry->GetVirtualURL().is_valid()) {
            if (entry->GetHasPostData())
                entry->GetPageState().RemovePasswordData();
            std::string encodedPageState = entry->GetPageState().ToEncodedData();
            output << toQt(entry->GetVirtualURL());
            output << toQt(entry->GetTitle());
            output << QByteArray(encodedPageState.data(), encodedPageState.size());
            output << static_cast<qint32>(entry->GetTransitionType());
            output << entry->GetHasPostData();
            output << toQt(entry->GetReferrer().url);
            output << static_cast<qint32>(entry->GetReferrer().policy);
            output << toQt(entry->GetOriginalRequestURL());
            output << entry->GetIsOverridingUserAgent();
            output << static_cast<qint64>(entry->GetTimestamp().ToInternalValue());
            output << entry->GetHttpStatusCode();
        }
    }
}
void WebContentsDelegateQt::NavigationStateChanged(content::WebContents* source, content::InvalidateTypes changed_flags)
{
    if (changed_flags & content::INVALIDATE_TYPE_URL)
        m_viewClient->urlChanged(toQt(source->GetVisibleURL()));
    if (changed_flags & content::INVALIDATE_TYPE_TITLE)
        m_viewClient->titleChanged(toQt(source->GetTitle()));
}
Beispiel #6
0
static WebEngineContextMenuData fromParams(const content::ContextMenuParams &params)
{
    WebEngineContextMenuData ret;
    ret.pos = QPoint(params.x, params.y);
    ret.linkUrl = toQt(params.link_url);
    ret.linkText = toQt(params.link_text.data());
    ret.selectedText = toQt(params.selection_text.data());
    return ret;
}
void PermissionManagerQt::ResetPermission(
    content::PermissionType permission,
    const GURL& requesting_origin,
    const GURL& /*embedding_origin*/)
{
    const BrowserContextAdapter::PermissionType permissionType = toQt(permission);
    if (permissionType == BrowserContextAdapter::UnsupportedPermission)
        return;

    QPair<QUrl, BrowserContextAdapter::PermissionType> key(toQt(requesting_origin), permissionType);
    m_permissions.remove(key);
}
QUrl WebContentsAdapter::requestedUrl() const
{
    Q_D(const WebContentsAdapter);
    content::NavigationEntry* entry = d->webContents->GetController().GetVisibleEntry();
    content::NavigationEntry* pendingEntry = d->webContents->GetController().GetPendingEntry();

    if (entry) {
        if (!entry->GetOriginalRequestURL().is_empty())
            return toQt(entry->GetOriginalRequestURL());

        if (pendingEntry && pendingEntry == entry)
            return toQt(entry->GetURL());
    }
    return QUrl();
}
int PermissionManagerQt::SubscribePermissionStatusChange(
    content::PermissionType permission,
    const GURL& requesting_origin,
    const GURL& /*embedding_origin*/,
    const base::Callback<void(content::PermissionStatus)>& callback)
{
    Subscriber subscriber = {
        m_subscriberCount++,
        toQt(permission),
        toQt(requesting_origin),
        callback
    };
    m_subscribers.append(subscriber);
    return subscriber.id;
}
content::PermissionStatus PermissionManagerQt::GetPermissionStatus(
    content::PermissionType permission,
    const GURL& requesting_origin,
    const GURL& /*embedding_origin*/)
{
    const BrowserContextAdapter::PermissionType permissionType = toQt(permission);
    if (permissionType == BrowserContextAdapter::UnsupportedPermission)
        return content::PERMISSION_STATUS_DENIED;

    QPair<QUrl, BrowserContextAdapter::PermissionType> key(toQt(requesting_origin), permissionType);
    if (!m_permissions.contains(key))
        return content::PERMISSION_STATUS_ASK;
    if (m_permissions[key])
        return content::PERMISSION_STATUS_GRANTED;
    return content::PERMISSION_STATUS_DENIED;
}
bool NetworkDelegateQt::OnCanSetCookie(const net::URLRequest& request,
                                       const std::string& cookie_line,
                                       net::CookieOptions*)
{
    Q_ASSERT(m_requestContextGetter);
    return m_requestContextGetter->m_cookieDelegate->canSetCookie(toQt(request.first_party_for_cookies()), QByteArray::fromStdString(cookie_line), toQt(request.url()));
}
void WebContentsDelegateQt::DidFailLoad(content::RenderFrameHost* render_frame_host, const GURL& validated_url, int error_code, const base::string16& error_description, bool was_ignored_by_handler)
{
    Q_UNUSED(was_ignored_by_handler);
    if (validated_url.spec() == content::kUnreachableWebDataURL) {
        m_loadingErrorFrameList.removeOne(render_frame_host->GetRoutingID());
        qCritical("Loading error-page failed. This shouldn't happen.");
        if (!render_frame_host->GetParent())
            m_viewClient->loadFinished(false /* success */, toQt(validated_url), true /* isErrorPage */);
        return;
    }

    if (render_frame_host->GetParent())
        return;

    m_viewClient->loadFinished(false /* success */ , toQt(validated_url), false /* isErrorPage */, error_code, toQt(error_description));
    m_viewClient->loadProgressChanged(0);
}
void WebContentsDelegateQt::DidStartProvisionalLoadForFrame(content::RenderFrameHost* render_frame_host, const GURL& validated_url, bool is_error_page, bool is_iframe_srcdoc)
{
    if (is_error_page) {
        m_loadingErrorFrameList.append(render_frame_host->GetRoutingID());

        // Trigger LoadStarted signal for main frame's error page only.
        if (!render_frame_host->GetParent())
            m_viewClient->loadStarted(toQt(validated_url), true);

        return;
    }

    if (render_frame_host->GetParent())
        return;

    m_loadingErrorFrameList.clear();
    m_viewClient->loadStarted(toQt(validated_url));
}
QUrl WebContentsAdapter::getNavigationEntryIconUrl(int index)
{
    Q_D(WebContentsAdapter);
    content::NavigationEntry *entry = d->webContents->GetController().GetEntryAtIndex(index);
    if (!entry)
        return QUrl();
    content::FaviconStatus favicon = entry->GetFavicon();
    return favicon.valid ? toQt(favicon.url) : QUrl();
}
QUrl WebContentsAdapter::iconUrl() const
{
    Q_D(const WebContentsAdapter);
    if (content::NavigationEntry* entry = d->webContents->GetController().GetVisibleEntry()) {
        content::FaviconStatus favicon = entry->GetFavicon();
        if (favicon.valid)
            return toQt(favicon.url);
    }
    return QUrl();
}
CertificateErrorControllerPrivate::CertificateErrorControllerPrivate(int cert_error,
                                                                     const net::SSLInfo& ssl_info,
                                                                     const GURL &request_url,
                                                                     ResourceType::Type resource_type,
                                                                     bool _overridable,
                                                                     bool strict_enforcement,
                                                                     const base::Callback<void(bool)>& cb
                                                                    )
    : certError(CertificateErrorController::CertificateError(cert_error))
    , requestUrl(toQt(request_url))
    , resourceType(CertificateErrorController::ResourceType(resource_type))
    , overridable(_overridable)
    , strictEnforcement(strict_enforcement)
    , callback(cb)
{
    if (ssl_info.cert) {
        validStart = toQt(ssl_info.cert->valid_start());
        validExpiry = toQt(ssl_info.cert->valid_expiry());
    }
}
 Q_FOREACH (content::FaviconURL candidate, candidates) {
     if (candidate.icon_type == content::FaviconURL::FAVICON && !candidate.icon_url.is_empty()) {
         content::NavigationEntry *entry = web_contents()->GetController().GetActiveEntry();
         if (!entry)
             continue;
         content::FaviconStatus &favicon = entry->GetFavicon();
         favicon.url = candidate.icon_url;
         favicon.valid = toQt(candidate.icon_url).isValid();
         break;
     }
 }
void PermissionManagerQt::CancelPermissionRequest(content::PermissionType permission,
                                                  content::RenderFrameHost *frameHost,
                                                  int request_id,
                                                  const GURL& requesting_origin)
{
    Q_UNUSED(frameHost);
    const BrowserContextAdapter::PermissionType permissionType = toQt(permission);
    if (permissionType == BrowserContextAdapter::UnsupportedPermission)
        return;

    // Should we add API to cancel permissions in the UI level?
    const QUrl origin = toQt(requesting_origin);
    auto it = m_requests.begin();
    while (it != m_requests.end()) {
        if (it->id == request_id && it->type == permissionType && it->origin == origin) {
            m_requests.erase(it);
            return;
        }
    }
    qWarning() << "PermissionManagerQt::CancelPermissionRequest called on unknown request" << request_id << origin << permissionType;
}
Beispiel #19
0
// Constructor.
SetComponentCommand::SetComponentCommand(beCore::ReflectedComponent *pReflectedComponent, uint4 componentIdx,
		const lean::any &component, beCore::ComponentMonitor *pComponentMonitor, QUndoCommand *pParent)
	: QUndoCommand(
		QCoreApplication::translate("SetComponentCommand", "Replaced component '%1'").arg(
				makeName(toQt( LEAN_ASSERT_NOT_NULL(pReflectedComponent)->GetComponentName(componentIdx) ))
			),
		pParent ),
	m_pReflectedComponent( LEAN_ASSERT_NOT_NULL(pReflectedComponent) ),
	m_componentIdx( componentIdx ),
	m_previousComponent( *pReflectedComponent->GetComponent(m_componentIdx) ),
	m_component( component ),
	m_pComponentMonitor( pComponentMonitor )
{
}
Beispiel #20
0
// Constructor.
ChangePropertyCommand::ChangePropertyCommand(beCore::PropertyProvider *pPropertyProvider, uint4 propertyID, QUndoCommand *pParent)
	: QUndoCommand(
		QCoreApplication::translate("ChangePropertyCommand", "Changed property '%1'").arg(
				makeName(toQt( LEAN_ASSERT_NOT_NULL(pPropertyProvider)->GetPropertyName(propertyID) ))
			),
		pParent ),
	m_pPropertyProvider( LEAN_ASSERT_NOT_NULL(pPropertyProvider) ),
	m_propertyID( propertyID ),
	m_previousData( createPropertyData(*m_pPropertyProvider, m_propertyID), lean::consume ),
	m_data( createPropertyData(*m_pPropertyProvider, m_propertyID), lean::consume ),
	m_bIgnoreOnce(false)
{
	m_pPropertyProvider->GetProperty(m_propertyID, m_previousData.property_type().type_info().type, m_previousData.data(), m_previousData.count());
	m_pPropertyProvider->GetProperty(m_propertyID, m_data.property_type().type_info().type, m_data.data(), m_data.count());
}
void URLRequestQrcJobQt::startGetHead()
{
    // Get qrc file path.
    QString qrcFilePath = ':' + toQt(request_->url()).path(QUrl::RemovePath | QUrl::RemoveQuery);
    m_file.setFileName(qrcFilePath);
    QFileInfo qrcFileInfo(m_file);
    // Get qrc file mime type.
    QMimeDatabase mimeDatabase;
    QMimeType mimeType = mimeDatabase.mimeTypeForFile(qrcFileInfo);
    m_mimeType = mimeType.name().toStdString();
    // Open file
    if (m_file.open(QIODevice::ReadOnly)) {
        m_remainingBytes = m_file.size();
        // Notify that the headers are complete
        NotifyHeadersComplete();
    } else {
        NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, ERR_INVALID_URL));
    }
}
QString WebContentsAdapter::getNavigationEntryTitle(int index)
{
    Q_D(WebContentsAdapter);
    content::NavigationEntry *entry = d->webContents->GetController().GetEntryAtIndex(index);
    return entry ? toQt(entry->GetTitle()) : QString();
}
QString WebContentsAdapter::pageTitle() const
{
    Q_D(const WebContentsAdapter);
    return toQt(d->webContents->GetTitle());
}
static QString getQStringForMessageId(int message_id) {
    base::string16 string = l10n_util::GetStringUTF16(message_id);
    return toQt(string);
}
QUrl URLRequestCustomJobDelegate::url() const
{
    return toQt(m_job->request()->url());
}
int NetworkDelegateQt::OnBeforeURLRequest(net::URLRequest *request, const net::CompletionCallback &callback, GURL *newUrl)
{
    Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
    Q_ASSERT(m_requestContextGetter);

    const content::ResourceRequestInfo *resourceInfo = content::ResourceRequestInfo::ForRequest(request);

    content::ResourceType resourceType = content::RESOURCE_TYPE_LAST_TYPE;
    int navigationType = QWebEngineUrlRequestInfo::NavigationTypeOther;

    if (resourceInfo) {
        resourceType = resourceInfo->GetResourceType();
        navigationType = pageTransitionToNavigationType(resourceInfo->GetPageTransition());
    }

    const QUrl qUrl = toQt(request->url());

    QWebEngineUrlRequestInterceptor* interceptor = m_requestContextGetter->m_requestInterceptor;
    if (interceptor) {
        QWebEngineUrlRequestInfoPrivate *infoPrivate = new QWebEngineUrlRequestInfoPrivate(static_cast<QWebEngineUrlRequestInfo::ResourceType>(resourceType)
                                                                                           , static_cast<QWebEngineUrlRequestInfo::NavigationType>(navigationType)
                                                                                           , qUrl
                                                                                           , toQt(request->first_party_for_cookies())
                                                                                           , QByteArray::fromStdString(request->method()));
        QWebEngineUrlRequestInfo requestInfo(infoPrivate);
        interceptor->interceptRequest(requestInfo);
        if (requestInfo.changed()) {
            int result = infoPrivate->shouldBlockRequest ? net::ERR_BLOCKED_BY_CLIENT : net::OK;

            if (qUrl != infoPrivate->url)
                *newUrl = toGurl(infoPrivate->url);

            if (!infoPrivate->extraHeaders.isEmpty()) {
                auto end = infoPrivate->extraHeaders.constEnd();
                for (auto header = infoPrivate->extraHeaders.constBegin(); header != end; ++header)
                    request->SetExtraRequestHeaderByName(header.key().toStdString(), header.value().toStdString(), /* overwrite */ true);
            }

            if (result != net::OK)
                return result;
        }
    }

    if (!resourceInfo)
        return net::OK;

    int renderProcessId;
    int renderFrameId;
    // Only intercept MAIN_FRAME and SUB_FRAME with an associated render frame.
    if (!content::IsResourceTypeFrame(resourceType) || !resourceInfo->GetRenderFrameForRequest(request, &renderProcessId, &renderFrameId))
        return net::OK;

    // Track active requests since |callback| and |new_url| are valid
    // only until OnURLRequestDestroyed is called for this request.
    m_activeRequests.insert(request);

    RequestParams params = {
        qUrl,
        resourceInfo->IsMainFrame(),
        navigationType,
        renderProcessId,
        renderFrameId
    };

    content::BrowserThread::PostTask(
                content::BrowserThread::UI,
                FROM_HERE,
                base::Bind(&NetworkDelegateQt::NotifyNavigationRequestedOnUIThread,
                           base::Unretained(this),
                           request,
                           params,
                           callback)
                );

    // We'll run the callback after we notified the UI thread.
    return net::ERR_IO_PENDING;
}
QUrl WebContentsAdapter::getNavigationEntryUrl(int index)
{
    Q_D(WebContentsAdapter);
    content::NavigationEntry *entry = d->webContents->GetController().GetEntryAtIndex(index);
    return entry ? toQt(entry->GetURL()) : QUrl();
}
Beispiel #28
0
QString UserScript::sourceCode() const
{
    if (isNull())
        return QString();
    return toQt(scriptData->source);
}
QString WebContentsAdapter::selectedText() const
{
    Q_D(const WebContentsAdapter);
    return toQt(d->webContents->GetRenderViewHost()->GetView()->GetSelectedText());
}
QDateTime WebContentsAdapter::getNavigationEntryTimestamp(int index)
{
    Q_D(WebContentsAdapter);
    content::NavigationEntry *entry = d->webContents->GetController().GetEntryAtIndex(index);
    return entry ? toQt(entry->GetTimestamp()) : QDateTime();
}