| OLD | NEW |
| 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/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "mojo/examples/window_manager/window_manager.mojom.h" | 8 #include "mojo/examples/window_manager/window_manager.mojom.h" |
| 9 #include "mojo/public/cpp/application/application.h" | 9 #include "mojo/public/cpp/application/application.h" |
| 10 #include "mojo/services/public/cpp/view_manager/node.h" | 10 #include "mojo/services/public/cpp/view_manager/node.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 AddService<WindowManagerConnection>(this); | 106 AddService<WindowManagerConnection>(this); |
| 107 AddService<NavigatorHost>(this); | 107 AddService<NavigatorHost>(this); |
| 108 ViewManager::Create(this, this); | 108 ViewManager::Create(this, this); |
| 109 } | 109 } |
| 110 | 110 |
| 111 // Overridden from ViewObserver: | 111 // Overridden from ViewObserver: |
| 112 virtual void OnViewInputEvent(View* view, const EventPtr& event) OVERRIDE { | 112 virtual void OnViewInputEvent(View* view, const EventPtr& event) OVERRIDE { |
| 113 if (event->action == ui::ET_MOUSE_RELEASED) { | 113 if (event->action == ui::ET_MOUSE_RELEASED) { |
| 114 std::string app_url; | 114 std::string app_url; |
| 115 if (event->flags & ui::EF_LEFT_MOUSE_BUTTON) | 115 if (event->flags & ui::EF_LEFT_MOUSE_BUTTON) |
| 116 app_url = "mojo:mojo_embedded_app"; | 116 app_url = "mojo://mojo_embedded_app"; |
| 117 else if (event->flags & ui::EF_RIGHT_MOUSE_BUTTON) | 117 else if (event->flags & ui::EF_RIGHT_MOUSE_BUTTON) |
| 118 app_url = "mojo:mojo_nesting_app"; | 118 app_url = "mojo://mojo_nesting_app"; |
| 119 DCHECK(!app_url.empty()); | 119 DCHECK(!app_url.empty()); |
| 120 | 120 |
| 121 Node* node = view_manager_->GetNodeById(parent_node_id_); | 121 Node* node = view_manager_->GetNodeById(parent_node_id_); |
| 122 navigation::NavigationDetailsPtr nav_details( | 122 navigation::NavigationDetailsPtr nav_details( |
| 123 navigation::NavigationDetails::New()); | 123 navigation::NavigationDetails::New()); |
| 124 size_t index = node->children().size() - 1; | 124 size_t index = node->children().size() - 1; |
| 125 nav_details->url = base::StringPrintf( | 125 nav_details->url = base::StringPrintf( |
| 126 "%s/%x", app_url.c_str(), kColors[index % arraysize(kColors)]); | 126 "%s/%x", app_url.c_str(), kColors[index % arraysize(kColors)]); |
| 127 navigation::ResponseDetailsPtr response; | 127 navigation::ResponseDetailsPtr response; |
| 128 CreateWindow(app_url, nav_details.Pass(), response.Pass()); | 128 CreateWindow(app_url, nav_details.Pass(), response.Pass()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 142 View* view = View::Create(view_manager); | 142 View* view = View::Create(view_manager); |
| 143 node->SetActiveView(view); | 143 node->SetActiveView(view); |
| 144 view->SetColor(SK_ColorBLUE); | 144 view->SetColor(SK_ColorBLUE); |
| 145 view->AddObserver(this); | 145 view->AddObserver(this); |
| 146 | 146 |
| 147 CreateLauncherUI(); | 147 CreateLauncherUI(); |
| 148 } | 148 } |
| 149 | 149 |
| 150 // Overridden from LauncherClient: | 150 // Overridden from LauncherClient: |
| 151 virtual void OnLaunch( | 151 virtual void OnLaunch( |
| 152 const mojo::String& handler_url, mojo::URLResponsePtr response, | 152 const mojo::String& requested_url, const mojo::String& handler_url, |
| 153 mojo::ScopedDataPipeConsumerHandle response_body_stream) OVERRIDE { | 153 navigation::ResponseDetailsPtr response) OVERRIDE { |
| 154 navigation::NavigationDetailsPtr nav_details( | 154 navigation::NavigationDetailsPtr nav_details( |
| 155 navigation::NavigationDetails::New()); | 155 navigation::NavigationDetails::New()); |
| 156 nav_details->url = response->url; | 156 nav_details->url = requested_url; |
| 157 navigation::ResponseDetailsPtr response_details( | 157 CreateWindow(handler_url, nav_details.Pass(), response.Pass()); |
| 158 navigation::ResponseDetails::New()); | |
| 159 response_details->response = response.Pass(); | |
| 160 response_details->response_body_stream = response_body_stream.Pass(); | |
| 161 CreateWindow(handler_url, nav_details.Pass(), response_details.Pass()); | |
| 162 } | 158 } |
| 163 | 159 |
| 164 void CreateLauncherUI() { | 160 void CreateLauncherUI() { |
| 165 navigation::NavigationDetailsPtr nav_details; | 161 navigation::NavigationDetailsPtr nav_details; |
| 166 navigation::ResponseDetailsPtr response; | 162 navigation::ResponseDetailsPtr response; |
| 167 launcher_ui_ = CreateChild("mojo:mojo_browser", gfx::Rect(25, 25, 400, 25), | 163 launcher_ui_ = CreateChild("mojo:mojo_browser", gfx::Rect(25, 25, 400, 25), |
| 168 nav_details.Pass(), response.Pass()); | 164 nav_details.Pass(), response.Pass()); |
| 169 } | 165 } |
| 170 | 166 |
| 171 void CreateWindow(const std::string& handler_url, | 167 void CreateWindow(const std::string& handler_url, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 } | 216 } |
| 221 | 217 |
| 222 } // namespace examples | 218 } // namespace examples |
| 223 | 219 |
| 224 // static | 220 // static |
| 225 Application* Application::Create() { | 221 Application* Application::Create() { |
| 226 return new examples::WindowManager; | 222 return new examples::WindowManager; |
| 227 } | 223 } |
| 228 | 224 |
| 229 } // namespace mojo | 225 } // namespace mojo |
| OLD | NEW |