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

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

Issue 380413003: Mojo: Use InterfaceFactory<Interface> for service registration (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review feedback Created 6 years, 5 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 "base/message_loop/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 #include "mojo/examples/html_viewer/blink_platform_impl.h" 6 #include "mojo/examples/html_viewer/blink_platform_impl.h"
7 #include "mojo/examples/html_viewer/html_document_view.h" 7 #include "mojo/examples/html_viewer/html_document_view.h"
8 #include "mojo/public/cpp/application/application_connection.h" 8 #include "mojo/public/cpp/application/application_connection.h"
9 #include "mojo/public/cpp/application/application_delegate.h" 9 #include "mojo/public/cpp/application/application_delegate.h"
10 #include "mojo/public/cpp/application/application_impl.h" 10 #include "mojo/public/cpp/application/application_impl.h"
11 #include "mojo/public/cpp/application/interface_factory_with_context.h"
11 #include "mojo/services/public/cpp/view_manager/node.h" 12 #include "mojo/services/public/cpp/view_manager/node.h"
12 #include "mojo/services/public/cpp/view_manager/types.h" 13 #include "mojo/services/public/cpp/view_manager/types.h"
13 #include "mojo/services/public/cpp/view_manager/view.h" 14 #include "mojo/services/public/cpp/view_manager/view.h"
14 #include "mojo/services/public/cpp/view_manager/view_manager.h" 15 #include "mojo/services/public/cpp/view_manager/view_manager.h"
16 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h"
15 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" 17 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
16 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" 18 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h"
17 #include "third_party/WebKit/public/web/WebKit.h" 19 #include "third_party/WebKit/public/web/WebKit.h"
18 20
19 namespace mojo { 21 namespace mojo {
20 namespace examples { 22 namespace examples {
21 23
22 class HTMLViewer; 24 class HTMLViewer;
23 25
24 class NavigatorImpl : public InterfaceImpl<navigation::Navigator> { 26 class NavigatorImpl : public InterfaceImpl<navigation::Navigator> {
25 public: 27 public:
26 explicit NavigatorImpl(ApplicationConnection* connection, 28 explicit NavigatorImpl(HTMLViewer* viewer) : viewer_(viewer) {}
27 HTMLViewer* viewer) : viewer_(viewer) {}
28 virtual ~NavigatorImpl() {} 29 virtual ~NavigatorImpl() {}
29 30
30 private: 31 private:
31 // Overridden from navigation::Navigator: 32 // Overridden from navigation::Navigator:
32 virtual void Navigate( 33 virtual void Navigate(
33 uint32_t node_id, 34 uint32_t node_id,
34 navigation::NavigationDetailsPtr navigation_details, 35 navigation::NavigationDetailsPtr navigation_details,
35 navigation::ResponseDetailsPtr response_details) OVERRIDE; 36 navigation::ResponseDetailsPtr response_details) OVERRIDE;
36 37
37 HTMLViewer* viewer_; 38 HTMLViewer* viewer_;
38 39
39 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl); 40 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl);
40 }; 41 };
41 42
42 class HTMLViewer : public ApplicationDelegate, 43 class HTMLViewer
43 public view_manager::ViewManagerDelegate { 44 : public ApplicationDelegate,
45 public view_manager::ViewManagerDelegate,
46 public InterfaceFactoryWithContext<NavigatorImpl, HTMLViewer> {
44 public: 47 public:
45 HTMLViewer() : application_impl_(NULL), document_view_(NULL) { 48 HTMLViewer()
46 } 49 : InterfaceFactoryWithContext(this),
50 application_impl_(NULL),
51 document_view_(NULL),
52 view_manager_client_factory_(this) {}
47 virtual ~HTMLViewer() { 53 virtual ~HTMLViewer() {
48 blink::shutdown(); 54 blink::shutdown();
49 } 55 }
50 56
51 void Load(URLResponsePtr response) { 57 void Load(URLResponsePtr response) {
52 // Need to wait for OnRootAdded. 58 // Need to wait for OnRootAdded.
53 response_ = response.Pass(); 59 response_ = response.Pass();
54 MaybeLoad(); 60 MaybeLoad();
55 } 61 }
56 62
57 private: 63 private:
58 // Overridden from ApplicationDelegate: 64 // Overridden from ApplicationDelegate:
59 virtual void Initialize(ApplicationImpl* app) OVERRIDE { 65 virtual void Initialize(ApplicationImpl* app) OVERRIDE {
60 application_impl_ = app; 66 application_impl_ = app;
61 blink_platform_impl_.reset(new BlinkPlatformImpl(app)); 67 blink_platform_impl_.reset(new BlinkPlatformImpl(app));
62 blink::initialize(blink_platform_impl_.get()); 68 blink::initialize(blink_platform_impl_.get());
63 } 69 }
64 70
65 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) 71 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
66 OVERRIDE { 72 OVERRIDE {
67 connection->AddService<NavigatorImpl>(this); 73 connection->AddServiceFactory(this);
68 view_manager::ViewManager::ConfigureIncomingConnection(connection, this); 74 connection->AddServiceFactory(&view_manager_client_factory_);
69 return true; 75 return true;
70 } 76 }
71 77
72 // Overridden from view_manager::ViewManagerDelegate: 78 // Overridden from view_manager::ViewManagerDelegate:
73 virtual void OnRootAdded(view_manager::ViewManager* view_manager, 79 virtual void OnRootAdded(view_manager::ViewManager* view_manager,
74 view_manager::Node* root) OVERRIDE { 80 view_manager::Node* root) OVERRIDE {
75 document_view_ = new HTMLDocumentView( 81 document_view_ = new HTMLDocumentView(
76 application_impl_->ConnectToApplication("mojo://mojo_window_manager/")-> 82 application_impl_->ConnectToApplication("mojo://mojo_window_manager/")->
77 GetServiceProvider(), view_manager); 83 GetServiceProvider(), view_manager);
78 document_view_->AttachToNode(root); 84 document_view_->AttachToNode(root);
79 MaybeLoad(); 85 MaybeLoad();
80 } 86 }
81 virtual void OnViewManagerDisconnected( 87 virtual void OnViewManagerDisconnected(
82 view_manager::ViewManager* view_manager) OVERRIDE { 88 view_manager::ViewManager* view_manager) OVERRIDE {
83 base::MessageLoop::current()->Quit(); 89 base::MessageLoop::current()->Quit();
84 } 90 }
85 91
86 void MaybeLoad() { 92 void MaybeLoad() {
87 if (document_view_ && response_.get()) 93 if (document_view_ && response_.get())
88 document_view_->Load(response_.Pass()); 94 document_view_->Load(response_.Pass());
89 } 95 }
90 96
91 scoped_ptr<BlinkPlatformImpl> blink_platform_impl_; 97 scoped_ptr<BlinkPlatformImpl> blink_platform_impl_;
92 ApplicationImpl* application_impl_; 98 ApplicationImpl* application_impl_;
93 99
94 // TODO(darin): Figure out proper ownership of this instance. 100 // TODO(darin): Figure out proper ownership of this instance.
95 HTMLDocumentView* document_view_; 101 HTMLDocumentView* document_view_;
96 URLResponsePtr response_; 102 URLResponsePtr response_;
103 view_manager::ViewManagerClientFactory view_manager_client_factory_;
97 104
98 DISALLOW_COPY_AND_ASSIGN(HTMLViewer); 105 DISALLOW_COPY_AND_ASSIGN(HTMLViewer);
99 }; 106 };
100 107
101 void NavigatorImpl::Navigate( 108 void NavigatorImpl::Navigate(
102 uint32_t node_id, 109 uint32_t node_id,
103 navigation::NavigationDetailsPtr navigation_details, 110 navigation::NavigationDetailsPtr navigation_details,
104 navigation::ResponseDetailsPtr response_details) { 111 navigation::ResponseDetailsPtr response_details) {
105 printf("In HTMLViewer, rendering url: %s\n", 112 printf("In HTMLViewer, rendering url: %s\n",
106 response_details->response->url.data()); 113 response_details->response->url.data());
107 viewer_->Load(response_details->response.Pass()); 114 viewer_->Load(response_details->response.Pass());
108 } 115 }
109 116
110 } 117 }
111 118
112 // static 119 // static
113 ApplicationDelegate* ApplicationDelegate::Create() { 120 ApplicationDelegate* ApplicationDelegate::Create() {
114 return new examples::HTMLViewer; 121 return new examples::HTMLViewer;
115 } 122 }
116 123
117 } 124 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698