/* * pmrpc 0.7.1 - Inter-widget remote procedure call library based on HTML5 * postMessage API and JSON-RPC. https://github.com/izuzak/pmrpc * * Copyright 2012 Ivan Zuzak, Marko Ivankovic * * 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. */ pmrpc = self.pmrpc = function() { // check if JSON library is available if (typeof JSON === "undefined" || typeof JSON.stringify === "undefined" || typeof JSON.parse === "undefined") { throw "pmrpc requires the JSON library"; } // TODO: make "contextType" private variable // check if postMessage APIs are available if (typeof this.postMessage === "undefined" && // window or worker typeof this.onconnect === "undefined") { // shared worker throw "pmrpc requires the HTML5 cross-document messaging and worker APIs"; } // Generates a version 4 UUID function generateUUID() { var uuid = [], nineteen = "89AB", hex = "0123456789ABCDEF"; for (var i=0; i<36; i++) { uuid[i] = hex[Math.floor(Math.random() * 16)]; } uuid[14] = '4'; uuid[19] = nineteen[Math.floor(Math.random() * 4)]; uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'; return uuid.join(''); } // Checks whether a domain satisfies the access control list. The access // control list has a whitelist and a blacklist. In order to satisfy the acl, // the domain must be on the whitelist, and must not be on the blacklist. function checkACL(accessControlList, origin) { var aclWhitelist = accessControlList.whitelist; var aclBlacklist = accessControlList.blacklist; var isWhitelisted = false; var isBlacklisted = false; for (var i=0; i