Merge "Avoid memory leak by only registering callback while attached to window." into jb-dev