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

Side by Side Diff: mojo/examples/wm_flow/embedded/embedded.cc

Issue 433513005: Pass ServiceProvider thru ViewManagerService::Embed() allowing embedder & embeddee to expose servic… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 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/wm_flow/app/embedder.mojom ('k') | mojo/examples/wm_flow/embedded/embeddee.mojom » ('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 "base/bind.h" 5 #include "base/bind.h"
6 #include "mojo/examples/wm_flow/app/embedder.mojom.h"
7 #include "mojo/examples/wm_flow/embedded/embeddee.mojom.h"
6 #include "mojo/public/cpp/application/application_connection.h" 8 #include "mojo/public/cpp/application/application_connection.h"
7 #include "mojo/public/cpp/application/application_delegate.h" 9 #include "mojo/public/cpp/application/application_delegate.h"
8 #include "mojo/public/cpp/application/application_impl.h" 10 #include "mojo/public/cpp/application/application_impl.h"
11 #include "mojo/public/cpp/application/connect.h"
12 #include "mojo/public/cpp/application/interface_factory_impl.h"
13 #include "mojo/public/cpp/application/service_provider_impl.h"
9 #include "mojo/services/public/cpp/view_manager/node.h" 14 #include "mojo/services/public/cpp/view_manager/node.h"
10 #include "mojo/services/public/cpp/view_manager/view.h" 15 #include "mojo/services/public/cpp/view_manager/view.h"
11 #include "mojo/services/public/cpp/view_manager/view_manager.h" 16 #include "mojo/services/public/cpp/view_manager/view_manager.h"
12 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" 17 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h"
13 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" 18 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
14 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" 19 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
15 20
16 namespace examples { 21 namespace examples {
22
17 namespace { 23 namespace {
18 void ConnectCallback(bool success) {}
19 24
20 const SkColor kColors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorYELLOW }; 25 class EmbeddeeImpl : public mojo::InterfaceImpl<Embeddee> {
26 public:
27 EmbeddeeImpl() {}
28 virtual ~EmbeddeeImpl() {}
29
30 private:
31 // Overridden from Embeddee:
32 virtual void HelloBack(const mojo::Callback<void()>& callback) OVERRIDE {
33 callback.Run();
34 }
35
36 DISALLOW_COPY_AND_ASSIGN(EmbeddeeImpl);
37 };
21 38
22 } // namespace 39 } // namespace
23 40
24 // This app starts its life via Connect() rather than by being embed, so it does 41 class WMFlowEmbedded : public mojo::ApplicationDelegate,
25 // not start with a connection to the ViewManager service. It has to obtain a 42 public mojo::ViewManagerDelegate {
26 // connection by connecting to the ViewManagerInit service and asking to be
27 // embed without a node context.
28 class WMFlowApp : public mojo::ApplicationDelegate,
29 public mojo::ViewManagerDelegate {
30 public: 43 public:
31 WMFlowApp() : embed_count_(0), view_manager_client_factory_(this) {} 44 WMFlowEmbedded()
32 virtual ~WMFlowApp() {} 45 : view_manager_client_factory_(this) {}
46 virtual ~WMFlowEmbedded() {}
33 47
34 private: 48 private:
35 // Overridden from Application: 49 // Overridden from Application:
36 virtual void Initialize(mojo::ApplicationImpl* app) MOJO_OVERRIDE { 50 virtual void Initialize(mojo::ApplicationImpl* app) MOJO_OVERRIDE {
37 mojo::ViewManagerInitServicePtr init_svc;
38 app->ConnectToService("mojo:mojo_view_manager", &init_svc);
39 init_svc->Embed("mojo:mojo_wm_flow_app", base::Bind(&ConnectCallback));
40 init_svc->Embed("mojo:mojo_wm_flow_app", base::Bind(&ConnectCallback));
41 init_svc->Embed("mojo:mojo_wm_flow_app", base::Bind(&ConnectCallback));
42 } 51 }
43 virtual bool ConfigureIncomingConnection( 52 virtual bool ConfigureIncomingConnection(
44 mojo::ApplicationConnection* connection) MOJO_OVERRIDE { 53 mojo::ApplicationConnection* connection) MOJO_OVERRIDE {
45 connection->AddService(&view_manager_client_factory_); 54 connection->AddService(&view_manager_client_factory_);
46 return true; 55 return true;
47 } 56 }
48 57
49 void OnConnect(bool success) {}
50
51 // Overridden from mojo::ViewManagerDelegate: 58 // Overridden from mojo::ViewManagerDelegate:
52 virtual void OnEmbed(mojo::ViewManager* view_manager, 59 virtual void OnEmbed(
53 mojo::Node* root) MOJO_OVERRIDE { 60 mojo::ViewManager* view_manager,
61 mojo::Node* root,
62 mojo::ServiceProviderImpl* exported_services,
63 scoped_ptr<mojo::ServiceProvider> imported_services) MOJO_OVERRIDE {
54 mojo::View* view = 64 mojo::View* view =
55 mojo::View::Create(view_manager); 65 mojo::View::Create(view_manager);
56 root->SetActiveView(view); 66 root->SetActiveView(view);
57 view->SetColor(kColors[embed_count_++ % arraysize(kColors)]); 67 view->SetColor(SK_ColorMAGENTA);
68
69 exported_services->AddService(&embeddee_factory_);
70 mojo::ConnectToService(imported_services.get(), &embedder_);
71 embedder_->HelloWorld(base::Bind(&WMFlowEmbedded::HelloWorldAck,
72 base::Unretained(this)));
58 } 73 }
59 virtual void OnViewManagerDisconnected( 74 virtual void OnViewManagerDisconnected(
60 mojo::ViewManager* view_manager) MOJO_OVERRIDE {} 75 mojo::ViewManager* view_manager) MOJO_OVERRIDE {}
61 76
62 int embed_count_; 77 void HelloWorldAck() {
78 printf("HelloWorld() ack'ed\n");
79 }
80
63 mojo::ViewManagerClientFactory view_manager_client_factory_; 81 mojo::ViewManagerClientFactory view_manager_client_factory_;
82 EmbedderPtr embedder_;
83 mojo::InterfaceFactoryImpl<EmbeddeeImpl> embeddee_factory_;
64 84
65 DISALLOW_COPY_AND_ASSIGN(WMFlowApp); 85 DISALLOW_COPY_AND_ASSIGN(WMFlowEmbedded);
66 }; 86 };
67 87
68 } // namespace examples 88 } // namespace examples
69 89
70 namespace mojo { 90 namespace mojo {
71 91
72 // static 92 // static
73 ApplicationDelegate* ApplicationDelegate::Create() { 93 ApplicationDelegate* ApplicationDelegate::Create() {
74 return new examples::WMFlowApp; 94 return new examples::WMFlowEmbedded;
75 } 95 }
76 96
77 } // namespace 97 } // namespace
OLDNEW
« no previous file with comments | « mojo/examples/wm_flow/app/embedder.mojom ('k') | mojo/examples/wm_flow/embedded/embeddee.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698