| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "base/bind.h" | |
| 6 #include "base/logging.h" | |
| 7 #include "base/macros.h" | |
| 8 #include "base/message_loop/message_loop.h" | |
| 9 #include "base/strings/string_number_conversions.h" | |
| 10 #include "examples/bitmap_uploader/bitmap_uploader.h" | |
| 11 #include "mojo/application/application_runner_chromium.h" | |
| 12 #include "mojo/public/c/system/main.h" | |
| 13 #include "mojo/public/cpp/application/application_connection.h" | |
| 14 #include "mojo/public/cpp/application/application_delegate.h" | |
| 15 #include "mojo/public/cpp/application/application_impl.h" | |
| 16 #include "mojo/public/cpp/application/connect.h" | |
| 17 #include "mojo/public/cpp/application/interface_factory_impl.h" | |
| 18 #include "mojo/services/navigation/interfaces/navigation.mojom.h" | |
| 19 #include "mojo/services/view_manager/cpp/view.h" | |
| 20 #include "mojo/services/view_manager/cpp/view_manager.h" | |
| 21 #include "mojo/services/view_manager/cpp/view_manager_client_factory.h" | |
| 22 #include "mojo/services/view_manager/cpp/view_manager_delegate.h" | |
| 23 #include "mojo/services/view_manager/cpp/view_observer.h" | |
| 24 #include "third_party/skia/include/core/SkColor.h" | |
| 25 #include "url/gurl.h" | |
| 26 #include "url/url_util.h" | |
| 27 | |
| 28 namespace mojo { | |
| 29 namespace examples { | |
| 30 | |
| 31 const SkColor kColors[] = {SK_ColorYELLOW, SK_ColorRED, SK_ColorGREEN, | |
| 32 SK_ColorMAGENTA}; | |
| 33 | |
| 34 struct Window { | |
| 35 Window(View* root, ServiceProviderPtr embedder_service_provider, Shell* shell) | |
| 36 : root(root), | |
| 37 embedder_service_provider(embedder_service_provider.Pass()), | |
| 38 bitmap_uploader(root) { | |
| 39 bitmap_uploader.Init(shell); | |
| 40 } | |
| 41 | |
| 42 View* root; | |
| 43 ServiceProviderPtr embedder_service_provider; | |
| 44 BitmapUploader bitmap_uploader; | |
| 45 }; | |
| 46 | |
| 47 class EmbeddedApp | |
| 48 : public ApplicationDelegate, | |
| 49 public ViewManagerDelegate, | |
| 50 public ViewObserver { | |
| 51 public: | |
| 52 EmbeddedApp() : shell_(nullptr) { url::AddStandardScheme("mojo"); } | |
| 53 ~EmbeddedApp() override {} | |
| 54 | |
| 55 private: | |
| 56 | |
| 57 // Overridden from ApplicationDelegate: | |
| 58 void Initialize(ApplicationImpl* app) override { | |
| 59 shell_ = app->shell(); | |
| 60 view_manager_client_factory_.reset( | |
| 61 new ViewManagerClientFactory(app->shell(), this)); | |
| 62 } | |
| 63 | |
| 64 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { | |
| 65 connection->AddService(view_manager_client_factory_.get()); | |
| 66 return true; | |
| 67 } | |
| 68 | |
| 69 // Overridden from ViewManagerDelegate: | |
| 70 void OnEmbed(View* root, | |
| 71 InterfaceRequest<ServiceProvider> services, | |
| 72 ServiceProviderPtr exposed_services) override { | |
| 73 root->AddObserver(this); | |
| 74 Window* window = new Window(root, exposed_services.Pass(), shell_); | |
| 75 windows_[root->id()] = window; | |
| 76 window->bitmap_uploader.SetColor( | |
| 77 kColors[next_color_++ % arraysize(kColors)]); | |
| 78 } | |
| 79 void OnViewManagerDisconnected(ViewManager* view_manager) override { | |
| 80 base::MessageLoop::current()->Quit(); | |
| 81 } | |
| 82 | |
| 83 // Overridden from ViewObserver: | |
| 84 void OnViewDestroyed(View* view) override { | |
| 85 DCHECK(windows_.find(view->id()) != windows_.end()); | |
| 86 windows_.erase(view->id()); | |
| 87 } | |
| 88 void OnViewInputEvent(View* view, const EventPtr& event) override { | |
| 89 if (event->action == EventType::POINTER_UP && | |
| 90 (static_cast<uint32_t>(event->flags) & | |
| 91 static_cast<uint32_t>(EventFlags::LEFT_MOUSE_BUTTON))) { | |
| 92 URLRequestPtr request(URLRequest::New()); | |
| 93 request->url = "http://www.aaronboodman.com/z_dropbox/test.html"; | |
| 94 NavigatorHostPtr navigator_host; | |
| 95 ConnectToService(windows_[view->id()]->embedder_service_provider.get(), | |
| 96 &navigator_host); | |
| 97 navigator_host->RequestNavigate(Target::SOURCE_NODE, request.Pass()); | |
| 98 } | |
| 99 } | |
| 100 | |
| 101 Shell* shell_; | |
| 102 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; | |
| 103 | |
| 104 typedef std::map<Id, Window*> WindowMap; | |
| 105 WindowMap windows_; | |
| 106 | |
| 107 int next_color_; | |
| 108 | |
| 109 DISALLOW_COPY_AND_ASSIGN(EmbeddedApp); | |
| 110 }; | |
| 111 | |
| 112 } // namespace examples | |
| 113 } // namespace mojo | |
| 114 | |
| 115 MojoResult MojoMain(MojoHandle application_request) { | |
| 116 mojo::ApplicationRunnerChromium runner(new mojo::examples::EmbeddedApp); | |
| 117 return runner.Run(application_request); | |
| 118 } | |
| OLD | NEW |