Skip to content

Commit

Permalink
Merge pull request #11 from tinyhippos/cordova
Browse files Browse the repository at this point in the history
Improved Cordova support
  • Loading branch information
gtanner committed Jul 11, 2012
2 parents d9aee8b + 5378926 commit 1a16d8f
Show file tree
Hide file tree
Showing 117 changed files with 2,163 additions and 351 deletions.
3 changes: 2 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
"sinon",
"setInterval", "clearInterval", "setTimeout", "clearTimeout",
"require", "Contact", "Position", "Coordinates", "Node",
"OpenLayers"
"OpenLayers",
"cordova"
],

"node" : true,
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ To test ripple as an extension in chrome/chromium just load the chromium folder

This will describe all the available commands for building and running the tests

## Running as a Chrome Extension

- go to the extension management page (chrome://chrome/extensions/) in chrome.
- Ensure that you have selected the developer mode checkbox
- click the Load Unpacked extension button
- select the chromium or chromestore folders in the pkg/ folder.

NOTE: for development you should be fine to just build with jake and refresh your browser. If
you end up editing anything in the ext folder you will need to refresh the extension from
the extension management page.

## Running Inside Other Web Browsers

Ripple is (by-design) browser agnostic, and is able to run inside any web browser (with disabled web security).
Expand All @@ -45,6 +56,8 @@ To get it running inside Chrome you should start it with these [command line](ht
--disable-web-security
--user-data-dir=/path/to/dummy/profile

This has only really be tested in chrome.

## Code Guidelines

* 4 spaces per editor tab
Expand Down
32 changes: 13 additions & 19 deletions build/btest.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,21 @@ module.exports = function () {
doc,
modules,
specs,
openlayers,
app = connect(
connect.static(__dirname + "/../lib/"),
connect.static(__dirname + "/../"),
connect.router(function (app) {
app.get('/', function (req, res) {
res.writeHead(200, {
"Cache-Control": "no-cache",
"Content-Type": "text/html"
});
res.end(doc);
app = connect()
.use(connect.static(__dirname + "/../lib/"))
.use(connect.static(__dirname + "/../"))
.use('/', function (req, res) {
res.writeHead(200, {
"Cache-Control": "max-age=0",
"Content-Type": "text/html"
});
})
);
res.end(doc);
});

//HACK: Openlayers causes weird stuff with the browser runner, so lets pop it off the list until we fix it
openlayers = conf.thirdpartyIncludes.pop();
if (openlayers !== "OpenLayers.js") {
//HACK: just a safe check to make sure our hack is still valid
console.log("HACK: we wanted to pop OpenLayers off but it looks like it wasn't the last one anymore");
}
//HACK: Openlayers causes weird stuff with the browser runner, so lets remove it from the list until we fix it
conf.thirdpartyIncludes = conf.thirdpartyIncludes.filter(function (filename) {
return !filename.match(/openlayers\.js/i);
});

modules = pack();

Expand Down
2 changes: 1 addition & 1 deletion build/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function _lintJS(files, done) {

function _lintCSS(files, done) {
var rules = JSON.parse(fs.readFileSync(__dirname + "/../.csslintrc", "utf-8")),
options = ["--rules=" + rules, "--format=compact"];
options = ["--errors=" + rules, "--format=compact", "--quiet"];
_spawn('csslint', files.concat(options), done);
}

Expand Down
2 changes: 1 addition & 1 deletion ext/chromium/controllers/Background.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ tinyHippos.Background = (function () {
},

isEnabled: function (url, enabledURIs) {
if (url.match(/enableripple=true/i)) {
if (url.match(/enableripple=/i)) {
_persistEnabled(url);
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion ext/chromium/controllers/Insertion.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
break;
case "disable":
localStorage.removeItem("tinyhippos-enabled-uri");
uri = uri.replace(/\?enableripple\=true/, "").replace(/\&enableripple\=true/, "");
//HACK: ummm .... I am sorry
uri = uri.replace(/enableripple=[^&]*[&]?/i, "").replace(/[\?&]*$/, "");
break;

default:
Expand Down
2 changes: 1 addition & 1 deletion ext/chromium/controllers/frame.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if (!document.getElementById("emulator-booting") && !document.getElementById("tinyhippos-injected")) {
var script = document.createElement("script");
script.id = "tinyhippos-injected";
script.src = chrome.extension.getURL("controllers/injector.js");
script.innerText = 'if (window.top.require) { window.top.require("ripple/bootstrap").inject(window, document); }';
document.documentElement.appendChild(script);
}
9 changes: 0 additions & 9 deletions ext/chromium/controllers/injector.js

This file was deleted.

6 changes: 6 additions & 0 deletions lib/ripple.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ var omgwtf = require('ripple/omgwtf'),
}
});

window.onbeforeunload = function () {
if (!window.tinyHipposReload) {
return "Are you sure you want to exit Ripple?";
}
};

jWorkflow.order(omgwtf.initialize, omgwtf)
.andThen(appcache.initialize, appcache)
.andThen(db.initialize, db)
Expand Down
2 changes: 1 addition & 1 deletion lib/ripple/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function _bootstrap() {
tinyHippos.boot(function () {
var uri = ui.registered('omnibar') ?
db.retrieve(_CURRENT_URL) || "about:blank" :
document.documentURI.replace(/enableripple=true[&]/i, "").replace(/[\?&]$/, "");
document.documentURI.replace(/enableripple=[^&]*[&]?/i, "").replace(/[\?&]*$/, "");

_post(uri);
delete tinyHippos.boot;
Expand Down
5 changes: 4 additions & 1 deletion lib/ripple/emulatorBridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,15 @@ module.exports = {
var marshal = function (obj, key) {
window[key] = win[key] = obj;
},
currentPlatform = platform.current(),
sandbox = {};

marshal(window.tinyHippos, "tinyHippos");
marshal(window.XMLHttpRequest, "XMLHttpRequest");

platform.current().initialize(win);
if (currentPlatform.initialize) {
currentPlatform.initialize(win);
}

builder.build(platform.current().objects).into(sandbox);
utils.forEach(sandbox, marshal);
Expand Down
49 changes: 31 additions & 18 deletions lib/ripple/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,30 @@ var _current,
spec = require('ripple/platform/spec'),
_self;

function _checkForDeprecatedPlatforms(replacement) {
if (!spec[_current.name] ||
!spec[_current.name][_current.version] ||
(spec[_current.name][_current.version] && !spec[_current.name][_current.version].objects)) {
_current = replacement;
db.saveObject("api-key", _current);
function _getRequestedPlatform() {
var requestedPlatform = null,
enableRippleArg = utils.queryString().enableripple,
platform;

if (enableRippleArg) {
enableRippleArg = enableRippleArg.split('-');
platform = spec.get(enableRippleArg[0], enableRippleArg[1]);
if (platform) {
requestedPlatform = { name: platform.id, version: platform.version };
}
}

return requestedPlatform;
}

function _validatePlatform(platform, defaultPlatform) {
if (!platform ||
!spec[platform.name] ||
!spec[platform.name][platform.version] ||
(spec[platform.name][platform.version] && !spec[platform.name][platform.version].objects)) {
return defaultPlatform;
}
return platform;
}

function _getPlatform() {
Expand All @@ -39,20 +56,16 @@ function _getPlatform() {
_self = {
initialize: function () {
var firstAvailablePlatform = utils.map(this.getList(), function (platform) {
return utils.map(platform, function (details, version) {
return {name: details.id, version: version};
})[0];
})[0];

_current = db.retrieveObject("api-key");
return utils.map(platform, function (details, version) {
return {name: details.id, version: version};
})[0];
})[0];

if (_current) {
_checkForDeprecatedPlatforms(firstAvailablePlatform);
} else {
_current = firstAvailablePlatform;
}
_current = _getRequestedPlatform() || db.retrieveObject("api-key") || firstAvailablePlatform;
_current = _validatePlatform(_current, firstAvailablePlatform);
db.saveObject("api-key", _current);

_console.prefix = _getPlatform().name;
_console.prefix = _current.name;
},

getList: function () {
Expand Down
27 changes: 27 additions & 0 deletions lib/ripple/platform/cordova/2.0.0/MediaError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2011 Research In Motion Limited.
*
* Licensed 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.
*/
var MediaError = function (code, msg) {
this.code = (code !== undefined ? code : null);
this.message = msg || "";
};

MediaError.MEDIA_ERR_NONE_ACTIVE = 0;
MediaError.MEDIA_ERR_ABORTED = 1;
MediaError.MEDIA_ERR_NETWORK = 2;
MediaError.MEDIA_ERR_DECODE = 3;
MediaError.MEDIA_ERR_NONE_SUPPORTED = 4;

module.exports = MediaError;
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ var _prompt = require('ripple/ui/plugins/exec-dialog');
module.exports = {
exec: function (success, fail, service, action, args) {
var emulator = {
"Network Status": require('ripple/platform/cordova/1.6/bridge/network'),
"NetworkStatus": require('ripple/platform/cordova/1.6/bridge/network'),
"Device": require('ripple/platform/cordova/1.6/bridge/device'),
"Contacts": require('ripple/platform/cordova/1.6/bridge/contacts'),
"Accelerometer": require('ripple/platform/cordova/1.6/bridge/accelerometer'),
"Compass": require('ripple/platform/cordova/1.6/bridge/compass'),
"Notification": require('ripple/platform/cordova/1.6/bridge/notification')
"Accelerometer": require('ripple/platform/cordova/2.0.0/bridge/accelerometer'),
"Compass": require('ripple/platform/cordova/2.0.0/bridge/compass'),
"Camera": require('ripple/platform/cordova/2.0.0/bridge/camera'),
"Capture": require('ripple/platform/cordova/2.0.0/bridge/capture'),
"Contacts": require('ripple/platform/cordova/2.0.0/bridge/contacts'),
"Debug Console": require('ripple/platform/cordova/2.0.0/bridge/console'),
"Device": require('ripple/platform/cordova/2.0.0/bridge/device'),
"File": require('ripple/platform/cordova/2.0.0/bridge/file'),
"Geolocation": require('ripple/platform/cordova/2.0.0/bridge/geolocation'),
"Media": require('ripple/platform/cordova/2.0.0/bridge/media'),
"Network Status": require('ripple/platform/cordova/2.0.0/bridge/network'),
"NetworkStatus": require('ripple/platform/cordova/2.0.0/bridge/network'),
"Notification": require('ripple/platform/cordova/2.0.0/bridge/notification')
};

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,33 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var utils = require('ripple/utils'),
event = require('ripple/event'),
_current = {x: 0, y: 0, z: 0, timestamp: (new Date()).getTime()};
var event = require('ripple/event'),
_success,
_error,
_current = {x: 0, y: 0, z: 0, timestamp: (new Date()).getTime()},
_interval;

event.on("AccelerometerInfoChangedEvent", function (accelerometerInfo) {
_current.x = accelerometerInfo.accelerationIncludingGravity.x / 9.8;
_current.y = accelerometerInfo.accelerationIncludingGravity.y / 9.8;
_current.z = accelerometerInfo.accelerationIncludingGravity.z / 9.8;
_current.x = accelerometerInfo.accelerationIncludingGravity.x;
_current.y = accelerometerInfo.accelerationIncludingGravity.y;
_current.z = accelerometerInfo.accelerationIncludingGravity.z;
_current.timestamp = (new Date()).getTime();
});

module.exports = {
getTimeout: function (success, error, args) {
return success && success(1);
start: function (success, error, args) {
_success = success;
_error = error;
// Possible HACK? update the timestamp of the last data to something current
_interval = window.setInterval(function () {
_current.timestamp = (new Date()).getTime();
_success(_current);
}, 50);
},

setTimeout: function (success, error, args) {
//do nothing
return success && success();
},

getAcceleration: function (success, error, args) {
// TODO: build facility to trigger onError() from emulator
// see pivotal item: https://www.pivotaltracker.com/story/show/7040343
success(utils.copy(_current));
stop: function () {
_success = null;
_error = null;
window.clearInterval(_interval);
}
};
29 changes: 29 additions & 0 deletions lib/ripple/platform/cordova/2.0.0/bridge/camera.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2011 Research In Motion Limited.
*
* Licensed 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.
*/
var camera = require('ripple/ui/plugins/camera'),
event = require('ripple/event');

module.exports = {
takePicture: function (success, error, args) {
event.once("captured-image", function (uri, file) {
success(uri);
});
camera.show();
},
cleanup: function (success, error, args) {
success();
}
};
28 changes: 28 additions & 0 deletions lib/ripple/platform/cordova/2.0.0/bridge/capture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2011 Research In Motion Limited.
*
* Licensed 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.
*/

var camera = require('ripple/ui/plugins/camera'),
event = require('ripple/event');

module.exports = {
captureImage: function (success, error, args) {
event.once("captured-image", function (uri, file) {
file.fullPath = uri;
success([file]);
});
camera.show();
}
};
Loading

0 comments on commit 1a16d8f

Please sign in to comment.