Permalink
Browse files

Init commit of samples

  • Loading branch information...
1 parent 7f6df08 commit c6422f6acb55dc8a8b1be25e9525778c01028439 @ebidel ebidel committed Jun 27, 2012
Showing 794 changed files with 126,665 additions and 0 deletions.
View
@@ -0,0 +1,4 @@
+analytics
+=========
+This example demonstrates how to include support for Google Analytics in your
+packaged app. You'll need to modify example.js to include real GA credentials.
@@ -0,0 +1,9 @@
+<!doctype html>
+<html>
+ <head>
+ <script type="text/javascript" src="https://ssl.google-analytics.com/u/ga_debug.js"></script>
+ <script type="text/javascript" src="embedded_ga.js"></script>
+ </head>
+ <body>
+ </body>
+</html>
View
@@ -0,0 +1,27 @@
+var cookies = {};
+document.__defineSetter__('cookie', function(value) {
+ if (value.indexOf(';') < 0) {
+ return;
+ }
+
+ var cookie_name = value.substring(0, value.indexOf('='));
+ var cookie_value = value.substring(cookie_name.length + 1, value.indexOf(';'));
+ cookies[cookie_name] = cookie_value;
+});
+
+document.__defineGetter__('cookie', function() {
+ var result = [];
+ for (var cookie in cookies) {
+ result.push(cookie + '=' + cookies[cookie]);
+ }
+ return result.join('; ');
+});
+
+history.__defineGetter__('length', function() {
+ return 0;
+});
+
+var _gaq = _gaq || [];
+window.addEventListener('message', function(message) {
+ _gaq.push(message.data);
+});
@@ -0,0 +1,3 @@
+#embedded_ga {
+ display: none;
+}
@@ -0,0 +1,11 @@
+<!doctype html>
+<html>
+ <head>
+ <meta http-equiv="X-WebKit-CSP" content="script-src 'self' chrome-extension: https://ssl.google-analytics.com; img-src 'self' chrome-extension: http://www.google-analytics.com"/>
+ <script type="text/javascript" src="https://ssl.google-analytics.com/ga.js"></script>
+ <script type="text/javascript" src="embedded_ga.js"></script>
+ </head>
+ <body>
+ You've forgotten to include embedded_ga_host.css, haven't you?
+ </body>
+</html>
@@ -0,0 +1,29 @@
+(function(namespace) {
+ function Proxy(bridge) {
+ this.bridge = bridge;
+ }
+
+ Proxy.prototype.push = function(values) {
+ this.bridge.postMessage(values, '*');
+ }
+
+ function installProxy() {
+ var bridge = document.getElementById("embedded_ga").contentWindow;
+ if (!bridge) {
+ console.log("Cannot find embedded_ga element.");
+ return;
+ }
+
+ var earlyEvents = [];
+ if (namespace._gaq != undefined) {
+ earlyEvents = namespace._gaq;
+ }
+
+ namespace._gaq = new Proxy(bridge);
+ for (var i in earlyEvents) {
+ namespace._gaq.push(earlyEvents[i]);
+ }
+ }
+
+ window.addEventListener('load', installProxy);
+})(window);
View
@@ -0,0 +1,6 @@
+console.log("You'll need to put valid credentials into example.js");
+
+var _gaq = _gaq || [];
+_gaq.push(['_setAccount', 'UA-XXXXXX-X']);
+_gaq.push(['_setDomainName', 'example.com']);
+_gaq.push(['_trackPageview']);
View
@@ -0,0 +1,6 @@
+chrome.experimental.app.onLaunched.addListener(function() {
+ chrome.appWindow.create('main.html', {
+ width: 680,
+ height: 480
+ });
+});
View
@@ -0,0 +1,10 @@
+<html>
+ <head>
+ <script type="text/javascript" src="example.js"></script>
+ <script type="text/javascript" src="embedded_ga_host.js"></script>
+ <link rel="stylesheet" media="all" href="embedded_ga_host.css"></link>
+ </head>
+ <body>
+ <iframe id="embedded_ga" seamless="seamless" src="embedded_ga_host.html"></iframe>
+ </body>
+</html>
View
@@ -0,0 +1,14 @@
+{
+ "name": "Google Analytics Sample",
+ "version": "1",
+ "manifest_version": 2,
+ "app": {
+ "background": {
+ "scripts": ["launch.js"]
+ }
+ },
+ "permissions": ["experimental"],
+ "sandbox": {
+ "pages": ["embedded_ga_host.html"]
+ }
+}
View
@@ -0,0 +1,18 @@
+- Basic Foursquare client implemented as a platform apps.
+- Just displays recent checkins.
+- Uses the storage API to persist the auth token locally
+- Uses the identity API to do the OAuth dance in a separate window
+- Uses the geolocation API to pass in the current location to the API
+
+The app is listed in the (internal) Chrome Web Store at:
+https://chrome.google.com/webstore/a/google.com/detail/hgdbciackkmabepeodkkdipmbjnfojmm
+
+When running it unpacked, it will normally have a different ID (the unpacked
+extension ID is a hash of the path on disk). However, this will result in the
+auth API not working, since the redirect URL will be different. To force the
+unpacked app to have the same ID, add this key and value to manifest.json:
+
+"key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDnyZBBnfu+qNi1x5C0YKIob4ACrA84HdMArTGobttMHIxM2Z6aLshFmoKZa/pbyQS6D5yNywr4KM/llWiY2aV2puIflUxRT8SjjPehswCvm6eWQM+r3mB755m48x+diDl8URJsX4AJ3pQHnKWEvitZcuBh0GTfsLzKU/BfHEaH7QIDAQAB"
+(this is a base 64 encoded version of the store app's public key)
+
+The key must be removed before uploading it to the store.
View
@@ -0,0 +1,6 @@
+chrome.experimental.app.onLaunched.addListener(function() {
+ chrome.appWindow.create('main.html', {
+ width: 300,
+ height: 600
+ });
+});
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -0,0 +1,91 @@
+var foursquare = {};
+
+(function(api) {
+ // See "Pure AJAX application" from
+ // https://developer.foursquare.com/overview/auth
+ var ACCESS_TOKEN_PREFIX = '#access_token=';
+
+ var storage = chrome.storage.local;
+ var ACCESS_TOKEN_STORAGE_KEY = 'foursquare-access-token';
+
+ var getAccessToken = function(callback) {
+ storage.get(ACCESS_TOKEN_STORAGE_KEY, function(items) {
+ callback(items[ACCESS_TOKEN_STORAGE_KEY]);
+ });
+ }
+
+ var setAccessToken = function(accessToken, callback) {
+ var items = {};
+ items[ACCESS_TOKEN_STORAGE_KEY] = accessToken;
+ storage.set(items, callback);
+ }
+
+ var clearAccessToken = function(callback) {
+ storage.remove(ACCESS_TOKEN_STORAGE_KEY, callback);
+ }
+
+ // Tokens state is not exposed via the API
+ api.isSignedIn = function(callback) {
+ getAccessToken(function(accessToken) {
+ callback(!!accessToken);
+ });
+ };
+ api.signIn = function(appId, clientId, successCallback, errorCallback) {
+ var redirectUrl = 'https://' + appId + '.chromiumapp.org/';
+ var authUrl = 'https://foursquare.com/oauth2/authorize?' +
+ 'client_id=' + clientId + '&' +
+ 'response_type=token&' +
+ 'redirect_uri=' + encodeURIComponent(redirectUrl);
+ chrome.experimental.identity.launchWebAuthFlow(
+ {url: authUrl},
+ function(responseUrl) {
+ if (chrome.extension.lastError) {
+ errorCallback(chrome.extension.lastError.message);
+ return;
+ }
+
+ var accessTokenStart = responseUrl.indexOf(ACCESS_TOKEN_PREFIX);
+
+ if (!accessTokenStart) {
+ errorCallback('Unexpected responseUrl: ' + responseUrl);
+ return;
+ }
+
+ var accessToken = responseUrl.substring(
+ accessTokenStart + ACCESS_TOKEN_PREFIX.length);
+
+ setAccessToken(accessToken, successCallback);
+ });
+ };
+ api.signOut = function(callback) {
+ clearAccessToken(callback);
+ };
+
+ var apiMethod = function(
+ path, postData, params, successCallback, errorCallback) {
+ getAccessToken(function(accessToken) {
+ var xhr = new XMLHttpRequest();
+ // TODO(mihaip): use xhr.responseType = 'json' once it's supported.
+ xhr.onload = function() {
+ successCallback(JSON.parse(xhr.responseText).response);
+ }
+ xhr.onerror = function() {
+ errorCallback(xhr.status, xhr.statusText, JSON.parse(xhr.responseText));
+ }
+
+ var encodedParams = [];
+ for (var paramName in params) {
+ encodedParams.push(encodeURIComponent(paramName) + '=' +
+ encodeURIComponent(params[paramName]));
+ }
+ xhr.open(
+ 'GET',
+ 'https://api.foursquare.com/v2/' + path + '?oauth_token=' +
+ encodeURIComponent(accessToken) + '&' + encodedParams.join('&'),
+ true);
+ xhr.send(null);
+ });
+ }
+
+ api.getRecentCheckins = apiMethod.bind(api, 'checkins/recent', undefined);
+})(foursquare);
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -0,0 +1 @@
+https://hgdbciackkmabepeodkkdipmbjnfojmm.chromiumapp.org/#access_token=1QUH0ZHBV3DYYQVS152MWKRAXQERS4ENTRLOQRFD2BN3ADOA
View
@@ -0,0 +1,14 @@
+function ImageLoader(url) {
+ this.url_ = url;
+}
+
+ImageLoader.prototype.loadInto = function(imageNode) {
+ var xhr = new XMLHttpRequest();
+ xhr.responseType = 'blob';
+ xhr.onload = function() {
+ // TODO(mihaip): cache the response into a local filesystem.
+ imageNode.src = window.webkitURL.createObjectURL(xhr.response);
+ }
+ xhr.open('GET', this.url_, true);
+ xhr.send();
+};
View
@@ -0,0 +1,119 @@
+<html>
+ <head>
+ <title>Foursquare Client</title>
+ <style>
+ body {
+ background: #fff;
+ font-family: Helvetica;
+ font-size: 12px;
+ padding: 0;
+ margin: 0;
+ overflow: hidden;
+ }
+
+ .container {
+ width: 100%;
+ height: 100%;
+ position: absolute;
+ top: 0;
+ opacity: 0;
+ -webkit-transition: opacity .2s;
+ }
+
+ .signed-in #signed-in,
+ .signed-out #signed-out {
+ opacity: 1;
+ }
+
+ .signed-in #signed-out,
+ .signed-out #signed-in {
+ display: none;
+ }
+
+ .header {
+ background: #eee;
+ border-bottom: solid 1px #ccc;
+ height: 23px;
+ padding: 3px;
+ }
+
+ .scrollable {
+ width: 300px;
+ height: -webkit-calc(100% - 30px);
+ overflow: auto;
+ }
+
+ #checkins {
+ list-style-type: none;
+ padding: 0;
+ margin: 0;
+ }
+
+ .checkin {
+ padding: 2px;
+ border-bottom: solid 1px #ccc;
+ overflow: hidden;
+ position: relative;
+ }
+
+ .checkin h3 {
+ margin: 0;
+ font-size: 14px;
+ line-height: 20px;
+ height: 20px;
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ }
+
+ .checkin .photo {
+ width: 40px;
+ height: 40px;
+ padding: 3px;
+ float: left;
+ }
+
+ .checkin .mayor-overlay {
+ position: absolute;
+ top: 0;
+ left: 0;
+ width: 18px;
+ height: 17px;
+ }
+
+ .checkin .location {
+ color: #999;
+ height: 14px;
+ overflow: hidden;
+ }
+
+ .checkin .timestamp {
+ color: #999;
+ font-size: 10px;
+ height: 12px;
+ overflow: hidden;
+ }
+ </style>
+ </head>
+ <body>
+ <div id="signed-in" class="container">
+ <div class="header">
+ <button id="sign-out-button">Sign out</button>
+ </div>
+
+ <div class="scrollable">
+ <ol id="checkins"></ol>
+ </div>
+ </div>
+
+ <div id="signed-out" class="container">
+ <div class="header">
+ <button id="sign-in-button">Sign in with Foursquare</button>
+ </div>
+ </div>
+
+ <script src="loader.js"></script>
+ <script src="foursquare.js"></script>
+ <script src="main.js"></script>
+ </body>
+</html>
Oops, something went wrong.

0 comments on commit c6422f6

Please sign in to comment.