| 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 "mojo/public/cpp/application/application.h" | 5 #include "mojo/public/cpp/application/application.h" |
| 6 #include "mojo/services/navigation/navigation.mojom.h" |
| 6 #include "mojo/services/public/cpp/view_manager/view.h" | 7 #include "mojo/services/public/cpp/view_manager/view.h" |
| 7 #include "mojo/services/public/cpp/view_manager/view_manager.h" | 8 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
| 8 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 9 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
| 9 #include "mojo/services/public/cpp/view_manager/view_manager_types.h" | 10 #include "mojo/services/public/cpp/view_manager/view_manager_types.h" |
| 10 #include "mojo/services/public/cpp/view_manager/view_tree_node.h" | 11 #include "mojo/services/public/cpp/view_manager/view_tree_node.h" |
| 11 #include "mojo/services/public/interfaces/launcher/launcher.mojom.h" | |
| 12 | 12 |
| 13 namespace mojo { | 13 namespace mojo { |
| 14 namespace examples { | 14 namespace examples { |
| 15 | 15 |
| 16 class HTMLViewer; | 16 class HTMLViewer; |
| 17 | 17 |
| 18 class LaunchableConnection : public InterfaceImpl<launcher::Launchable> { | 18 class NavigatorImpl : public InterfaceImpl<navigation::Navigator> { |
| 19 public: | 19 public: |
| 20 explicit LaunchableConnection(HTMLViewer* viewer) : viewer_(viewer) {} | 20 explicit NavigatorImpl(HTMLViewer* viewer) : viewer_(viewer) {} |
| 21 virtual ~LaunchableConnection() {} | 21 virtual ~NavigatorImpl() {} |
| 22 | 22 |
| 23 private: | 23 private: |
| 24 // Overridden from launcher::Launchable: | 24 // Overridden from navigation::Navigator: |
| 25 virtual void OnLaunch( | 25 virtual void Navigate( |
| 26 URLResponsePtr response, | 26 uint32_t node_id, |
| 27 ScopedDataPipeConsumerHandle response_body_stream, | 27 navigation::NavigationDetailsPtr details) OVERRIDE { |
| 28 view_manager::Id node_id) MOJO_OVERRIDE { | 28 printf("In HTMLViewer, rendering url: %s\n", details->response->url.data()); |
| 29 printf("In HTMLViewer, rendering url: %s\n", response->url.data()); | |
| 30 printf("HTML: \n"); | 29 printf("HTML: \n"); |
| 31 for (;;) { | 30 for (;;) { |
| 32 char buf[512]; | 31 char buf[512]; |
| 33 uint32_t num_bytes = sizeof(buf); | 32 uint32_t num_bytes = sizeof(buf); |
| 34 MojoResult result = ReadDataRaw( | 33 MojoResult result = ReadDataRaw( |
| 35 response_body_stream.get(), | 34 details->response_body_stream.get(), |
| 36 buf, | 35 buf, |
| 37 &num_bytes, | 36 &num_bytes, |
| 38 MOJO_READ_DATA_FLAG_NONE); | 37 MOJO_READ_DATA_FLAG_NONE); |
| 39 if (result == MOJO_RESULT_SHOULD_WAIT) { | 38 if (result == MOJO_RESULT_SHOULD_WAIT) { |
| 40 Wait(response_body_stream.get(), | 39 Wait(details->response_body_stream.get(), |
| 41 MOJO_WAIT_FLAG_READABLE, | 40 MOJO_WAIT_FLAG_READABLE, |
| 42 MOJO_DEADLINE_INDEFINITE); | 41 MOJO_DEADLINE_INDEFINITE); |
| 43 } else if (result == MOJO_RESULT_OK) { | 42 } else if (result == MOJO_RESULT_OK) { |
| 44 fwrite(buf, num_bytes, 1, stdout); | 43 fwrite(buf, num_bytes, 1, stdout); |
| 45 } else { | 44 } else { |
| 46 break; | 45 break; |
| 47 } | 46 } |
| 48 } | 47 } |
| 49 printf("\n>>>> EOF <<<<\n\n"); | 48 printf("\n>>>> EOF <<<<\n\n"); |
| 50 | 49 |
| 51 UpdateView(); | 50 UpdateView(); |
| 52 } | 51 } |
| 53 | 52 |
| 54 void UpdateView(); | 53 void UpdateView(); |
| 55 | 54 |
| 56 HTMLViewer* viewer_; | 55 HTMLViewer* viewer_; |
| 57 | 56 |
| 58 DISALLOW_COPY_AND_ASSIGN(LaunchableConnection); | 57 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl); |
| 59 }; | 58 }; |
| 60 | 59 |
| 61 class HTMLViewer : public Application, | 60 class HTMLViewer : public Application, |
| 62 public view_manager::ViewManagerDelegate { | 61 public view_manager::ViewManagerDelegate { |
| 63 public: | 62 public: |
| 64 HTMLViewer() : content_view_(NULL) {} | 63 HTMLViewer() : content_view_(NULL) {} |
| 65 virtual ~HTMLViewer() {} | 64 virtual ~HTMLViewer() {} |
| 66 | 65 |
| 67 private: | 66 private: |
| 68 friend class LaunchableConnection; | 67 friend class NavigatorImpl; |
| 69 | 68 |
| 70 // Overridden from Application: | 69 // Overridden from Application: |
| 71 virtual void Initialize() OVERRIDE { | 70 virtual void Initialize() OVERRIDE { |
| 72 AddService<LaunchableConnection>(this); | 71 AddService<NavigatorImpl>(this); |
| 73 view_manager::ViewManager::Create(this, this); | 72 view_manager::ViewManager::Create(this, this); |
| 74 } | 73 } |
| 75 | 74 |
| 76 // Overridden from view_manager::ViewManagerDelegate: | 75 // Overridden from view_manager::ViewManagerDelegate: |
| 77 virtual void OnRootAdded(view_manager::ViewManager* view_manager, | 76 virtual void OnRootAdded(view_manager::ViewManager* view_manager, |
| 78 view_manager::ViewTreeNode* root) OVERRIDE { | 77 view_manager::ViewTreeNode* root) OVERRIDE { |
| 79 content_view_ = view_manager::View::Create(view_manager); | 78 content_view_ = view_manager::View::Create(view_manager); |
| 80 root->SetActiveView(content_view_); | 79 root->SetActiveView(content_view_); |
| 81 content_view_->SetColor(SK_ColorRED); | 80 content_view_->SetColor(SK_ColorRED); |
| 82 } | 81 } |
| 83 | 82 |
| 84 view_manager::View* content_view_; | 83 view_manager::View* content_view_; |
| 85 | 84 |
| 86 DISALLOW_COPY_AND_ASSIGN(HTMLViewer); | 85 DISALLOW_COPY_AND_ASSIGN(HTMLViewer); |
| 87 }; | 86 }; |
| 88 | 87 |
| 89 void LaunchableConnection::UpdateView() { | 88 void NavigatorImpl::UpdateView() { |
| 90 viewer_->content_view_->SetColor(SK_ColorGREEN); | 89 viewer_->content_view_->SetColor(SK_ColorGREEN); |
| 91 } | 90 } |
| 92 | 91 |
| 93 } | 92 } |
| 94 | 93 |
| 95 // static | 94 // static |
| 96 Application* Application::Create() { | 95 Application* Application::Create() { |
| 97 return new examples::HTMLViewer; | 96 return new examples::HTMLViewer; |
| 98 } | 97 } |
| 99 | 98 |
| 100 } | 99 } |
| OLD | NEW |