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

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: convert everything over, remove ApplicationConnection::AddService 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/context_interface_factory.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 : public ApplicationDelegate,
43 public view_manager::ViewManagerDelegate { 44 public view_manager::ViewManagerDelegate,
45 public ContextInterfaceFactory<NavigatorImpl, HTMLViewer> {
44 public: 46 public:
45 HTMLViewer() : application_impl_(NULL), document_view_(NULL) { 47 HTMLViewer()
46 } 48 : ContextInterfaceFactory(this),
49 application_impl_(NULL),
50 document_view_(NULL),
51 view_manager_client_factory_(this) {}
47 virtual ~HTMLViewer() { 52 virtual ~HTMLViewer() {
48 blink::shutdown(); 53 blink::shutdown();
49 } 54 }
50 55
51 void Load(URLResponsePtr response) { 56 void Load(URLResponsePtr response) {
52 // Need to wait for OnRootAdded. 57 // Need to wait for OnRootAdded.
53 response_ = response.Pass(); 58 response_ = response.Pass();
54 MaybeLoad(); 59 MaybeLoad();
55 } 60 }
56 61
57 private: 62 private:
58 // Overridden from ApplicationDelegate: 63 // Overridden from ApplicationDelegate:
59 virtual void Initialize(ApplicationImpl* app) OVERRIDE { 64 virtual void Initialize(ApplicationImpl* app) OVERRIDE {
60 application_impl_ = app; 65 application_impl_ = app;
61 blink_platform_impl_.reset(new BlinkPlatformImpl(app)); 66 blink_platform_impl_.reset(new BlinkPlatformImpl(app));
62 blink::initialize(blink_platform_impl_.get()); 67 blink::initialize(blink_platform_impl_.get());
63 } 68 }
64 69
65 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) 70 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
66 OVERRIDE { 71 OVERRIDE {
67 connection->AddService<NavigatorImpl>(this); 72 connection->AddServiceFactory(this);
68 view_manager::ViewManager::ConfigureIncomingConnection(connection, this); 73 connection->AddServiceFactory(&view_manager_client_factory_);
69 return true; 74 return true;
70 } 75 }
71 76
72 // Overridden from view_manager::ViewManagerDelegate: 77 // Overridden from view_manager::ViewManagerDelegate:
73 virtual void OnRootAdded(view_manager::ViewManager* view_manager, 78 virtual void OnRootAdded(view_manager::ViewManager* view_manager,
74 view_manager::Node* root) OVERRIDE { 79 view_manager::Node* root) OVERRIDE {
75 document_view_ = new HTMLDocumentView( 80 document_view_ = new HTMLDocumentView(
76 application_impl_->ConnectToApplication("mojo://mojo_window_manager/")-> 81 application_impl_->ConnectToApplication("mojo://mojo_window_manager/")->
77 GetServiceProvider(), view_manager); 82 GetServiceProvider(), view_manager);
78 document_view_->AttachToNode(root); 83 document_view_->AttachToNode(root);
79 MaybeLoad(); 84 MaybeLoad();
80 } 85 }
81 virtual void OnViewManagerDisconnected( 86 virtual void OnViewManagerDisconnected(
82 view_manager::ViewManager* view_manager) OVERRIDE { 87 view_manager::ViewManager* view_manager) OVERRIDE {
83 base::MessageLoop::current()->Quit(); 88 base::MessageLoop::current()->Quit();
84 } 89 }
85 90
86 void MaybeLoad() { 91 void MaybeLoad() {
87 if (document_view_ && response_.get()) 92 if (document_view_ && response_.get())
88 document_view_->Load(response_.Pass()); 93 document_view_->Load(response_.Pass());
89 } 94 }
90 95
91 scoped_ptr<BlinkPlatformImpl> blink_platform_impl_; 96 scoped_ptr<BlinkPlatformImpl> blink_platform_impl_;
92 ApplicationImpl* application_impl_; 97 ApplicationImpl* application_impl_;
93 98
94 // TODO(darin): Figure out proper ownership of this instance. 99 // TODO(darin): Figure out proper ownership of this instance.
95 HTMLDocumentView* document_view_; 100 HTMLDocumentView* document_view_;
96 URLResponsePtr response_; 101 URLResponsePtr response_;
102 view_manager::ViewManagerClientFactory view_manager_client_factory_;
97 103
98 DISALLOW_COPY_AND_ASSIGN(HTMLViewer); 104 DISALLOW_COPY_AND_ASSIGN(HTMLViewer);
99 }; 105 };
100 106
101 void NavigatorImpl::Navigate( 107 void NavigatorImpl::Navigate(
102 uint32_t node_id, 108 uint32_t node_id,
103 navigation::NavigationDetailsPtr navigation_details, 109 navigation::NavigationDetailsPtr navigation_details,
104 navigation::ResponseDetailsPtr response_details) { 110 navigation::ResponseDetailsPtr response_details) {
105 printf("In HTMLViewer, rendering url: %s\n", 111 printf("In HTMLViewer, rendering url: %s\n",
106 response_details->response->url.data()); 112 response_details->response->url.data());
107 viewer_->Load(response_details->response.Pass()); 113 viewer_->Load(response_details->response.Pass());
108 } 114 }
109 115
110 } 116 }
111 117
112 // static 118 // static
113 ApplicationDelegate* ApplicationDelegate::Create() { 119 ApplicationDelegate* ApplicationDelegate::Create() {
114 return new examples::HTMLViewer; 120 return new examples::HTMLViewer;
115 } 121 }
116 122
117 } 123 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698