WebBrowser/Tools/Scripts.py

changeset 6140
c20e2d414d0d
parent 6135
12e48d27f1d7
child 6142
304a469455c8
--- a/WebBrowser/Tools/Scripts.py	Mon Feb 12 18:22:39 2018 +0100
+++ b/WebBrowser/Tools/Scripts.py	Mon Feb 12 19:04:07 2018 +0100
@@ -19,16 +19,22 @@
 from .WebBrowserTools import readAllFileContents
 
 
-def setupWebChannel():
+def setupWebChannel(worldId):
     """
     Function generating  a script to setup the web channel.
     
+    @param worlId world ID for which to setup the channel
+    @type int
     @return script to setup the web channel
     @rtype str
     """
     source = """
+// ==UserScript==
+{0}
+// ==/UserScript==
+
 (function() {{
-    {0}
+    {1}
     
     function registerExternal(e) {{
         window.external = e;
@@ -71,7 +77,13 @@
 
 }})()"""
     
-    return source.format(readAllFileContents(":/javascript/qwebchannel.js"))
+    from WebBrowser.WebBrowserPage import WebBrowserPage
+    if worldId == WebBrowserPage.SafeJsWorld:
+        match = "// @exclude eric:*"
+    else:
+        match = "// @include eric:*"
+    return source.format(
+        match, readAllFileContents(":/javascript/qwebchannel.js"))
 
 
 def setStyleSheet(css):

eric ide

mercurial