OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "examples/bitmap_uploader/bitmap_uploader.h" | 10 #include "examples/bitmap_uploader/bitmap_uploader.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 ServiceProviderPtr embedder_service_provider; | 43 ServiceProviderPtr embedder_service_provider; |
44 BitmapUploader bitmap_uploader; | 44 BitmapUploader bitmap_uploader; |
45 }; | 45 }; |
46 | 46 |
47 class EmbeddedApp | 47 class EmbeddedApp |
48 : public ApplicationDelegate, | 48 : public ApplicationDelegate, |
49 public ViewManagerDelegate, | 49 public ViewManagerDelegate, |
50 public ViewObserver { | 50 public ViewObserver { |
51 public: | 51 public: |
52 EmbeddedApp() : shell_(nullptr) { url::AddStandardScheme("mojo"); } | 52 EmbeddedApp() : shell_(nullptr) { url::AddStandardScheme("mojo"); } |
53 virtual ~EmbeddedApp() {} | 53 ~EmbeddedApp() override {} |
54 | 54 |
55 private: | 55 private: |
56 | 56 |
57 // Overridden from ApplicationDelegate: | 57 // Overridden from ApplicationDelegate: |
58 virtual void Initialize(ApplicationImpl* app) override { | 58 void Initialize(ApplicationImpl* app) override { |
59 shell_ = app->shell(); | 59 shell_ = app->shell(); |
60 view_manager_client_factory_.reset( | 60 view_manager_client_factory_.reset( |
61 new ViewManagerClientFactory(app->shell(), this)); | 61 new ViewManagerClientFactory(app->shell(), this)); |
62 } | 62 } |
63 | 63 |
64 virtual bool ConfigureIncomingConnection( | 64 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { |
65 ApplicationConnection* connection) override { | |
66 connection->AddService(view_manager_client_factory_.get()); | 65 connection->AddService(view_manager_client_factory_.get()); |
67 return true; | 66 return true; |
68 } | 67 } |
69 | 68 |
70 // Overridden from ViewManagerDelegate: | 69 // Overridden from ViewManagerDelegate: |
71 virtual void OnEmbed(View* root, | 70 void OnEmbed(View* root, |
72 InterfaceRequest<ServiceProvider> services, | 71 InterfaceRequest<ServiceProvider> services, |
73 ServiceProviderPtr exposed_services) override { | 72 ServiceProviderPtr exposed_services) override { |
74 root->AddObserver(this); | 73 root->AddObserver(this); |
75 Window* window = new Window(root, exposed_services.Pass(), shell_); | 74 Window* window = new Window(root, exposed_services.Pass(), shell_); |
76 windows_[root->id()] = window; | 75 windows_[root->id()] = window; |
77 window->bitmap_uploader.SetColor( | 76 window->bitmap_uploader.SetColor( |
78 kColors[next_color_++ % arraysize(kColors)]); | 77 kColors[next_color_++ % arraysize(kColors)]); |
79 } | 78 } |
80 virtual void OnViewManagerDisconnected(ViewManager* view_manager) override { | 79 void OnViewManagerDisconnected(ViewManager* view_manager) override { |
81 base::MessageLoop::current()->Quit(); | 80 base::MessageLoop::current()->Quit(); |
82 } | 81 } |
83 | 82 |
84 // Overridden from ViewObserver: | 83 // Overridden from ViewObserver: |
85 virtual void OnViewDestroyed(View* view) override { | 84 void OnViewDestroyed(View* view) override { |
86 DCHECK(windows_.find(view->id()) != windows_.end()); | 85 DCHECK(windows_.find(view->id()) != windows_.end()); |
87 windows_.erase(view->id()); | 86 windows_.erase(view->id()); |
88 } | 87 } |
89 virtual void OnViewInputEvent(View* view, const EventPtr& event) override { | 88 void OnViewInputEvent(View* view, const EventPtr& event) override { |
90 if (event->action == EVENT_TYPE_MOUSE_RELEASED) { | 89 if (event->action == EVENT_TYPE_MOUSE_RELEASED) { |
91 if (event->flags & EVENT_FLAGS_LEFT_MOUSE_BUTTON) { | 90 if (event->flags & EVENT_FLAGS_LEFT_MOUSE_BUTTON) { |
92 URLRequestPtr request(URLRequest::New()); | 91 URLRequestPtr request(URLRequest::New()); |
93 request->url = "http://www.aaronboodman.com/z_dropbox/test.html"; | 92 request->url = "http://www.aaronboodman.com/z_dropbox/test.html"; |
94 NavigatorHostPtr navigator_host; | 93 NavigatorHostPtr navigator_host; |
95 ConnectToService(windows_[view->id()]->embedder_service_provider.get(), | 94 ConnectToService(windows_[view->id()]->embedder_service_provider.get(), |
96 &navigator_host); | 95 &navigator_host); |
97 navigator_host->RequestNavigate(TARGET_SOURCE_NODE, request.Pass()); | 96 navigator_host->RequestNavigate(TARGET_SOURCE_NODE, request.Pass()); |
98 } | 97 } |
99 } | 98 } |
(...skipping 10 matching lines...) Expand all Loading... |
110 DISALLOW_COPY_AND_ASSIGN(EmbeddedApp); | 109 DISALLOW_COPY_AND_ASSIGN(EmbeddedApp); |
111 }; | 110 }; |
112 | 111 |
113 } // namespace examples | 112 } // namespace examples |
114 } // namespace mojo | 113 } // namespace mojo |
115 | 114 |
116 MojoResult MojoMain(MojoHandle shell_handle) { | 115 MojoResult MojoMain(MojoHandle shell_handle) { |
117 mojo::ApplicationRunnerChromium runner(new mojo::examples::EmbeddedApp); | 116 mojo::ApplicationRunnerChromium runner(new mojo::examples::EmbeddedApp); |
118 return runner.Run(shell_handle); | 117 return runner.Run(shell_handle); |
119 } | 118 } |
OLD | NEW |