Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Narvaez <dwnarvaez@gmail.com>2013-05-06 20:07:27 (GMT)
committer Daniel Narvaez <dwnarvaez@gmail.com>2013-06-10 13:46:53 (GMT)
commit0abae0e7d058489e62f69186f69267a001a81810 (patch)
tree1d16928dde6cb9335a9a5823e8275e7db13b4f9e
parente649070aa2a39a8c4848d63a18b1908a0733f8ee (diff)
Use a custom scheme for app content
To get the origin right.
-rw-r--r--src/sugar3/activity/htmlactivity.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/sugar3/activity/htmlactivity.py b/src/sugar3/activity/htmlactivity.py
index 38beed5..5b8ae4d 100644
--- a/src/sugar3/activity/htmlactivity.py
+++ b/src/sugar3/activity/htmlactivity.py
@@ -19,6 +19,7 @@ import json
import os
from gi.repository import GConf
+from gi.repository import Gio
from gi.repository import WebKit2
from gwebsockets.server import Server
@@ -42,6 +43,9 @@ class HTMLActivity(activity.Activity):
def __init__(self, handle):
activity.Activity.__init__(self, handle)
+ context = WebKit2.WebContext.get_default()
+ context.register_uri_scheme("activity", self._app_scheme_cb, None)
+
self._web_view = WebKit2.WebView()
self.set_canvas(self._web_view)
self._web_view.show()
@@ -54,12 +58,20 @@ class HTMLActivity(activity.Activity):
index_path = os.path.join(activity.get_bundle_path(), "index.html")
self._key = os.urandom(16).encode("hex")
- self._web_view.load_uri("file://%s?port=%s&key=%s" %
- (index_path, port, self._key))
+ self._web_view.load_uri("activity://%s/%s?port=%s&key=%s" %
+ (self.get_bundle_id(),
+ index_path,
+ port, self._key))
self._apis = {}
self._apis["activity"] = ActivityAPI(self)
+ def _app_scheme_cb(self, request, user_data):
+ path = os.path.join(activity.get_bundle_path(), request.get_path())
+
+ request.finish(Gio.File.new_for_path(path).read(None),
+ -1, Gio.content_type_guess(path, None)[0])
+
def _session_started_cb(self, server, session):
session.connect("message-received", self._message_received_cb)