This repository has been archived by the owner on Oct 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from mozilla/bug/689792-contentWindow
Bug/689792 content window r=anant
- Loading branch information
Showing
8 changed files
with
211 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
|
||
if (!window.navigator.mozApps) | ||
window.navigator.mozApps = {} | ||
if (!window.navigator.mozApps.services) | ||
window.navigator.mozApps.services = {} | ||
|
||
// Insert the services api into unsafeWindow | ||
if (!unsafeWindow.navigator.mozApps) | ||
unsafeWindow.navigator.mozApps = window.navigator.mozApps; | ||
if (!unsafeWindow.navigator.mozApps.mediation) 3 | ||
unsafeWindow.navigator.mozApps.services = window.navigator.mozApps.services; | ||
|
||
var activities = {}; | ||
var origin = null; | ||
var callid = 0; | ||
|
||
window.navigator.mozApps.services = { | ||
// notify our mediator that we're ready for business. | ||
ready: function() { | ||
self.port.emit("owa.service.ready", origin); | ||
}, | ||
// the service is registering a handler. we track it here and then let the mediator know | ||
// we're listing for shit | ||
registerHandler: function(action, message, func) { | ||
var activity = { | ||
origin: origin, | ||
action: action, | ||
message: message | ||
} | ||
activities[action+"/"+message] = { | ||
activity: activity, | ||
message: message, | ||
callback: func | ||
} | ||
self.port.emit("owa.service.register.handler", activity); | ||
}, | ||
// the service is making an oauth call, setup a result callback mechanism then make the call. | ||
// the service will already have oauth credentials from an early login process initiated by | ||
// our mediator | ||
oauth: { | ||
call: function(svc, data, callback) { | ||
callid++; | ||
self.port.once("owa.service.oauth.call.result."+callid, function(result) { | ||
callback(result); | ||
}); | ||
self.port.emit('owa.service.oauth.call', { | ||
svc: svc, | ||
data: data, | ||
result: "owa.service.oauth.call.result."+callid | ||
}); | ||
} | ||
} | ||
} | ||
|
||
self.port.on("owa.service.origin", function(frameOrigin) { | ||
origin = frameOrigin; | ||
}); | ||
|
||
// someone called invokeService, we handle it here | ||
self.port.on("owa.service.invoke", function(args) { | ||
var activity = args.activity; | ||
var credentials = args.credentials; | ||
activity.postResult = function postResult(result) { | ||
self.port.emit(activity.success, result); | ||
} | ||
activity.postException = function postException(exc) { | ||
self.port.emit(activity.error, exc); | ||
} | ||
activities[activity.action+"/"+activity.message].callback(activity, credentials); | ||
}); | ||
|
||
unsafeWindow.navigator.mozApps.services = window.navigator.mozApps.services; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.