Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add methods to allow adding resource mapping item for single QCefView… #113

Merged
merged 1 commit into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions example/QCefViewTest/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ MainWindow::MainWindow(QWidget* parent)
QString webResourceDir = /*QString("file://") +*/ QDir::toNativeSeparators(dir.filePath("webres"));
#endif

// add a local folder to URL map
// add a local folder to URL map (global)
QCefContext::instance()->addLocalFolderResource(webResourceDir, URL_ROOT);

createCefView();
}

Expand All @@ -59,8 +59,8 @@ MainWindow::createCefView()
setting.setBackgroundColor(QColor::fromRgba(qRgba(0, 255, 0, 255)));

// create the QCefView widget and add it to the layout container
// cefViewWidget = new CefViewWidget(INDEX_URL, &setting);
cefViewWidget = new CefViewWidget("https://www.testufo.com", &setting, this);
cefViewWidget = new CefViewWidget(INDEX_URL, &setting);
// cefViewWidget = new CefViewWidget("https://www.testufo.com", &setting, this);
// cefViewWidget = new CefViewWidget("https://devicetests.com", &setting);
ui.cefContainer->layout()->addWidget(cefViewWidget);
cefViewWidget->setStyleSheet("background-color: blue;");
Expand Down
6 changes: 3 additions & 3 deletions include/QCefContext.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef QCEF_H
#ifndef QCEF_H
#define QCEF_H
#pragma once
#include <QCefView_global.h>
Expand Down Expand Up @@ -45,15 +45,15 @@ class QCEFVIEW_EXPORT QCefContext : public QObject
~QCefContext();

/// <summary>
/// Adds a url mapping item with local web resource directory
/// Adds a url mapping item with local web resource directory. This works for all <see ref="QCefView" /> instances created subsequently
/// </summary>
/// <param name="path">The path to the local resource directory</param>
/// <param name="url">The url to be mapped to</param>
/// <param name="priority">The priority</param>
void addLocalFolderResource(const QString& path, const QString& url, int priority = 0);

/// <summary>
/// Adds a url mapping item with local archive (.zip) file which contains the web resource
/// Adds a url mapping item with local archive (.zip) file which contains the web resource. This works for all <see ref="QCefView" /> instances created subsequently
/// </summary>
/// <param name="path">The path to the local archive file</param>
/// <param name="url">The url to be mapped to</param>
Expand Down
17 changes: 17 additions & 0 deletions include/QCefView.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,23 @@ class QCEFVIEW_EXPORT QCefView : public QWidget
/// Destructs the QCefView instance
/// </summary>
~QCefView();

/// <summary>
/// Adds a url mapping item with local web resource directory
/// </summary>
/// <param name="path">The path to the local resource directory</param>
/// <param name="url">The url to be mapped to</param>
/// <param name="priority">The priority</param>
void addLocalFolderResource(const QString& path, const QString& url, int priority = 0);

/// <summary>
/// Adds a url mapping item with local archive (.zip) file which contains the web resource
/// </summary>
/// <param name="path">The path to the local archive file</param>
/// <param name="url">The url to be mapped to</param>
/// <param name="password">The password of the archive</param>
/// <param name="priority">The priority</param>
void addArchiveResource(const QString& path, const QString& url, const QString& password = "", int priority = 0);

/// <summary>
/// Gets the browser id
Expand Down
25 changes: 23 additions & 2 deletions src/QCefView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,33 @@ QCefView::QCefView(const QString url, const QCefSetting* setting, QWidget* paren

QCefView::QCefView(QWidget* parent /*= 0*/)
: QCefView("about:blank", nullptr, parent)
{}
{
}

QCefView::~QCefView()
{
qDebug() << this << "is being destructed";
}

void
QCefView::addLocalFolderResource(const QString& path, const QString& url, int priority /*= 0*/)
{
Q_D(QCefView);

d->addLocalFolderResource(path, url, priority);
}

void
QCefView::addArchiveResource(const QString& path,
const QString& url,
const QString& password /*= ""*/,
int priority /*= 0*/)
{
Q_D(QCefView);

d->addArchiveResource(path, url, password, priority);
}

int
QCefView::browserId()
{
Expand Down Expand Up @@ -186,7 +206,8 @@ QCefView::onBeforePopup(qint64 frameId,

void
QCefView::onPopupCreated(QWindow* wnd)
{}
{
}

QVariant
QCefView::inputMethodQuery(Qt::InputMethodQuery query) const
Expand Down
19 changes: 19 additions & 0 deletions src/details/QCefViewPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,25 @@ QCefViewPrivate::destroyCefBrowser()
pCefBrowser_ = nullptr;
}

void
QCefViewPrivate::addLocalFolderResource(const QString& path, const QString& url, int priority /*= 0*/)
{
if (pClient_) {
pClient_->AddLocalDirectoryResourceProvider(path.toStdString(), url.toStdString(), priority);
}
}

void
QCefViewPrivate::addArchiveResource(const QString& path,
const QString& url,
const QString& password /*= ""*/,
int priority /*= 0*/)
{
if (pClient_) {
pClient_->AddArchiveResourceProvider(path.toStdString(), url.toStdString(), password.toStdString(), priority);
}
}

void
QCefViewPrivate::onCefMainBrowserCreated(CefRefPtr<CefBrowser>& browser, QWindow* window)
{
Expand Down
4 changes: 4 additions & 0 deletions src/details/QCefViewPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ class QCefViewPrivate : public QObject

void destroyCefBrowser();

void addLocalFolderResource(const QString& path, const QString& url, int priority = 0);

void addArchiveResource(const QString& path, const QString& url, const QString& password = "", int priority = 0);

protected:
void onCefMainBrowserCreated(CefRefPtr<CefBrowser>& browser, QWindow* window);

Expand Down