Skip to content

Commit

Permalink
feat(registry,ui): respect per docset JavaScript enablement (fixes #999
Browse files Browse the repository at this point in the history
…) (#1003)
  • Loading branch information
nishanthkarthik authored and trollixx committed Oct 7, 2018
1 parent b7d528b commit 8bfacd7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/libs/registry/docset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const char DashDocSetPluginKeyword[] = "DashDocSetPluginKeyword";
const char DashIndexFilePath[] = "dashIndexFilePath";
const char DocSetPlatformFamily[] = "DocSetPlatformFamily";
//const char IsDashDocset[] = "isDashDocset";
//const char IsJavaScriptEnabled[] = "isJavaScriptEnabled";
const char IsJavaScriptEnabled[] = "isJavaScriptEnabled";
}
}

Expand Down Expand Up @@ -163,6 +163,10 @@ Docset::Docset(const QString &path) :
}
}

if (plist.contains(InfoPlist::IsJavaScriptEnabled)) {
m_javaScriptEnabled = plist[InfoPlist::IsJavaScriptEnabled].toBool();
}

m_keywords.removeDuplicates();

// Prefer index path provided by the docset over metadata.
Expand Down Expand Up @@ -682,6 +686,11 @@ void Docset::setFuzzySearchEnabled(bool enabled)
m_fuzzySearchEnabled = enabled;
}

bool Docset::isJavaScriptEnabled() const
{
return m_javaScriptEnabled;
}

/**
* \brief Returns score based on a substring position in a string.
* \param str Original string.
Expand Down
3 changes: 3 additions & 0 deletions src/libs/registry/docset.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class Docset
bool isFuzzySearchEnabled() const;
void setFuzzySearchEnabled(bool enabled);

bool isJavaScriptEnabled() const;

private:
enum class Type {
Invalid,
Expand Down Expand Up @@ -113,6 +115,7 @@ class Docset
mutable QMap<QString, QMap<QString, QUrl>> m_symbols;
Util::SQLiteDatabase *m_db = nullptr;
bool m_fuzzySearchEnabled = false;
bool m_javaScriptEnabled = false;
};

} // namespace Registry
Expand Down
5 changes: 3 additions & 2 deletions src/libs/ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,9 +624,10 @@ void MainWindow::attachTab(TabState *tabState)
m_tabBar->setTabIcon(m_tabBar->currentIndex(), docsetIcon(name));

Registry::Docset *docset = m_application->docsetRegistry()->docset(name);
if (docset)
if (docset) {
tabState->tocModel->setResults(docset->relatedLinks(url));

tabState->widget->setJavaScriptEnabled(docset->isJavaScriptEnabled());
}
ui->actionBack->setEnabled(tabState->widget->canGoBack());
ui->actionForward->setEnabled(tabState->widget->canGoForward());
});
Expand Down
5 changes: 5 additions & 0 deletions src/libs/ui/widgets/webviewtab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ void WebViewTab::setZoomLevel(int level)
m_webView->setZoomLevel(level);
}

void WebViewTab::setJavaScriptEnabled(bool enabled)
{
m_webView->page()->settings()->setAttribute(QWebSettings::JavascriptEnabled, enabled);
}

void WebViewTab::setWebBridgeObject(const QString &name, QObject *object)
{
connect(m_webView->page()->mainFrame(), &QWebFrame::javaScriptWindowObjectCleared,
Expand Down
1 change: 1 addition & 0 deletions src/libs/ui/widgets/webviewtab.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class WebViewTab : public QWidget

int zoomLevel() const;
void setZoomLevel(int level);
void setJavaScriptEnabled(bool enabled);

void setWebBridgeObject(const QString &name, QObject *object);

Expand Down

0 comments on commit 8bfacd7

Please sign in to comment.