Skip to content

Commit

Permalink
Merge pull request #1 from zalun/add-firefoxos-plugin
Browse files Browse the repository at this point in the history
CB-6396 [Firefox OS] Adding basic support
  • Loading branch information
Steckelfisch committed Apr 7, 2014
2 parents 9399ed3 + 51879d8 commit c14871d
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 0 deletions.
11 changes: 11 additions & 0 deletions doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 108 additions & 0 deletions src/firefoxos/InAppBrowserProxy.js
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit c14871d

Please sign in to comment.