Sockets secure implementations

Rebased on `master`.
Unless this is really the code used by desktop, you should use a different code for each error case. You probably also should use: https://github.com/MobileChromeApps/mobile-chrome-apps/blob/5c52c0f47514af3c744f80115818414e9df5f52d/chrome-cordova/plugins/chrome-common/errors.js
to set chrome.runtime.lastError to a string message saying what went wrong.