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