CB-6396 [Firefox OS] Adding basic support
This commit is contained in:
parent
9399ed3955
commit
51879d8e2f
11
doc/index.md
11
doc/index.md
@ -30,6 +30,17 @@ and can't access Cordova APIs.
|
||||
|
||||
cordova plugin add org.apache.cordova.inappbrowser
|
||||
|
||||
### Firefox OS
|
||||
|
||||
Create __www/manifest.webapp__ as described in
|
||||
[Manifest Docs](https://developer.mozilla.org/en-US/Apps/Developing/Manifest).
|
||||
Add relevant permisions.
|
||||
|
||||
"permissions": {
|
||||
"browser": {}
|
||||
}
|
||||
|
||||
|
||||
## window.open
|
||||
|
||||
Opens a URL in a new `InAppBrowser` instance, the current browser
|
||||
|
@ -137,5 +137,14 @@
|
||||
</js-module>
|
||||
</platform>
|
||||
|
||||
<!-- firefoxos -->
|
||||
<platform name="firefoxos">
|
||||
<js-module src="www/inappbrowser.js" name="inappbrowser">
|
||||
<clobbers target="window.open" />
|
||||
</js-module>
|
||||
<js-module src="src/firefoxos/InAppBrowserProxy.js" name="InAppBrowserProxy">
|
||||
<merges target="" />
|
||||
</js-module>
|
||||
</platform>
|
||||
|
||||
</plugin>
|
||||
|
108
src/firefoxos/InAppBrowserProxy.js
Normal file
108
src/firefoxos/InAppBrowserProxy.js
Normal file
@ -0,0 +1,108 @@
|
||||
/*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/WebAPI/Browser
|
||||
|
||||
var cordova = require('cordova'),
|
||||
channel = require('cordova/channel'),
|
||||
modulemapper = require('cordova/modulemapper');
|
||||
|
||||
var origOpenFunc = modulemapper.getOriginalSymbol(window, 'window.open');
|
||||
var browserWrap;
|
||||
|
||||
var IABExecs = {
|
||||
|
||||
close: function (win, lose) {
|
||||
if (browserWrap) {
|
||||
browserWrap.parentNode.removeChild(browserWrap);
|
||||
browserWrap = null;
|
||||
}
|
||||
},
|
||||
|
||||
/*
|
||||
* Reveal browser if opened hidden
|
||||
*/
|
||||
show: function (win, lose) {
|
||||
console.error('[FirefoxOS] show not implemented');
|
||||
},
|
||||
|
||||
open: function (win, lose, args) {
|
||||
var strUrl = args[0],
|
||||
target = args[1],
|
||||
features = args[2],
|
||||
url,
|
||||
elem;
|
||||
|
||||
if (target === '_system') {
|
||||
origOpenFunc.apply(window, [strUrl, '_blank']);
|
||||
} else if (target === '_blank') {
|
||||
var browserElem = document.createElement('iframe');
|
||||
browserElem.setAttribute('mozbrowser', true);
|
||||
// make this loaded in its own child process
|
||||
browserElem.setAttribute('remote', true);
|
||||
browserElem.setAttribute('src', strUrl);
|
||||
if (browserWrap) {
|
||||
document.body.removeChild(browserWrap);
|
||||
}
|
||||
browserWrap = document.createElement('div');
|
||||
browserWrap.style.position = 'absolute';
|
||||
browserWrap.style.backgroundColor = 'rgba(0,0,0,0.75)';
|
||||
browserWrap.style.color = 'rgba(235,235,235,1.0)';
|
||||
browserWrap.style.width = window.innerWidth + 'px';
|
||||
browserWrap.style.height = window.innerHeight + 'px';
|
||||
browserWrap.style.padding = '10px,0,0,0';
|
||||
browserElem.style.position = 'absolute';
|
||||
browserElem.style.top = '60px';
|
||||
browserElem.style.left = '0px';
|
||||
browserElem.style.height = (window.innerHeight - 60) + 'px';
|
||||
browserElem.style.width = browserWrap.style.width;
|
||||
|
||||
browserWrap.addEventListener('click', function () {
|
||||
setTimeout(function () {
|
||||
IAB.close();
|
||||
}, 0);
|
||||
}, false);
|
||||
var p = document.createElement('p');
|
||||
p.appendChild(document.createTextNode('close'));
|
||||
// TODO: make all buttons - ← → ×
|
||||
p.style.paddingTop = '10px';
|
||||
p.style.textAlign = 'center';
|
||||
browserWrap.appendChild(p);
|
||||
browserWrap.appendChild(browserElem);
|
||||
document.body.appendChild(browserWrap);
|
||||
// assign browser element to browserWrap for future
|
||||
// reference
|
||||
browserWrap.browser = browserElem;
|
||||
} else {
|
||||
window.location = strUrl;
|
||||
}
|
||||
},
|
||||
injectScriptCode: function (code, bCB) {
|
||||
console.error('[FirefoxOS] injectScriptCode not implemented');
|
||||
},
|
||||
injectScriptFile: function (file, bCB) {
|
||||
console.error('[FirefoxOS] injectScriptFile not implemented');
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = IABExecs;
|
||||
|
||||
require('cordova/firefoxos/commandProxy').add('InAppBrowser', module.exports);
|
Loading…
Reference in New Issue
Block a user