Skip to content
This repository has been archived by the owner on Oct 2, 2018. It is now read-only.

Commit

Permalink
Merge pull request #347 from airbornos/develop
Browse files Browse the repository at this point in the history
Fix for Firefox Marketplace
  • Loading branch information
ferndot committed Dec 12, 2015
2 parents b74a98b + b0c6202 commit 31b8592
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 1 deletion.
3 changes: 3 additions & 0 deletions builder/build
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ cp -r ../modules ../build
cp -r ../locales ../build
cp ../manifest.webapp ../build

mkdir -p ../build/scripts/cloud
mkdir -p ../build/scripts/lib
mkdir -p ../build/scripts/parsers/odt.js/lib
cp ../scripts/messages.js ../build/scripts
cp ../scripts/cloud/dropbox.min.js ../build/scripts/cloud
cp ../scripts/cloud/dropbox_authdriver_firefoxos_receiver.js ../build/scripts/cloud
cp ../scripts/lib/jszip.js ../build/scripts/lib
cp ../scripts/lib/jszip-deflate.js ../build/scripts/lib
cp ../scripts/lib/jszip-inflate.js ../build/scripts/lib
Expand Down
7 changes: 6 additions & 1 deletion manifest.webapp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"version": "0.5",
"type": "privileged",
"launch_path": "/index.html",
"origin": "app://firetext",
"developer": {
"name": "Airborn OS",
"url": "https://www.airbornos.com/"
Expand Down Expand Up @@ -94,6 +93,12 @@
"access": "readwrite"
}
},
"redirects": [
{
"from": "https://firetext-server.herokuapp.com/auth/dropbox/oauth2/",
"to": "/modules/oauth2/index.html"
}
],
"activities": {
"open": {
"href": "./index.html",
Expand Down
20 changes: 20 additions & 0 deletions modules/oauth2/dropbox.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions modules/oauth2/dropbox_oauth2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Launch OAuth Receiver with internal app flag
Dropbox.AuthDriver.FFOSPopup.oauthReceiver(true);
35 changes: 35 additions & 0 deletions modules/oauth2/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Dropbox Auth</title>
<script src="../../scripts/cloud/dropbox.min.js"></script>
<script src="../../scripts/cloud/dropbox_authdriver_firefoxos_receiver.js"></script>
<script src="dropbox_oauth2.js"></script>
<style>
body, html {
color: #515151;
text-shadow: 0 0 2px white;
background: #ffffff;
font-size: 1em;
}
.container {
text-align: center;
padding: 1rem;
}
h3 {
font-size: 2rem;
font-weight: bold;
font-family: sans-serif;
}
</style>
</head>
<body>
<div class="container">
<img src="dropbox.svg" alt="Dropbox Logo" width="150" height="150" />
<h3 style="margin: 0;">You can now use Firetext with Dropbox!</h3>
<p><i>This window should close automatically in a few seconds...</i></p>
</div>
</body>
</html>
78 changes: 78 additions & 0 deletions scripts/cloud/dropbox_authdriver_firefoxos_receiver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Firefox OS Popup Dropbox Receiver
* Copyright (C) Codexa Organization.
*/

if (Dropbox && Dropbox.AuthDriver) {
Dropbox.AuthDriver.FFOSPopup = (function(superClass) {
var allowedOrigins = ["https://codexa.github.io", "http://firetext.codexa.bugs3.com", "localhost"];

function FFOSPopup() {
}

FFOSPopup.locationOrigin = function(location) {
var match;
match = /^(file:\/\/[^\?\#]*)/.exec(location);
if (match) {
return "file";
}

match = /^([^\:]+\:\/\/localhost(:[0-9]*){0,1}([\/]|$))/.exec(location);
if (match) {
return "localhost";
}

match = /^([^\:]+\:\/\/[^\/\?\#]*)/.exec(location);
if (match) {
return match[1];
}
return location;
};

FFOSPopup.oauthReceiver = function(inApp) {
window.addEventListener('load', function() {
var frameError, getOriginMessage, ieError, message, opener, pageUrl, receiveMessage;
pageUrl = window.location.href;
getOriginMessage = JSON.stringify({
_dropboxjs_needs_origin: true
});
message = JSON.stringify({
_dropboxjs_oauth_info: pageUrl
});
Dropbox.AuthDriver.BrowserBase.cleanupLocation();
opener = window.opener;
if (window.parent !== window.top) {
opener || (opener = window.parent);
}
if (opener) {
receiveMessage = function(e) {
if (e.source === opener &&
(allowedOrigins.indexOf(Dropbox.AuthDriver.FFOSPopup.locationOrigin(e.origin)) !== -1 ||
inApp)) {
opener.postMessage(message, e.origin);
window.close();
}
};
window.addEventListener('message', receiveMessage, false);
try {
opener.postMessage(getOriginMessage, "*");
} catch (_error) {
ieError = _error;
}
try {
opener.Dropbox.AuthDriver.FFOSPopup.onMessage.dispatch(message);
window.close();
} catch (_error) {
frameError = _error;
}
}
});
};

FFOSPopup.onMessage = new Dropbox.Util.EventSource;

return FFOSPopup;
})(Dropbox.AuthDriver.BrowserBase);
} else {
console.log("Dropbox.js is not present.");
}

0 comments on commit 31b8592

Please sign in to comment.