Remove the RenderProcessHost observer and attach the WebContentsObserver earlier...
[chromium-blink-merge.git] / mojo / examples / wm_flow / embedded / embedded.cc
blobd328501b8ae14fa046045401fa407a28a5d9cc6d
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
3 // found in the LICENSE file.
5 #include "base/bind.h"
6 #include "base/macros.h"
7 #include "mojo/application/application_runner_chromium.h"
8 #include "mojo/examples/bitmap_uploader/bitmap_uploader.h"
9 #include "mojo/examples/wm_flow/app/embedder.mojom.h"
10 #include "mojo/examples/wm_flow/embedded/embeddee.mojom.h"
11 #include "mojo/public/cpp/application/application_connection.h"
12 #include "mojo/public/cpp/application/application_delegate.h"
13 #include "mojo/public/cpp/application/application_impl.h"
14 #include "mojo/public/cpp/application/connect.h"
15 #include "mojo/public/cpp/application/interface_factory_impl.h"
16 #include "mojo/public/cpp/application/service_provider_impl.h"
17 #include "mojo/services/public/cpp/view_manager/view.h"
18 #include "mojo/services/public/cpp/view_manager/view_manager.h"
19 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h"
20 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
22 namespace examples {
24 namespace {
26 class EmbeddeeImpl : public mojo::InterfaceImpl<Embeddee> {
27 public:
28 EmbeddeeImpl() {}
29 virtual ~EmbeddeeImpl() {}
31 private:
32 // Overridden from Embeddee:
33 virtual void HelloBack(const mojo::Callback<void()>& callback) override {
34 callback.Run();
37 DISALLOW_COPY_AND_ASSIGN(EmbeddeeImpl);
40 } // namespace
42 class WMFlowEmbedded : public mojo::ApplicationDelegate,
43 public mojo::ViewManagerDelegate {
44 public:
45 WMFlowEmbedded() : shell_(nullptr) {}
46 virtual ~WMFlowEmbedded() {}
48 private:
49 // Overridden from Application:
50 virtual void Initialize(mojo::ApplicationImpl* app) override {
51 shell_ = app->shell();
52 view_manager_client_factory_.reset(
53 new mojo::ViewManagerClientFactory(app->shell(), this));
55 virtual bool ConfigureIncomingConnection(
56 mojo::ApplicationConnection* connection) override {
57 connection->AddService(view_manager_client_factory_.get());
58 return true;
61 // Overridden from mojo::ViewManagerDelegate:
62 virtual void OnEmbed(
63 mojo::ViewManager* view_manager,
64 mojo::View* root,
65 mojo::ServiceProviderImpl* exported_services,
66 scoped_ptr<mojo::ServiceProvider> imported_services) override {
67 bitmap_uploader_.reset(new mojo::BitmapUploader(root));
68 bitmap_uploader_->Init(shell_);
69 bitmap_uploader_->SetColor(SK_ColorMAGENTA);
71 exported_services->AddService(&embeddee_factory_);
72 mojo::ConnectToService(imported_services.get(), &embedder_);
73 embedder_->HelloWorld(base::Bind(&WMFlowEmbedded::HelloWorldAck,
74 base::Unretained(this)));
76 virtual void OnViewManagerDisconnected(
77 mojo::ViewManager* view_manager) override {}
79 void HelloWorldAck() {
80 printf("HelloWorld() ack'ed\n");
83 mojo::Shell* shell_;
84 scoped_ptr<mojo::ViewManagerClientFactory> view_manager_client_factory_;
85 EmbedderPtr embedder_;
86 mojo::InterfaceFactoryImpl<EmbeddeeImpl> embeddee_factory_;
87 scoped_ptr<mojo::BitmapUploader> bitmap_uploader_;
89 DISALLOW_COPY_AND_ASSIGN(WMFlowEmbedded);
92 } // namespace examples
94 MojoResult MojoMain(MojoHandle shell_handle) {
95 mojo::ApplicationRunnerChromium runner(new examples::WMFlowEmbedded);
96 return runner.Run(shell_handle);