mirror of
https://github.com/GoogleChrome/chrome-extensions-samples.git
synced 2026-04-02 14:29:37 +07:00
* Remove docs folder. This was a redirect from a GitHub pages site that does not appear to be in use. * Rename api folder to api-samples. * Move examples to functional-samples folder. * Move cookbook sample to functional-samples. * Move tutorials to functional-samples folder. * Move mv2 and apps folders to _archive. * Rename tools folder to .repo. * Move reference folder to functional-samples. * Update README. Update README with new relative links for reorg. * Update README.md Co-authored-by: amysteamdev <37001393+AmySteam@users.noreply.github.com> --------- Co-authored-by: amysteamdev <37001393+AmySteam@users.noreply.github.com>
59 lines
1.4 KiB
JavaScript
Executable File
59 lines
1.4 KiB
JavaScript
Executable File
(function(window) {
|
|
|
|
var ORIGIN_ = location.protocol + '//' + location.host;
|
|
|
|
function SlideController() {
|
|
this.popup = null;
|
|
this.isPopup = window.opener;
|
|
|
|
if (this.setupDone()) {
|
|
window.addEventListener('message', this.onMessage_.bind(this), false);
|
|
}
|
|
}
|
|
|
|
SlideController.prototype.setupDone = function() {
|
|
return true;
|
|
}
|
|
|
|
SlideController.prototype.onMessage_ = function(e) {
|
|
var data = e.data;
|
|
|
|
// Restrict messages to being from this origin. Allow local developmet
|
|
// from file:// though.
|
|
// TODO: It would be dope if FF implemented location.origin!
|
|
if (e.origin != ORIGIN_ && ORIGIN_.indexOf('file://') != 0) {
|
|
alert('Someone tried to postMessage from an unknown origin');
|
|
return;
|
|
}
|
|
|
|
// if (e.source.location.hostname != 'localhost') {
|
|
// alert('Someone tried to postMessage from an unknown origin');
|
|
// return;
|
|
// }
|
|
|
|
if ('keyCode' in data) {
|
|
var evt = document.createEvent('Event');
|
|
evt.initEvent('keydown', true, true);
|
|
evt.keyCode = data.keyCode;
|
|
document.dispatchEvent(evt);
|
|
}
|
|
};
|
|
|
|
SlideController.prototype.sendMsg = function(msg) {
|
|
// // Send message to popup window.
|
|
// if (this.popup) {
|
|
// this.popup.postMessage(msg, ORIGIN_);
|
|
// }
|
|
|
|
// Send message to main window.
|
|
if (this.isPopup) {
|
|
// TODO: It would be dope if FF implemented location.origin.
|
|
window.opener.postMessage(msg, '*');
|
|
}
|
|
};
|
|
|
|
window.SlideController = SlideController;
|
|
|
|
})(window);
|
|
|