Messagelib

webenginemanagescript.cpp
1 /*
2  SPDX-FileCopyrightText: 2016-2021 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "webenginemanagescript.h"
8 #include "webengineviewer_debug.h"
9 
10 #include <QWebEngineProfile>
11 #include <QWebEngineScript>
12 #include <QWebEngineScriptCollection>
13 
14 using namespace WebEngineViewer;
15 
16 WebEngineManageScript::WebEngineManageScript(QObject *parent)
17  : QObject(parent)
18 {
19 }
20 
21 WebEngineManageScript::~WebEngineManageScript() = default;
22 
23 void WebEngineManageScript::addScript(QWebEngineProfile *profile,
24  const QString &source,
25  const QString &scriptName,
26  QWebEngineScript::InjectionPoint injectionPoint)
27 {
28  if (profile) {
29  QWebEngineScript script;
30  const QList<QWebEngineScript> collectionScripts = profile->scripts()->findScripts(scriptName);
31  if (!collectionScripts.isEmpty()) {
32  script = collectionScripts.first();
33  }
34  for (const QWebEngineScript &s : collectionScripts) {
35  profile->scripts()->remove(s);
36  }
37 
38  if (script.isNull()) {
39  script.setName(scriptName);
40  script.setInjectionPoint(injectionPoint);
41  script.setRunsOnSubFrames(true);
42  script.setWorldId(scriptWordId());
43  }
44  script.setSourceCode(source);
45  profile->scripts()->insert(script);
46  // qCDebug(WEBENGINEVIEWER_LOG) << " void WebEngineManageScript::addScript profile:" << profile;
47  }
48 }
bool isEmpty() const const
T & first()
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Nov 26 2021 23:16:44 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.