зеркало из https://github.com/mozilla/gecko-dev.git
Bug 754141 (3/4) - Get the application object from an AppsService based on the manifest URL and save it on the window object. r=fabrice,jlebar
This commit is contained in:
Родитель
ec077a5c28
Коммит
27ddcf683c
|
@ -75,6 +75,7 @@ DIRS += \
|
|||
$(NULL)
|
||||
|
||||
DIRS += \
|
||||
apps \
|
||||
base \
|
||||
bindings \
|
||||
battery \
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
# You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
DEPTH = ../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
relativesrcdir = dom/apps
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
PARALLEL_DIRS = src
|
||||
|
||||
TEST_DIRS += tests
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
|
@ -0,0 +1,41 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
"use strict"
|
||||
|
||||
function debug(s) {
|
||||
//dump("-*- AppsService: " + s + "\n");
|
||||
}
|
||||
|
||||
const Ci = Components.interfaces;
|
||||
const Cu = Components.utils;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Webapps.jsm");
|
||||
|
||||
const APPS_SERVICE_CONTRACTID = "@mozilla.org/AppsService;1";
|
||||
const APPS_SERVICE_CID = Components.ID("{05072afa-92fe-45bf-ae22-39b69c117058}");
|
||||
|
||||
function AppsService()
|
||||
{
|
||||
debug("AppsService Constructor");
|
||||
}
|
||||
|
||||
AppsService.prototype = {
|
||||
getAppByManifestURL: function getAppByManifestURL(aManifestURL) {
|
||||
debug("GetAppByManifestURL( " + aManifestURL + " )");
|
||||
return DOMApplicationRegistry.getAppByManifestURL(aManifestURL)
|
||||
},
|
||||
|
||||
classID : APPS_SERVICE_CID,
|
||||
QueryInterface : XPCOMUtils.generateQI([Ci.nsIAppsService]),
|
||||
|
||||
classInfo : XPCOMUtils.generateCI({classID: APPS_SERVICE_CID,
|
||||
contractID: APPS_SERVICE_CONTRACTID,
|
||||
classDescription: "AppsService",
|
||||
interfaces: [Ci.nsIAppsService],
|
||||
flags: Ci.nsIClassInfo.DOM_OBJECT})
|
||||
}
|
||||
|
||||
const NSGetFactory = XPCOMUtils.generateNSGetFactory([AppsService])
|
|
@ -0,0 +1,2 @@
|
|||
component {05072afa-92fe-45bf-ae22-39b69c117058} AppsService.js
|
||||
contract @mozilla.org/AppsService;1 {05072afa-92fe-45bf-ae22-39b69c117058}
|
|
@ -0,0 +1,17 @@
|
|||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
# You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
EXTRA_COMPONENTS = \
|
||||
AppsService.js \
|
||||
AppsService.manifest \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
|
@ -0,0 +1,34 @@
|
|||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
# You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
relativesrcdir = dom/apps/tests
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
_TEST_FILES = \
|
||||
$(NULL)
|
||||
|
||||
_CHROME_TEST_FILES = \
|
||||
test_apps_service.xul \
|
||||
$(NULL)
|
||||
|
||||
ifneq (,$(_TEST_FILES))
|
||||
libs:: $(_TEST_FILES)
|
||||
$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
|
||||
endif
|
||||
|
||||
ifneq (,$(_CHROME_TEST_FILES))
|
||||
libs:: $(_CHROME_TEST_FILES)
|
||||
$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
|
||||
endif
|
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
|
||||
<?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=754141
|
||||
-->
|
||||
<window title="Mozilla Bug 754141"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
|
||||
<!-- test results are displayed in the html:body -->
|
||||
<body xmlns="http://www.w3.org/1999/xhtml">
|
||||
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=754141"
|
||||
target="_blank">Mozilla Bug 754141</a>
|
||||
</body>
|
||||
|
||||
<!-- test code goes here -->
|
||||
<script type="application/javascript">
|
||||
<![CDATA[
|
||||
|
||||
/** Test for Bug 754141 **/
|
||||
|
||||
var appsService = Components.classes['@mozilla.org/AppsService;1']
|
||||
.getService(Components.interfaces.nsIAppsService);
|
||||
SimpleTest.ok(appsService, "Should be able to get the Apps Service");
|
||||
|
||||
SimpleTest.ok('getAppByManifestURL' in appsService,
|
||||
"getAppByManifestURL() should be a method in nsIAppsService");
|
||||
|
||||
SimpleTest.is(appsService.getAppByManifestURL(''), null,
|
||||
"getAppByManifestURL() should return null for an empty string manifest url");
|
||||
|
||||
]]>
|
||||
</script>
|
||||
</window>
|
|
@ -346,6 +346,20 @@ let DOMApplicationRegistry = {
|
|||
let app = this._cloneAppObject(this.webapps[aId]);
|
||||
return app;
|
||||
},
|
||||
|
||||
getAppByManifestURL: function(aManifestURL) {
|
||||
// This could be O(1) if |webapps| was a dictionary indexed on manifestURL
|
||||
// which should be the unique app identifier.
|
||||
// It's currently O(n).
|
||||
for (let id in this.webapps) {
|
||||
let app = this.webapps[id];
|
||||
if (app.manifestURL == aManifestURL) {
|
||||
return this._cloneAppObject(app);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
getAllWithoutManifests: function(aCallback) {
|
||||
let result = {};
|
||||
|
|
|
@ -260,6 +260,7 @@
|
|||
#include "nsLocation.h"
|
||||
#include "nsWrapperCacheInlines.h"
|
||||
#include "nsDOMEventTargetHelper.h"
|
||||
#include "nsIAppsService.h"
|
||||
|
||||
#ifdef ANDROID
|
||||
#include <android/log.h>
|
||||
|
@ -10014,6 +10015,9 @@ nsGlobalWindow::SetIsApp(bool aValue)
|
|||
{
|
||||
FORWARD_TO_OUTER_VOID(SetIsApp, (aValue));
|
||||
|
||||
// You shouldn't call SetIsApp() more than once.
|
||||
MOZ_ASSERT(mIsApp == TriState_Unknown);
|
||||
|
||||
mIsApp = aValue ? TriState_True : TriState_False;
|
||||
}
|
||||
|
||||
|
@ -10027,6 +10031,8 @@ nsGlobalWindow::IsPartOfApp()
|
|||
for (nsGlobalWindow* w = this; w;
|
||||
w = static_cast<nsGlobalWindow*>(w->GetParentInternal())) {
|
||||
if (w->mIsApp == TriState_True) {
|
||||
// The window should be part of an application.
|
||||
MOZ_ASSERT(w->mApp);
|
||||
return true;
|
||||
} else if (w->mIsApp == TriState_False) {
|
||||
return false;
|
||||
|
@ -10039,7 +10045,26 @@ nsGlobalWindow::IsPartOfApp()
|
|||
nsresult
|
||||
nsGlobalWindow::SetApp(const nsAString& aManifestURL)
|
||||
{
|
||||
MOZ_ASSERT(mIsApp != TriState_True);
|
||||
// SetIsApp(true) should be called before calling SetApp().
|
||||
if (mIsApp != TriState_True) {
|
||||
MOZ_ASSERT(false);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIAppsService> appsService = do_GetService(APPS_SERVICE_CONTRACTID);
|
||||
if (!appsService) {
|
||||
NS_ERROR("Apps Service is not available!");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsCOMPtr<mozIDOMApplication> app;
|
||||
appsService->GetAppByManifestURL(aManifestURL, getter_AddRefs(app));
|
||||
if (!app) {
|
||||
NS_WARNING("No application found with the specified manifest URL");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
mApp = app.forget();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -99,6 +99,7 @@
|
|||
#include "nsIDOMTouchEvent.h"
|
||||
#include "nsIInlineEventHandlers.h"
|
||||
#include "nsWrapperCacheInlines.h"
|
||||
#include "nsIDOMApplicationRegistry.h"
|
||||
|
||||
// JS includes
|
||||
#include "jsapi.h"
|
||||
|
@ -994,6 +995,10 @@ protected:
|
|||
|
||||
nsTArray<PRUint32> mEnabledSensors;
|
||||
|
||||
// The application associated with this window.
|
||||
// This should only be non-null if mIsApp's value is TriState_True.
|
||||
nsCOMPtr<mozIDOMApplication> mApp;
|
||||
|
||||
friend class nsDOMScriptableHelper;
|
||||
friend class nsDOMWindowUtils;
|
||||
friend class PostMessageEvent;
|
||||
|
|
|
@ -48,6 +48,7 @@ GRE_MODULE = 1
|
|||
|
||||
XPIDLSRCS = \
|
||||
nsIDOMApplicationRegistry.idl \
|
||||
nsIAppsService.idl \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "domstubs.idl"
|
||||
|
||||
interface mozIDOMApplication;
|
||||
|
||||
%{C++
|
||||
#define APPS_SERVICE_CID { 0x05072afa, 0x92fe, 0x45bf, { 0xae, 0x22, 0x39, 0xb6, 0x9c, 0x11, 0x70, 0x58 } }
|
||||
#define APPS_SERVICE_CONTRACTID "@mozilla.org/AppsService;1"
|
||||
%}
|
||||
|
||||
/*
|
||||
* This service allows accessing some DOMApplicationRegistry methods from
|
||||
* non-javascript code.
|
||||
*/
|
||||
[scriptable, uuid(8a4d9921-58ae-41da-a6f1-5f842c3a050f)]
|
||||
interface nsIAppsService : nsISupports
|
||||
{
|
||||
mozIDOMApplication getAppByManifestURL(in DOMString manifestURL);
|
||||
};
|
Загрузка…
Ссылка в новой задаче