History

add option to add javascript objects to a DataWebDialog

Stephen Birarda committed 12 years ago

Commit e09eef91 parent a66b6e73 files · +25 −3Browse files

Showing the changes to interface/src/ui/DataWebDialog.cpp (1 of 3 files). Show all

Unified · Split

interface/src/ui/DataWebDialog.cpp+13−1
@@ -9,6 +9,7 @@ · 8 unmodified lines
9// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html9// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10//10//
11 11
12#include <qwebframe.h>
12#include <qwebview.h>13#include <qwebview.h>
13 14
14#include <AccountManager.h>15#include <AccountManager.h>
@@ -33,9 +34,14 @@ DataWebDialog::DataWebDialog() { · 18 unmodified lines
33 connect(this, &QWebView::linkClicked, Application::getInstance(), &Application::openUrl);34 connect(this, &QWebView::linkClicked, Application::getInstance(), &Application::openUrl);
34}35}
35 36
36DataWebDialog* DataWebDialog::dialogForPath(const QString& path) {37DataWebDialog* DataWebDialog::dialogForPath(const QString& path,
38 const JavascriptObjectMap& javascriptObjects) {
37 DataWebDialog* dialogWebView = new DataWebDialog();39 DataWebDialog* dialogWebView = new DataWebDialog();
38 40
41 dialogWebView->_javascriptObjects = javascriptObjects;
42 connect(dialogWebView->page()->mainFrame(), &QWebFrame::javaScriptWindowObjectCleared,
43 dialogWebView, &DataWebDialog::addJavascriptObjectsToWindow);
44
39 QUrl dataWebUrl(DEFAULT_NODE_AUTH_URL);45 QUrl dataWebUrl(DEFAULT_NODE_AUTH_URL);
40 dataWebUrl.setPath(path);46 dataWebUrl.setPath(path);
41 47
@@ -44,4 +50,10 @@ DataWebDialog* DataWebDialog::dialogForPath(const QString& path) { · 2 unmodified lines
44 dialogWebView->load(dataWebUrl);50 dialogWebView->load(dataWebUrl);
45 51
46 return dialogWebView;52 return dialogWebView;
53}
54
55void DataWebDialog::addJavascriptObjectsToWindow() {
56 foreach(const QString& name, _javascriptObjects.keys()) {
57 page()->mainFrame()->addToJavaScriptWindowObject(name, _javascriptObjects[name]);
58 }
47}59}