File indexing completed on 2024-05-05 05:00:08
0001 /* 0002 SPDX-FileCopyrightText: 1996 Martin R. Jones 0003 SPDX-FileCopyrightText: 1998 Bernd Wuebben 0004 0005 SPDX-FileCopyrightText: 1998 Torben Weis 0006 KControl port & modifications 0007 0008 SPDX-FileCopyrightText: 1998 David Faure 0009 End of the KControl port, added 'kfmclient configure' call. 0010 0011 SPDX-FileCopyrightText: 2000 Kalle Dalheimer 0012 New configuration scheme for Java/JavaScript 0013 0014 SPDX-FileCopyrightText: 2000 Daniel Molkentin 0015 Redesign and cleanup 0016 0017 SPDX-FileCopyrightText: 2002-2003 Leo Savernik 0018 Big changes to accommodate per-domain settings 0019 0020 */ 0021 0022 // Own 0023 #include "javaopts.h" 0024 0025 // Qt 0026 #include <QFormLayout> 0027 #include <QGroupBox> 0028 #include <QTreeWidget> 0029 0030 // KDE 0031 #include <kurlrequester.h> 0032 #include <klineedit.h> 0033 #include <KLocalizedString> 0034 #include <QHBoxLayout> 0035 #include <kconfiggroup.h> 0036 #include <kpluralhandlingspinbox.h> 0037 0038 // Local 0039 #include "htmlopts.h" 0040 #include "policydlg.h" 0041 #include <htmlextension.h> 0042 #include <htmlsettingsinterface.h> 0043 0044 // == class JavaPolicies ===== 0045 0046 JavaPolicies::JavaPolicies(const KSharedConfig::Ptr &config, const QString &group, bool global, 0047 const QString &domain) : 0048 Policies(config, group, global, domain, QStringLiteral("java."), QStringLiteral("EnableJava")) 0049 { 0050 } 0051 0052 /* 0053 JavaPolicies::JavaPolicies() : Policies(0,QString(),false, 0054 QString(),QString(),QString()) { 0055 } 0056 */ 0057 0058 JavaPolicies::~JavaPolicies() 0059 { 0060 } 0061 0062 // == class KJavaOptions ===== 0063 0064 KJavaOptions::KJavaOptions(const KSharedConfig::Ptr &config, const QString &group, 0065 QWidget *parent) 0066 : KCModule(parent), 0067 _removeJavaScriptDomainAdvice(false), 0068 m_pConfig(config), 0069 m_groupname(group), 0070 java_global_policies(config, group, true), 0071 _removeJavaDomainSettings(false) 0072 { 0073 QVBoxLayout *toplevel = new QVBoxLayout(widget()); 0074 0075 /*************************************************************************** 0076 ********************* Global Settings ************************************* 0077 **************************************************************************/ 0078 enableJavaGloballyCB = new QCheckBox(i18n("Enable Ja&va globally"), widget()); 0079 connect(enableJavaGloballyCB, &QAbstractButton::clicked, this, &KJavaOptions::slotChanged); 0080 connect(enableJavaGloballyCB, &QAbstractButton::clicked, this, &KJavaOptions::toggleJavaControls); 0081 toplevel->addWidget(enableJavaGloballyCB); 0082 0083 /*************************************************************************** 0084 ***************** Domain Specific Settings ******************************** 0085 **************************************************************************/ 0086 domainSpecific = new JavaDomainListView(m_pConfig, m_groupname, this, widget()); 0087 connect(domainSpecific, &DomainListView::changed, this, &KJavaOptions::slotChanged); 0088 toplevel->addWidget(domainSpecific, 2); 0089 0090 /*************************************************************************** 0091 ***************** Java Runtime Settings *********************************** 0092 **************************************************************************/ 0093 QGroupBox *javartGB = new QGroupBox(i18n("Java Runtime Settings"), widget()); 0094 QFormLayout *laygroup1 = new QFormLayout(javartGB); 0095 toplevel->addWidget(javartGB); 0096 0097 javaSecurityManagerCB = new QCheckBox(i18n("&Use security manager"), widget()); 0098 laygroup1->addRow(javaSecurityManagerCB); 0099 connect(javaSecurityManagerCB, &QAbstractButton::toggled, this, &KJavaOptions::slotChanged); 0100 0101 useKioCB = new QCheckBox(i18n("Use &KIO"), widget()); 0102 laygroup1->addRow(useKioCB); 0103 connect(useKioCB, &QAbstractButton::toggled, this, &KJavaOptions::slotChanged); 0104 0105 enableShutdownCB = new QCheckBox(i18n("Shu&tdown applet server when inactive for more than"), widget()); 0106 connect(enableShutdownCB, &QAbstractButton::toggled, this, &KJavaOptions::slotChanged); 0107 connect(enableShutdownCB, &QAbstractButton::clicked, this, &KJavaOptions::toggleJavaControls); 0108 QWidget *secondsHB = new QWidget(javartGB); 0109 QHBoxLayout *secondsHBHBoxLayout = new QHBoxLayout(secondsHB); 0110 secondsHBHBoxLayout->setContentsMargins(0, 0, 0, 0); 0111 laygroup1->addWidget(secondsHB); 0112 serverTimeoutSB = new KPluralHandlingSpinBox(secondsHB); 0113 serverTimeoutSB->setSizePolicy(QSizePolicy::MinimumExpanding, serverTimeoutSB->sizePolicy().verticalPolicy()); 0114 secondsHBHBoxLayout->addWidget(serverTimeoutSB); 0115 serverTimeoutSB->setSingleStep(5); 0116 serverTimeoutSB->setRange(0, 1000); 0117 serverTimeoutSB->setSuffix(ki18np(" second", " seconds")); 0118 connect(serverTimeoutSB, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](){ slotChanged(); }); 0119 laygroup1->addRow(enableShutdownCB, serverTimeoutSB); 0120 0121 pathED = new KUrlRequester(widget()); 0122 connect(pathED, &KUrlRequester::textChanged, this, &KJavaOptions::slotChanged); 0123 laygroup1->addRow(i18n("&Path to Java executable, or 'java':"), pathED); 0124 0125 addArgED = new QLineEdit(widget()); 0126 connect(addArgED, &QLineEdit::textChanged, this, &KJavaOptions::slotChanged); 0127 laygroup1->addRow(i18n("Additional Java a&rguments:"), addArgED); 0128 0129 /*************************************************************************** 0130 ********************** WhatsThis? items *********************************** 0131 **************************************************************************/ 0132 enableJavaGloballyCB->setToolTip(i18n("Enables the execution of scripts written in Java " 0133 "that can be contained in HTML pages. " 0134 "Note that, as with any browser, enabling active contents can be a security problem.")); 0135 QString wtstr = i18n("<p>This box contains the domains and hosts you have set " 0136 "a specific Java policy for. This policy will be used " 0137 "instead of the default policy for enabling or disabling Java applets on pages sent by these " 0138 "domains or hosts.</p><p>Select a policy and use the controls on " 0139 "the right to modify it.</p>"); 0140 domainSpecific->listView()->setToolTip(wtstr); 0141 #if 0 0142 domainSpecific->importButton()->setToolTip(i18n("Click this button to choose the file that contains " 0143 "the Java policies. These policies will be merged " 0144 "with the existing ones. Duplicate entries are ignored.")); 0145 domainSpecific->exportButton()->setToolTip(i18n("Click this button to save the Java policy to a zipped " 0146 "file. The file, named <b>java_policy.tgz</b>, will be " 0147 "saved to a location of your choice.")); 0148 #endif 0149 domainSpecific->setToolTip(i18n("Here you can set specific Java policies for any particular " 0150 "host or domain. To add a new policy, simply click the <i>New...</i> " 0151 "button and supply the necessary information requested by the " 0152 "dialog box. To change an existing policy, click on the <i>Change...</i> " 0153 "button and choose the new policy from the policy dialog box. Clicking " 0154 "on the <i>Delete</i> button will remove the selected policy, causing the default " 0155 "policy setting to be used for that domain.")); 0156 #if 0 0157 "The <i>Import</i> and <i>Export</i> " 0158 "button allows you to easily share your policies with other people by allowing " 0159 "you to save and retrieve them from a zipped file.")); 0160 #endif 0161 0162 javaSecurityManagerCB->setToolTip(i18n("Enabling the security manager will cause the jvm to run with a Security " 0163 "Manager in place. This will keep applets from being able to read and " 0164 "write to your file system, creating arbitrary sockets, and other actions " 0165 "which could be used to compromise your system. Disable this option at your " 0166 "own risk. You can modify your $HOME/.java.policy file with the Java " 0167 "policytool utility to give code downloaded from certain sites more " 0168 "permissions.")); 0169 0170 useKioCB->setToolTip(i18n("Enabling this will cause the jvm to use KIO for network transport ")); 0171 0172 pathED->setToolTip(i18n("Enter the path to the java executable. If you want to use the jre in " 0173 "your path, simply leave it as 'java'. If you need to use a different jre, " 0174 "enter the path to the java executable (e.g. /usr/lib/jdk/bin/java), " 0175 "or the path to the directory that contains 'bin/java' (e.g. /opt/IBMJava2-13).")); 0176 0177 addArgED->setToolTip(i18n("If you want special arguments to be passed to the virtual machine, enter them here.")); 0178 0179 QString shutdown = i18n("When all the applets have been destroyed, the applet server should shut down. " 0180 "However, starting the jvm takes a lot of time. If you would like to " 0181 "keep the java process running while you are " 0182 "browsing, you can set the timeout value to whatever you like. To keep " 0183 "the java process running for the whole time that the konqueror process is, " 0184 "leave the Shutdown Applet Server checkbox unchecked."); 0185 serverTimeoutSB->setToolTip(shutdown); 0186 enableShutdownCB->setToolTip(shutdown); 0187 } 0188 0189 void KJavaOptions::load() 0190 { 0191 // *** load *** 0192 java_global_policies.load(); 0193 bool bJavaGlobal = java_global_policies.isFeatureEnabled(); 0194 bool bSecurityManager = m_pConfig->group(m_groupname).readEntry("UseSecurityManager", true); 0195 bool bUseKio = m_pConfig->group(m_groupname).readEntry("UseKio", false); 0196 bool bServerShutdown = m_pConfig->group(m_groupname).readEntry("ShutdownAppletServer", true); 0197 int serverTimeout = m_pConfig->group(m_groupname).readEntry("AppletServerTimeout", 60); 0198 QString sJavaPath = m_pConfig->group(m_groupname).readPathEntry("JavaPath", QStringLiteral("java")); 0199 0200 if (sJavaPath == QLatin1String("/usr/lib/jdk")) { 0201 sJavaPath = QStringLiteral("java"); 0202 } 0203 0204 if (m_pConfig->group(m_groupname).hasKey("JavaDomains")) { 0205 domainSpecific->initialize(m_pConfig->group(m_groupname).readEntry("JavaDomains", QStringList())); 0206 } else if (m_pConfig->group(m_groupname).hasKey("JavaDomainSettings")) { 0207 domainSpecific->updateDomainListLegacy(m_pConfig->group(m_groupname).readEntry("JavaDomainSettings", QStringList())); 0208 _removeJavaDomainSettings = true; 0209 } else { 0210 domainSpecific->updateDomainListLegacy(m_pConfig->group(m_groupname).readEntry("JavaScriptDomainAdvice", QStringList())); 0211 _removeJavaScriptDomainAdvice = true; 0212 } 0213 0214 // *** apply to GUI *** 0215 enableJavaGloballyCB->setChecked(bJavaGlobal); 0216 javaSecurityManagerCB->setChecked(bSecurityManager); 0217 useKioCB->setChecked(bUseKio); 0218 0219 addArgED->setText(m_pConfig->group(m_groupname).readEntry("JavaArgs")); 0220 pathED->lineEdit()->setText(sJavaPath); 0221 0222 enableShutdownCB->setChecked(bServerShutdown); 0223 serverTimeoutSB->setValue(serverTimeout); 0224 0225 toggleJavaControls(); 0226 0227 KCModule::load(); 0228 } 0229 0230 void KJavaOptions::defaults() 0231 { 0232 java_global_policies.defaults(); 0233 enableJavaGloballyCB->setChecked(false); 0234 javaSecurityManagerCB->setChecked(true); 0235 useKioCB->setChecked(false); 0236 pathED->lineEdit()->setText(QStringLiteral("java")); 0237 addArgED->setText(QLatin1String("")); 0238 enableShutdownCB->setChecked(true); 0239 serverTimeoutSB->setValue(60); 0240 toggleJavaControls(); 0241 setNeedsSave(true); 0242 0243 #if QT_VERSION_MAJOR > 5 0244 setRepresentsDefaults(true); 0245 #endif 0246 } 0247 0248 void KJavaOptions::save() 0249 { 0250 java_global_policies.save(); 0251 m_pConfig->group(m_groupname).writeEntry("JavaArgs", addArgED->text()); 0252 m_pConfig->group(m_groupname).writePathEntry("JavaPath", pathED->lineEdit()->text()); 0253 m_pConfig->group(m_groupname).writeEntry("UseSecurityManager", javaSecurityManagerCB->isChecked()); 0254 m_pConfig->group(m_groupname).writeEntry("UseKio", useKioCB->isChecked()); 0255 m_pConfig->group(m_groupname).writeEntry("ShutdownAppletServer", enableShutdownCB->isChecked()); 0256 m_pConfig->group(m_groupname).writeEntry("AppletServerTimeout", serverTimeoutSB->value()); 0257 0258 domainSpecific->save(m_groupname, QStringLiteral("JavaDomains")); 0259 0260 if (_removeJavaDomainSettings) { 0261 m_pConfig->group(m_groupname).deleteEntry("JavaDomainSettings"); 0262 _removeJavaDomainSettings = false; 0263 } 0264 0265 KCModule::save(); 0266 } 0267 0268 void KJavaOptions::slotChanged() 0269 { 0270 setNeedsSave(true); 0271 } 0272 0273 void KJavaOptions::toggleJavaControls() 0274 { 0275 bool isEnabled = true; //enableJavaGloballyCB->isChecked(); 0276 0277 java_global_policies.setFeatureEnabled(enableJavaGloballyCB->isChecked()); 0278 javaSecurityManagerCB->setEnabled(isEnabled); 0279 useKioCB->setEnabled(isEnabled); 0280 addArgED->setEnabled(isEnabled); 0281 pathED->setEnabled(isEnabled); 0282 enableShutdownCB->setEnabled(isEnabled); 0283 0284 serverTimeoutSB->setEnabled(enableShutdownCB->isChecked() && isEnabled); 0285 } 0286 0287 // == class JavaDomainListView ===== 0288 0289 JavaDomainListView::JavaDomainListView(KSharedConfig::Ptr config, const QString &group, 0290 KJavaOptions *options, QWidget *parent) 0291 : DomainListView(config, i18nc("@title:group", "Doma&in-Specific"), parent), 0292 group(group), options(options) 0293 { 0294 } 0295 0296 JavaDomainListView::~JavaDomainListView() 0297 { 0298 } 0299 0300 void JavaDomainListView::updateDomainListLegacy(const QStringList &domainConfig) 0301 { 0302 domainSpecificLV->clear(); 0303 JavaPolicies pol(config, group, false); 0304 pol.defaults(); 0305 const QStringList::ConstIterator itEnd = domainConfig.end(); 0306 for (QStringList::ConstIterator it = domainConfig.begin(); it != itEnd; ++it) { 0307 QString domain; 0308 HtmlSettingsInterface::JavaScriptAdvice javaAdvice; 0309 HtmlSettingsInterface::JavaScriptAdvice javaScriptAdvice; 0310 HtmlSettingsInterface::splitDomainAdvice(*it, domain, javaAdvice, javaScriptAdvice); 0311 if (javaAdvice != HtmlSettingsInterface::JavaScriptDunno) { 0312 QTreeWidgetItem *index = new QTreeWidgetItem(domainSpecificLV, QStringList() << domain << 0313 i18n(HtmlSettingsInterface::javascriptAdviceToText(javaAdvice))); 0314 pol.setDomain(domain); 0315 pol.setFeatureEnabled(javaAdvice != HtmlSettingsInterface::JavaScriptReject); 0316 domainPolicies[index] = new JavaPolicies(pol); 0317 } 0318 } 0319 } 0320 0321 void JavaDomainListView::setupPolicyDlg(PushButton trigger, PolicyDialog &pDlg, 0322 Policies *pol) 0323 { 0324 QString caption; 0325 switch (trigger) { 0326 case AddButton: caption = i18nc("@title:window", "New Java Policy"); 0327 pol->setFeatureEnabled(!options->enableJavaGloballyCB->isChecked()); 0328 break; 0329 case ChangeButton: caption = i18nc("@title:window", "Change Java Policy"); break; 0330 default:; // inhibit gcc warning 0331 }/*end switch*/ 0332 pDlg.setWindowTitle(caption); 0333 pDlg.setFeatureEnabledLabel(i18n("&Java policy:")); 0334 pDlg.setFeatureEnabledWhatsThis(i18n("Select a Java policy for " 0335 "the above host or domain.")); 0336 pDlg.refresh(); 0337 } 0338 0339 JavaPolicies *JavaDomainListView::createPolicies() 0340 { 0341 return new JavaPolicies(config, group, false); 0342 } 0343 0344 JavaPolicies *JavaDomainListView::copyPolicies(Policies *pol) 0345 { 0346 return new JavaPolicies(*static_cast<JavaPolicies *>(pol)); 0347 } 0348