[Extension] Added application id for permission checking calls.

The permission checking/registering was issued from extension process
but we don't know where it comes from, i.e. from which application.
In the beginning, we take the app id from the running app list
(simply pick the first one) which is just not right when we're going
to support multiple apps.
So the right way is to bind each extension process with its
corresponding app id, and then whenever there is a permission check
we know where it comes from.
Merge pull request #1612 from mbbill/appid

[Extension] Added application id for permission checking calls.