| 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 <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "base/macros.h" |
| 7 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 9 #include "base/strings/string_tokenizer.h" | 10 #include "base/strings/string_tokenizer.h" |
| 10 #include "mojo/application/application_runner_chromium.h" | 11 #include "mojo/application/application_runner_chromium.h" |
| 11 #include "mojo/examples/media_viewer/media_viewer.mojom.h" | 12 #include "mojo/examples/media_viewer/media_viewer.mojom.h" |
| 12 #include "mojo/public/c/system/main.h" | 13 #include "mojo/public/c/system/main.h" |
| 13 #include "mojo/public/cpp/application/application_connection.h" | 14 #include "mojo/public/cpp/application/application_connection.h" |
| 14 #include "mojo/public/cpp/application/application_delegate.h" | 15 #include "mojo/public/cpp/application/application_delegate.h" |
| 15 #include "mojo/public/cpp/application/application_impl.h" | 16 #include "mojo/public/cpp/application/application_impl.h" |
| 16 #include "mojo/public/cpp/application/interface_factory_impl.h" | 17 #include "mojo/public/cpp/application/interface_factory_impl.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 68 |
| 68 virtual ~PNGView() { | 69 virtual ~PNGView() { |
| 69 if (root_) | 70 if (root_) |
| 70 root_->RemoveObserver(this); | 71 root_->RemoveObserver(this); |
| 71 } | 72 } |
| 72 | 73 |
| 73 // Overridden from ViewManagerDelegate: | 74 // Overridden from ViewManagerDelegate: |
| 74 virtual void OnEmbed(ViewManager* view_manager, | 75 virtual void OnEmbed(ViewManager* view_manager, |
| 75 View* root, | 76 View* root, |
| 76 ServiceProviderImpl* exported_services, | 77 ServiceProviderImpl* exported_services, |
| 77 scoped_ptr<ServiceProvider> imported_services) OVERRIDE { | 78 scoped_ptr<ServiceProvider> imported_services) override { |
| 78 root_ = root; | 79 root_ = root; |
| 79 root_->AddObserver(this); | 80 root_->AddObserver(this); |
| 80 root_->SetColor(SK_ColorGRAY); | 81 root_->SetColor(SK_ColorGRAY); |
| 81 if (!bitmap_.isNull()) | 82 if (!bitmap_.isNull()) |
| 82 DrawBitmap(); | 83 DrawBitmap(); |
| 83 } | 84 } |
| 84 | 85 |
| 85 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE { | 86 virtual void OnViewManagerDisconnected(ViewManager* view_manager) override { |
| 86 // TODO(aa): Need to figure out how shutdown works. | 87 // TODO(aa): Need to figure out how shutdown works. |
| 87 } | 88 } |
| 88 | 89 |
| 89 // Overridden from ViewObserver: | 90 // Overridden from ViewObserver: |
| 90 virtual void OnViewBoundsChanged(View* view, | 91 virtual void OnViewBoundsChanged(View* view, |
| 91 const gfx::Rect& old_bounds, | 92 const gfx::Rect& old_bounds, |
| 92 const gfx::Rect& new_bounds) OVERRIDE { | 93 const gfx::Rect& new_bounds) override { |
| 93 DCHECK_EQ(view, root_); | 94 DCHECK_EQ(view, root_); |
| 94 DrawBitmap(); | 95 DrawBitmap(); |
| 95 } | 96 } |
| 96 | 97 |
| 97 virtual void OnViewDestroyed(View* view) OVERRIDE { | 98 virtual void OnViewDestroyed(View* view) override { |
| 98 DCHECK_EQ(view, root_); | 99 DCHECK_EQ(view, root_); |
| 99 delete this; | 100 delete this; |
| 100 } | 101 } |
| 101 | 102 |
| 102 void DecodePNG(URLResponsePtr response) { | 103 void DecodePNG(URLResponsePtr response) { |
| 103 int content_length = GetContentLength(response->headers); | 104 int content_length = GetContentLength(response->headers); |
| 104 scoped_ptr<unsigned char[]> data(new unsigned char[content_length]); | 105 scoped_ptr<unsigned char[]> data(new unsigned char[content_length]); |
| 105 unsigned char* buf = data.get(); | 106 unsigned char* buf = data.get(); |
| 106 uint32_t bytes_remaining = content_length; | 107 uint32_t bytes_remaining = content_length; |
| 107 uint32_t num_bytes = bytes_remaining; | 108 uint32_t num_bytes = bytes_remaining; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 class ContentHandlerImpl : public InterfaceImpl<ContentHandler> { | 189 class ContentHandlerImpl : public InterfaceImpl<ContentHandler> { |
| 189 public: | 190 public: |
| 190 explicit ContentHandlerImpl(Shell* shell) : shell_(shell) {} | 191 explicit ContentHandlerImpl(Shell* shell) : shell_(shell) {} |
| 191 virtual ~ContentHandlerImpl() {} | 192 virtual ~ContentHandlerImpl() {} |
| 192 | 193 |
| 193 private: | 194 private: |
| 194 // Overridden from ContentHandler: | 195 // Overridden from ContentHandler: |
| 195 virtual void OnConnect( | 196 virtual void OnConnect( |
| 196 const mojo::String& url, | 197 const mojo::String& url, |
| 197 URLResponsePtr response, | 198 URLResponsePtr response, |
| 198 InterfaceRequest<ServiceProvider> service_provider) OVERRIDE { | 199 InterfaceRequest<ServiceProvider> service_provider) override { |
| 199 ServiceProviderImpl* exported_services = new ServiceProviderImpl(); | 200 ServiceProviderImpl* exported_services = new ServiceProviderImpl(); |
| 200 BindToRequest(exported_services, &service_provider); | 201 BindToRequest(exported_services, &service_provider); |
| 201 scoped_ptr<ServiceProvider> remote( | 202 scoped_ptr<ServiceProvider> remote( |
| 202 exported_services->CreateRemoteServiceProvider()); | 203 exported_services->CreateRemoteServiceProvider()); |
| 203 PNGView::Spawn(response.Pass(), exported_services, remote.Pass(), shell_); | 204 PNGView::Spawn(response.Pass(), exported_services, remote.Pass(), shell_); |
| 204 } | 205 } |
| 205 | 206 |
| 206 Shell* shell_; | 207 Shell* shell_; |
| 207 | 208 |
| 208 DISALLOW_COPY_AND_ASSIGN(ContentHandlerImpl); | 209 DISALLOW_COPY_AND_ASSIGN(ContentHandlerImpl); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 232 DISALLOW_COPY_AND_ASSIGN(PNGViewer); | 233 DISALLOW_COPY_AND_ASSIGN(PNGViewer); |
| 233 }; | 234 }; |
| 234 | 235 |
| 235 } // namespace examples | 236 } // namespace examples |
| 236 } // namespace mojo | 237 } // namespace mojo |
| 237 | 238 |
| 238 MojoResult MojoMain(MojoHandle shell_handle) { | 239 MojoResult MojoMain(MojoHandle shell_handle) { |
| 239 mojo::ApplicationRunnerChromium runner(new mojo::examples::PNGViewer); | 240 mojo::ApplicationRunnerChromium runner(new mojo::examples::PNGViewer); |
| 240 return runner.Run(shell_handle); | 241 return runner.Run(shell_handle); |
| 241 } | 242 } |
| OLD | NEW |