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

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

Issue 514063003: Update view_manager and window_manager to make use of content handling. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@viewman2
Patch Set: rebase Created 6 years, 3 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
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/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "mojo/examples/window_manager/window_manager.mojom.h" 9 #include "mojo/examples/window_manager/window_manager.mojom.h"
10 #include "mojo/public/c/system/main.h" 10 #include "mojo/public/c/system/main.h"
11 #include "mojo/public/cpp/application/application_connection.h" 11 #include "mojo/public/cpp/application/application_connection.h"
12 #include "mojo/public/cpp/application/application_delegate.h" 12 #include "mojo/public/cpp/application/application_delegate.h"
13 #include "mojo/public/cpp/application/application_impl.h"
13 #include "mojo/public/cpp/application/application_runner_chromium.h" 14 #include "mojo/public/cpp/application/application_runner_chromium.h"
14 #include "mojo/public/cpp/application/interface_factory_impl.h" 15 #include "mojo/public/cpp/application/interface_factory_impl.h"
15 #include "mojo/services/public/cpp/view_manager/view.h" 16 #include "mojo/services/public/cpp/view_manager/view.h"
16 #include "mojo/services/public/cpp/view_manager/view_manager.h" 17 #include "mojo/services/public/cpp/view_manager/view_manager.h"
17 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" 18 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h"
18 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" 19 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
19 #include "mojo/services/public/cpp/view_manager/view_observer.h" 20 #include "mojo/services/public/cpp/view_manager/view_observer.h"
20 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h"
21 #include "ui/events/event_constants.h" 21 #include "ui/events/event_constants.h"
22 #include "url/gurl.h" 22 #include "url/gurl.h"
23 23
24 namespace mojo { 24 namespace mojo {
25 namespace examples { 25 namespace examples {
26 26
27 namespace { 27 namespace {
28 const char kEmbeddedAppURL[] = "mojo:mojo_embedded_app"; 28 const char kEmbeddedAppURL[] = "mojo:mojo_embedded_app";
29 } 29 }
30 30
31 class NestingApp; 31 class NestingApp;
32 32
33 class NavigatorImpl : public InterfaceImpl<Navigator> {
34 public:
35 explicit NavigatorImpl(NestingApp* app) : app_(app) {}
36
37 private:
38 virtual void Navigate(
39 uint32 node_id,
40 NavigationDetailsPtr navigation_details,
41 ResponseDetailsPtr response_details) OVERRIDE;
42
43 NestingApp* app_;
44 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl);
45 };
46
47 // An app that embeds another app. 33 // An app that embeds another app.
48 // TODO(davemoore): Is this the right name? 34 // TODO(davemoore): Is this the right name?
49 class NestingApp 35 class NestingApp
50 : public ApplicationDelegate, 36 : public ApplicationDelegate,
51 public ViewManagerDelegate, 37 public ViewManagerDelegate,
52 public ViewObserver { 38 public ViewObserver {
53 public: 39 public:
54 NestingApp() 40 NestingApp()
55 : navigator_factory_(this), 41 : nested_(NULL) {}
56 view_manager_client_factory_(this),
57 nested_(NULL) {}
58 virtual ~NestingApp() {} 42 virtual ~NestingApp() {}
59 43
60 void set_color(const std::string& color) { color_ = color; } 44 private:
61 45 // Overridden from ApplicationDelegate:
62 void NavigateChild() { 46 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE {
63 if (!color_.empty() && nested_) { 47 view_manager_client_factory_.reset(
64 NavigationDetailsPtr details(NavigationDetails::New()); 48 new ViewManagerClientFactory(app->shell(), this));
65 details->request->url =
66 base::StringPrintf("%s/%s", kEmbeddedAppURL, color_.c_str());
67 ResponseDetailsPtr response_details(ResponseDetails::New());
68 navigator_->Navigate(
69 nested_->id(), details.Pass(), response_details.Pass());
70 }
71 } 49 }
72 50
73 private:
74 // Overridden from ApplicationImpl: 51 // Overridden from ApplicationImpl:
75 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) 52 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
76 MOJO_OVERRIDE { 53 MOJO_OVERRIDE {
77 connection->ConnectToService(&window_manager_); 54 connection->ConnectToService(&window_manager_);
78 connection->AddService(&view_manager_client_factory_); 55 connection->AddService(view_manager_client_factory_.get());
79 connection->AddService(&navigator_factory_);
80 // TODO(davemoore): Is this ok?
81 if (!navigator_) {
82 connection->ConnectToApplication(
83 kEmbeddedAppURL)->ConnectToService(&navigator_);
84 }
85 return true; 56 return true;
86 } 57 }
87 58
88 // Overridden from ViewManagerDelegate: 59 // Overridden from ViewManagerDelegate:
89 virtual void OnEmbed(ViewManager* view_manager, 60 virtual void OnEmbed(ViewManager* view_manager,
90 View* root, 61 View* root,
91 ServiceProviderImpl* exported_services, 62 ServiceProviderImpl* exported_services,
92 scoped_ptr<ServiceProvider> imported_services) OVERRIDE { 63 scoped_ptr<ServiceProvider> imported_services) OVERRIDE {
93 root->AddObserver(this); 64 root->AddObserver(this);
94 root->SetColor(SK_ColorCYAN); 65 root->SetColor(SK_ColorCYAN);
95 66
96 nested_ = View::Create(view_manager); 67 nested_ = View::Create(view_manager);
97 root->AddChild(nested_); 68 root->AddChild(nested_);
98 nested_->SetBounds(gfx::Rect(20, 20, 50, 50)); 69 nested_->SetBounds(gfx::Rect(20, 20, 50, 50));
99 nested_->Embed(kEmbeddedAppURL); 70 nested_->Embed(kEmbeddedAppURL);
100
101 NavigateChild();
102 } 71 }
103 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE { 72 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE {
104 base::MessageLoop::current()->Quit(); 73 base::MessageLoop::current()->Quit();
105 } 74 }
106 75
107 // Overridden from ViewObserver: 76 // Overridden from ViewObserver:
108 virtual void OnViewDestroyed(View* view) OVERRIDE { 77 virtual void OnViewDestroyed(View* view) OVERRIDE {
109 // TODO(beng): reap views & child Views. 78 // TODO(beng): reap views & child Views.
110 nested_ = NULL; 79 nested_ = NULL;
111 } 80 }
112 virtual void OnViewInputEvent(View* view, const EventPtr& event) OVERRIDE { 81 virtual void OnViewInputEvent(View* view, const EventPtr& event) OVERRIDE {
113 if (event->action == EVENT_TYPE_MOUSE_RELEASED) 82 if (event->action == EVENT_TYPE_MOUSE_RELEASED)
114 window_manager_->CloseWindow(view->id()); 83 window_manager_->CloseWindow(view->id());
115 } 84 }
116 85
117 InterfaceFactoryImplWithContext<NavigatorImpl, NestingApp> navigator_factory_; 86 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_;
118 ViewManagerClientFactory view_manager_client_factory_;
119 87
120 std::string color_;
121 View* nested_; 88 View* nested_;
122 NavigatorPtr navigator_;
123 IWindowManagerPtr window_manager_; 89 IWindowManagerPtr window_manager_;
124 90
125 DISALLOW_COPY_AND_ASSIGN(NestingApp); 91 DISALLOW_COPY_AND_ASSIGN(NestingApp);
126 }; 92 };
127 93
128 void NavigatorImpl::Navigate(uint32 node_id,
129 NavigationDetailsPtr navigation_details,
130 ResponseDetailsPtr response_details) {
131 GURL url(navigation_details->request->url.To<std::string>());
132 if (!url.is_valid()) {
133 LOG(ERROR) << "URL is invalid.";
134 return;
135 }
136 app_->set_color(url.path().substr(1));
137 app_->NavigateChild();
138 }
139
140 } // namespace examples 94 } // namespace examples
141 } // namespace mojo 95 } // namespace mojo
142 96
143 MojoResult MojoMain(MojoHandle shell_handle) { 97 MojoResult MojoMain(MojoHandle shell_handle) {
144 mojo::ApplicationRunnerChromium runner(new mojo::examples::NestingApp); 98 mojo::ApplicationRunnerChromium runner(new mojo::examples::NestingApp);
145 return runner.Run(shell_handle); 99 return runner.Run(shell_handle);
146 } 100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698