Skip to content

Instantly share code, notes, and snippets.

@janjongboom
Created April 30, 2015 13:41
Show Gist options
  • Save janjongboom/c8ed5fb371805d33d1f5 to your computer and use it in GitHub Desktop.
Save janjongboom/c8ed5fb371805d33d1f5 to your computer and use it in GitHub Desktop.
diff --git a/dom/apps/AppsUtils.jsm b/dom/apps/AppsUtils.jsm
index b44c11e..edc5caa 100644
--- a/dom/apps/AppsUtils.jsm
+++ b/dom/apps/AppsUtils.jsm
@@ -33,7 +33,7 @@ this.EXPORTED_SYMBOLS =
["AppsUtils", "ManifestHelper", "isAbsoluteURI", "mozIApplication"];
function debug(s) {
- //dump("-*- AppsUtils.jsm: " + s + "\n");
+ dump("-*- AppsUtils.jsm: " + s + "\n");
}
this.isAbsoluteURI = function(aURI) {
@@ -117,6 +117,8 @@ function _setAppProperties(aObj, aApp) {
aObj.kind = aApp.kind;
aObj.enabled = aApp.enabled !== undefined ? aApp.enabled : true;
aObj.sideloaded = aApp.sideloaded;
+ aObj.osPaths = aApp.osPaths;
+ dump('Set osPaths to ' + JSON.stringify(aObj.osPaths) + '\n');
}
this.AppsUtils = {
@@ -978,5 +980,13 @@ ManifestHelper.prototype = {
get csp() {
return this._manifest.csp || "";
+ },
+
+ get osPaths() {
+ let permissions = this._manifest.permissions;
+ if (!permissions || !permissions.os) {
+ return [];
+ }
+ return permissions.os;
}
}
diff --git a/dom/interfaces/apps/mozIApplication.idl b/dom/interfaces/apps/mozIApplication.idl
index 0056df3..9f5c95d 100644
--- a/dom/interfaces/apps/mozIApplication.idl
+++ b/dom/interfaces/apps/mozIApplication.idl
@@ -7,6 +7,8 @@
#include "domstubs.idl"
+interface nsIArray;
+
/**
* We expose Gecko-internal helpers related to "web apps" through this
* sub-interface.
@@ -58,4 +60,8 @@ interface mozIApplication: nsISupports
/* Returns the kind of the app. */
readonly attribute DOMString kind;
+
+ /* If the app has access to the os module, lists all the paths that the app
+ is allowed to access */
+ readonly attribute nsIArray osPaths; // DOMString[]
};
diff --git a/dom/os/OsManager.cpp b/dom/os/OsManager.cpp
index 4fbf067..2365e7b 100644
--- a/dom/os/OsManager.cpp
+++ b/dom/os/OsManager.cpp
@@ -19,21 +19,85 @@
#include "mozilla/ipc/FileDescriptor.h"
#include "mozilla/ipc/PBackgroundChild.h"
#include "nsIDOMClassInfo.h"
+#include "nsThreadUtils.h"
#include "OsManager.h"
#include "StatSerializer.h"
+#include "mozIApplication.h"
+#include "nsIAppsService.h"
+#include "nsIServiceManager.h"
+
namespace mozilla {
namespace dom {
namespace os {
+
+typedef void (*TestCallback)(const int& aResult);
using mozilla::ipc::FileDescriptor;
+class TestRunnable : public nsRunnable {
+public:
+ TestRunnable(uint32_t aAppId, TestCallback aCallback)
+ : mAppId(aAppId)
+ , mCallback(aCallback)
+ {
+ MOZ_ASSERT(!NS_IsMainThread());
+ }
+
+ NS_IMETHOD Run() {
+ MOZ_ASSERT(NS_IsMainThread());
+
+ nsCOMPtr<nsIAppsService> appsService = do_GetService(APPS_SERVICE_CONTRACTID);
+ if (!appsService) {
+ printf("No appsService...\n");
+ return NS_ERROR_FAILURE;
+ }
+
+ printf("has appService\n");
+
+ nsCOMPtr<mozIApplication> app;
+ nsresult rv = appsService->GetAppByLocalId(mAppId, getter_AddRefs(app));
+ if (NS_FAILED(rv)) {
+ printf("GetAppByLocalId failed\n");
+ return rv;
+ }
+ if (!app) {
+ printf("Could not get app... %d\n", mAppId);
+ return NS_ERROR_FAILURE;
+ }
+
+ nsAutoString manifestURL;
+ app->GetManifestURL(manifestURL);
+
+ nsCOMPtr<nsIArray> bla;
+ app->GetOsPaths(getter_AddRefs(bla));
+
+ printf("Still here\n");
+
+ uint32_t length;
+ bla->GetLength(&length);
+ printf("Length=%d\n", length);
+
+ mCallback(42);
+ return NS_OK;
+ }
+private:
+ uint32_t mAppId;
+ TestCallback mCallback;
+};
+
NS_IMPL_ADDREF_INHERITED(OsManager, DOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(OsManager, DOMEventTargetHelper)
NS_INTERFACE_MAP_BEGIN(OsManager)
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
+
+void OnBlabla(const int& aResult)
+{
+ printf("OsManager::OnBlabla %d\n", aResult);
+}
+
OsManager::OsManager(workers::WorkerGlobalScope* aScope)
: DOMEventTargetHelper(static_cast<DOMEventTargetHelper*>(aScope)),
mScope(aScope)
@@ -43,6 +107,20 @@ OsManager::OsManager(workers::WorkerGlobalScope* aScope)
mActor = backgroundChild->SendPOsFileChannelConstructor();
MOZ_ASSERT(mActor);
+
+ auto principal = workers::GetCurrentThreadWorkerPrivate()->GetPrincipal();
+ uint32_t appId;
+ nsresult rv = principal->GetAppId(&appId);
+ if (NS_FAILED(rv)) {
+ printf("Could not get appId... What now?\n");
+ return;
+ }
+ MOZ_ASSERT(appId != nsIScriptSecurityManager::UNKNOWN_APP_ID);
+
+ rv = NS_DispatchToMainThread(new TestRunnable(appId, &OnBlabla));
+ if (NS_FAILED(rv)) {
+ printf("DispatchToMainThread failed...\n");
+ }
}
JSObject*
@@ -51,6 +129,7 @@ OsManager::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
return OsManagerBinding::Wrap(aCx, this, aGivenProto);
}
+
void
OsManager::HandleErrno(int aErr, ErrorResult& aRv)
{
diff --git a/dom/os/test/test_symlink.html b/dom/os/test/test_symlink.html
index 93f6342..296bb98 100644
--- a/dom/os/test/test_symlink.html
+++ b/dom/os/test/test_symlink.html
@@ -20,7 +20,6 @@
var workerCode = `
try {
var path = navigator.os.TEMP_DIR + '/test_symlink';
- dump('path is ' + path);
try {
navigator.os.unlink(path);
}
diff --git a/dom/os/test/testapp_bla.manifest b/dom/os/test/testapp_bla.manifest
index 1efceeb..65218f3 100644
--- a/dom/os/test/testapp_bla.manifest
+++ b/dom/os/test/testapp_bla.manifest
@@ -3,5 +3,9 @@
"description": "Test",
"launch_path": "http://mochi.test:8888/tests/dom/os/test/testapp_bla.html",
"type": "certified",
- "permissions": {}
+ "permissions": {
+ "os": [
+ "/zus/zo"
+ ]
+ }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment