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

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

Issue 340453002: Mojo: HTML Viewer based on Blink. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix build 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
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/examples/html_viewer/blink_platform_impl.h"
6 #include "mojo/examples/html_viewer/html_document_view.h"
5 #include "mojo/public/cpp/application/application.h" 7 #include "mojo/public/cpp/application/application.h"
6 #include "mojo/services/public/cpp/view_manager/node.h" 8 #include "mojo/services/public/cpp/view_manager/node.h"
7 #include "mojo/services/public/cpp/view_manager/types.h" 9 #include "mojo/services/public/cpp/view_manager/types.h"
8 #include "mojo/services/public/cpp/view_manager/view.h" 10 #include "mojo/services/public/cpp/view_manager/view.h"
9 #include "mojo/services/public/cpp/view_manager/view_manager.h" 11 #include "mojo/services/public/cpp/view_manager/view_manager.h"
10 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" 12 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
11 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" 13 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h"
14 #include "third_party/WebKit/public/web/WebKit.h"
12 15
13 namespace mojo { 16 namespace mojo {
14 namespace examples { 17 namespace examples {
15 18
16 class HTMLViewer; 19 class HTMLViewer;
17 20
18 class NavigatorImpl : public InterfaceImpl<navigation::Navigator> { 21 class NavigatorImpl : public InterfaceImpl<navigation::Navigator> {
19 public: 22 public:
20 explicit NavigatorImpl(HTMLViewer* viewer) : viewer_(viewer) {} 23 explicit NavigatorImpl(HTMLViewer* viewer) : viewer_(viewer) {}
21 virtual ~NavigatorImpl() {} 24 virtual ~NavigatorImpl() {}
22 25
23 private: 26 private:
24 // Overridden from navigation::Navigator: 27 // Overridden from navigation::Navigator:
25 virtual void Navigate( 28 virtual void Navigate(
26 uint32_t node_id, 29 uint32_t node_id,
27 navigation::NavigationDetailsPtr navigation_details, 30 navigation::NavigationDetailsPtr navigation_details,
28 navigation::ResponseDetailsPtr response_details) OVERRIDE { 31 navigation::ResponseDetailsPtr response_details) OVERRIDE;
29 printf("In HTMLViewer, rendering url: %s\n",
30 response_details->response->url.data());
31 printf("HTML: \n");
32 for (;;) {
33 char buf[512];
34 uint32_t num_bytes = sizeof(buf);
35 MojoResult result = ReadDataRaw(
36 response_details->response_body_stream.get(),
37 buf,
38 &num_bytes,
39 MOJO_READ_DATA_FLAG_NONE);
40 if (result == MOJO_RESULT_SHOULD_WAIT) {
41 Wait(response_details->response_body_stream.get(),
42 MOJO_HANDLE_SIGNAL_READABLE,
43 MOJO_DEADLINE_INDEFINITE);
44 } else if (result == MOJO_RESULT_OK) {
45 fwrite(buf, num_bytes, 1, stdout);
46 } else {
47 break;
48 }
49 }
50 printf("\n>>>> EOF <<<<\n\n");
51
52 UpdateView();
53 }
54
55 void UpdateView();
56 32
57 HTMLViewer* viewer_; 33 HTMLViewer* viewer_;
58 34
59 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl); 35 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl);
60 }; 36 };
61 37
62 class HTMLViewer : public Application, 38 class HTMLViewer : public Application,
63 public view_manager::ViewManagerDelegate { 39 public view_manager::ViewManagerDelegate {
64 public: 40 public:
65 HTMLViewer() : content_view_(NULL) {} 41 HTMLViewer() : document_view_(NULL) {
66 virtual ~HTMLViewer() {} 42 }
43 virtual ~HTMLViewer() {
44 blink::shutdown();
45 }
46
47 void Load(URLResponsePtr response,
48 ScopedDataPipeConsumerHandle response_body_stream) {
49 // Need to wait for OnRootAdded.
50 response_ = response.Pass();
51 response_body_stream_ = response_body_stream.Pass();
52 MaybeLoad();
53 }
67 54
68 private: 55 private:
69 friend class NavigatorImpl;
70
71 // Overridden from Application: 56 // Overridden from Application:
72 virtual void Initialize() OVERRIDE { 57 virtual void Initialize() OVERRIDE {
58 blink_platform_impl_.reset(new BlinkPlatformImpl(this));
59 blink::initialize(blink_platform_impl_.get());
60
73 AddService<NavigatorImpl>(this); 61 AddService<NavigatorImpl>(this);
74 view_manager::ViewManager::Create(this, this); 62 view_manager::ViewManager::Create(this, this);
75 } 63 }
76 64
77 // Overridden from view_manager::ViewManagerDelegate: 65 // Overridden from view_manager::ViewManagerDelegate:
78 virtual void OnRootAdded(view_manager::ViewManager* view_manager, 66 virtual void OnRootAdded(view_manager::ViewManager* view_manager,
79 view_manager::Node* root) OVERRIDE { 67 view_manager::Node* root) OVERRIDE {
80 content_view_ = view_manager::View::Create(view_manager); 68 document_view_ = new HTMLDocumentView(view_manager);
81 root->SetActiveView(content_view_); 69 document_view_->AttachToNode(root);
82 content_view_->SetColor(SK_ColorRED); 70 MaybeLoad();
83 } 71 }
84 72
85 view_manager::View* content_view_; 73 void MaybeLoad() {
74 if (document_view_ && response_.get())
75 document_view_->Load(response_.Pass(), response_body_stream_.Pass());
76 }
77
78 scoped_ptr<BlinkPlatformImpl> blink_platform_impl_;
79
80 // TODO(darin): Figure out proper ownership of this instance.
81 HTMLDocumentView* document_view_;
82 URLResponsePtr response_;
83 ScopedDataPipeConsumerHandle response_body_stream_;
86 84
87 DISALLOW_COPY_AND_ASSIGN(HTMLViewer); 85 DISALLOW_COPY_AND_ASSIGN(HTMLViewer);
88 }; 86 };
89 87
90 void NavigatorImpl::UpdateView() { 88 void NavigatorImpl::Navigate(
91 viewer_->content_view_->SetColor(SK_ColorGREEN); 89 uint32_t node_id,
90 navigation::NavigationDetailsPtr navigation_details,
91 navigation::ResponseDetailsPtr response_details) {
92 printf("In HTMLViewer, rendering url: %s\n",
93 response_details->response->url.data());
94 viewer_->Load(response_details->response.Pass(),
95 response_details->response_body_stream.Pass());
92 } 96 }
93 97
94 } 98 }
95 99
96 // static 100 // static
97 Application* Application::Create() { 101 Application* Application::Create() {
98 return new examples::HTMLViewer; 102 return new examples::HTMLViewer;
99 } 103 }
100 104
101 } 105 }
OLDNEW
« no previous file with comments | « mojo/examples/html_viewer/html_document_view.cc ('k') | mojo/examples/html_viewer/webmimeregistry_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698