Whitelist origins depending on domain/debug setting (bug 1075515)

Also, add loop dev URL on dev or if debug is True.
Merge pull request #2614 from diox/iframe-perms-refactor

Whitelist origins depending on domain/debug setting (bug 1075515)