Refactors event dispatching of NativeViewport into its own interface

This way the WindowManager can handle the event directly. New flow is
for the ViewManager to request the NativeViewportEventDispatcher from
the WindowManager and connect said NativeViewportEventDispatcher to
the NativeViewport.

BUG=none
TEST=none
R=ben@chromium.org

Review URL: https://codereview.chromium.org/685013002
diff --git a/examples/sample_app/sample_app.cc b/examples/sample_app/sample_app.cc
index 26eac51..afc80fa 100644
--- a/examples/sample_app/sample_app.cc
+++ b/examples/sample_app/sample_app.cc
@@ -21,20 +21,24 @@
 
 namespace examples {
 
-class SampleApp : public mojo::ApplicationDelegate,
-                  public mojo::NativeViewportClient {
+class SampleApp
+    : public mojo::ApplicationDelegate,
+      public mojo::NativeViewportClient,
+      public mojo::InterfaceImpl<mojo::NativeViewportEventDispatcher> {
  public:
   SampleApp() : weak_factory_(this) {}
 
-  virtual ~SampleApp() {
+  ~SampleApp() override {
     // TODO(darin): Fix shutdown so we don't need to leak this.
     mojo_ignore_result(gles2_client_.release());
   }
 
-  virtual void Initialize(mojo::ApplicationImpl* app) override {
+  void Initialize(mojo::ApplicationImpl* app) override {
     app->ConnectToService("mojo:native_viewport_service", &viewport_);
     viewport_.set_client(this);
 
+    SetEventDispatcher();
+
     // TODO(jamesr): Should be mojo:gpu_service
     app->ConnectToService("mojo:native_viewport_service", &gpu_service_);
 
@@ -47,16 +51,16 @@
     viewport_->Show();
   }
 
-  virtual void OnDestroyed() override { mojo::RunLoop::current()->Quit(); }
+  void OnDestroyed() override { mojo::RunLoop::current()->Quit(); }
 
-  virtual void OnSizeChanged(mojo::SizePtr size) override {
+  void OnSizeChanged(mojo::SizePtr size) override {
     assert(size);
     if (gles2_client_)
       gles2_client_->SetSize(*size);
   }
 
-  virtual void OnEvent(mojo::EventPtr event,
-                       const mojo::Callback<void()>& callback) override {
+  void OnEvent(mojo::EventPtr event,
+               const mojo::Callback<void()>& callback) override {
     assert(event);
     if (event->location_data && event->location_data->in_view_location)
       gles2_client_->HandleInputEvent(*event);
@@ -64,6 +68,12 @@
   }
 
  private:
+  void SetEventDispatcher() {
+    mojo::NativeViewportEventDispatcherPtr proxy;
+    mojo::WeakBindToProxy(this, &proxy);
+    viewport_->SetEventDispatcher(proxy.Pass());
+  }
+
   void OnCreatedNativeViewport(uint64_t native_viewport_id) {
     mojo::SizePtr size = mojo::Size::New();
     size->width = 800;