Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Side by Side Diff: mojo/examples/html_viewer/html_viewer.cc

Issue 331323007: Eliminate Launchable. Use Navigator instead. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/examples/embedded_app/embedded_app.cc ('k') | mojo/examples/image_viewer/image_viewer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/node.h" 7 #include "mojo/services/public/cpp/view_manager/node.h"
7 #include "mojo/services/public/cpp/view_manager/types.h" 8 #include "mojo/services/public/cpp/view_manager/types.h"
8 #include "mojo/services/public/cpp/view_manager/view.h" 9 #include "mojo/services/public/cpp/view_manager/view.h"
9 #include "mojo/services/public/cpp/view_manager/view_manager.h" 10 #include "mojo/services/public/cpp/view_manager/view_manager.h"
10 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" 11 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.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 navigation_details,
28 view_manager::Id node_id) MOJO_OVERRIDE { 28 navigation::ResponseDetailsPtr response_details) OVERRIDE {
29 printf("In HTMLViewer, rendering url: %s\n", response->url.data()); 29 printf("In HTMLViewer, rendering url: %s\n",
30 response_details->response->url.data());
30 printf("HTML: \n"); 31 printf("HTML: \n");
31 for (;;) { 32 for (;;) {
32 char buf[512]; 33 char buf[512];
33 uint32_t num_bytes = sizeof(buf); 34 uint32_t num_bytes = sizeof(buf);
34 MojoResult result = ReadDataRaw( 35 MojoResult result = ReadDataRaw(
35 response_body_stream.get(), 36 response_details->response_body_stream.get(),
36 buf, 37 buf,
37 &num_bytes, 38 &num_bytes,
38 MOJO_READ_DATA_FLAG_NONE); 39 MOJO_READ_DATA_FLAG_NONE);
39 if (result == MOJO_RESULT_SHOULD_WAIT) { 40 if (result == MOJO_RESULT_SHOULD_WAIT) {
40 Wait(response_body_stream.get(), 41 Wait(response_details->response_body_stream.get(),
41 MOJO_HANDLE_SIGNAL_READABLE, 42 MOJO_HANDLE_SIGNAL_READABLE,
42 MOJO_DEADLINE_INDEFINITE); 43 MOJO_DEADLINE_INDEFINITE);
43 } else if (result == MOJO_RESULT_OK) { 44 } else if (result == MOJO_RESULT_OK) {
44 fwrite(buf, num_bytes, 1, stdout); 45 fwrite(buf, num_bytes, 1, stdout);
45 } else { 46 } else {
46 break; 47 break;
47 } 48 }
48 } 49 }
49 printf("\n>>>> EOF <<<<\n\n"); 50 printf("\n>>>> EOF <<<<\n\n");
50 51
51 UpdateView(); 52 UpdateView();
52 } 53 }
53 54
54 void UpdateView(); 55 void UpdateView();
55 56
56 HTMLViewer* viewer_; 57 HTMLViewer* viewer_;
57 58
58 DISALLOW_COPY_AND_ASSIGN(LaunchableConnection); 59 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl);
59 }; 60 };
60 61
61 class HTMLViewer : public Application, 62 class HTMLViewer : public Application,
62 public view_manager::ViewManagerDelegate { 63 public view_manager::ViewManagerDelegate {
63 public: 64 public:
64 HTMLViewer() : content_view_(NULL) {} 65 HTMLViewer() : content_view_(NULL) {}
65 virtual ~HTMLViewer() {} 66 virtual ~HTMLViewer() {}
66 67
67 private: 68 private:
68 friend class LaunchableConnection; 69 friend class NavigatorImpl;
69 70
70 // Overridden from Application: 71 // Overridden from Application:
71 virtual void Initialize() OVERRIDE { 72 virtual void Initialize() OVERRIDE {
72 AddService<LaunchableConnection>(this); 73 AddService<NavigatorImpl>(this);
73 view_manager::ViewManager::Create(this, this); 74 view_manager::ViewManager::Create(this, this);
74 } 75 }
75 76
76 // Overridden from view_manager::ViewManagerDelegate: 77 // Overridden from view_manager::ViewManagerDelegate:
77 virtual void OnRootAdded(view_manager::ViewManager* view_manager, 78 virtual void OnRootAdded(view_manager::ViewManager* view_manager,
78 view_manager::Node* root) OVERRIDE { 79 view_manager::Node* root) OVERRIDE {
79 content_view_ = view_manager::View::Create(view_manager); 80 content_view_ = view_manager::View::Create(view_manager);
80 root->SetActiveView(content_view_); 81 root->SetActiveView(content_view_);
81 content_view_->SetColor(SK_ColorRED); 82 content_view_->SetColor(SK_ColorRED);
82 } 83 }
83 84
84 view_manager::View* content_view_; 85 view_manager::View* content_view_;
85 86
86 DISALLOW_COPY_AND_ASSIGN(HTMLViewer); 87 DISALLOW_COPY_AND_ASSIGN(HTMLViewer);
87 }; 88 };
88 89
89 void LaunchableConnection::UpdateView() { 90 void NavigatorImpl::UpdateView() {
90 viewer_->content_view_->SetColor(SK_ColorGREEN); 91 viewer_->content_view_->SetColor(SK_ColorGREEN);
91 } 92 }
92 93
93 } 94 }
94 95
95 // static 96 // static
96 Application* Application::Create() { 97 Application* Application::Create() {
97 return new examples::HTMLViewer; 98 return new examples::HTMLViewer;
98 } 99 }
99 100
100 } 101 }
OLDNEW
« no previous file with comments | « mojo/examples/embedded_app/embedded_app.cc ('k') | mojo/examples/image_viewer/image_viewer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698