diff options
-rw-r--r-- | mojo/aura/window_tree_host_mojo.cc | 1 | ||||
-rw-r--r-- | mojo/examples/browser/browser.cc | 22 | ||||
-rw-r--r-- | mojo/examples/html_viewer/html_viewer.cc | 66 | ||||
-rw-r--r-- | mojo/mojo.gyp | 2 | ||||
-rw-r--r-- | mojo/mojo_examples.gypi | 19 | ||||
-rw-r--r-- | mojo/mojo_services.gypi | 33 | ||||
-rw-r--r-- | mojo/services/launcher/DEPS | 3 | ||||
-rw-r--r-- | mojo/services/launcher/launcher.cc | 159 | ||||
-rw-r--r-- | mojo/services/public/interfaces/launcher/launcher.mojom | 18 |
9 files changed, 321 insertions, 2 deletions
diff --git a/mojo/aura/window_tree_host_mojo.cc b/mojo/aura/window_tree_host_mojo.cc index 78dd923..2ee5f14e 100644 --- a/mojo/aura/window_tree_host_mojo.cc +++ b/mojo/aura/window_tree_host_mojo.cc @@ -99,7 +99,6 @@ ui::EventSource* WindowTreeHostMojo::GetEventSource() { } gfx::AcceleratedWidget WindowTreeHostMojo::GetAcceleratedWidget() { - NOTIMPLEMENTED() << "GetAcceleratedWidget"; return gfx::kNullAcceleratedWidget; } diff --git a/mojo/examples/browser/browser.cc b/mojo/examples/browser/browser.cc index 85a6bcb..9757d0f 100644 --- a/mojo/examples/browser/browser.cc +++ b/mojo/examples/browser/browser.cc @@ -9,19 +9,24 @@ #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" #include "mojo/services/public/cpp/view_manager/view_observer.h" #include "mojo/services/public/cpp/view_manager/view_tree_node.h" +#include "mojo/services/public/interfaces/launcher/launcher.mojom.h" #include "mojo/views/native_widget_view_manager.h" #include "mojo/views/views_init.h" #include "ui/views/controls/textfield/textfield.h" +#include "ui/views/controls/textfield/textfield_controller.h" #include "ui/views/layout/fill_layout.h" #include "ui/views/widget/widget.h" #include "ui/views/widget/widget_delegate.h" +#include "url/gurl.h" namespace mojo { namespace examples { // This is the basics of creating a views widget with a textfield. // TODO: cleanup! -class Browser : public Application, public view_manager::ViewManagerDelegate { +class Browser : public Application, + public view_manager::ViewManagerDelegate, + public views::TextfieldController { public: Browser() : view_manager_(NULL), view_(NULL) {} @@ -34,10 +39,13 @@ class Browser : public Application, public view_manager::ViewManagerDelegate { views_init_.reset(new ViewsInit); view_manager::ViewManager::Create(this, this); + + ConnectTo("mojo:mojo_launcher", &launcher_); } void CreateWidget() { views::Textfield* textfield = new views::Textfield; + textfield->set_controller(this); views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView; widget_delegate->GetContentsView()->AddChildView(textfield); @@ -67,10 +75,22 @@ class Browser : public Application, public view_manager::ViewManagerDelegate { view_manager::ViewTreeNode* root) OVERRIDE { } + // views::TextfieldController: + virtual bool HandleKeyEvent(views::Textfield* sender, + const ui::KeyEvent& key_event) OVERRIDE { + if (key_event.key_code() == ui::VKEY_RETURN) { + GURL url(sender->text()); + printf("User entered this URL: %s\n", url.spec().c_str()); + launcher_->Launch(url.spec()); + } + return false; + } + scoped_ptr<ViewsInit> views_init_; view_manager::ViewManager* view_manager_; view_manager::View* view_; + launcher::LauncherPtr launcher_; DISALLOW_COPY_AND_ASSIGN(Browser); }; diff --git a/mojo/examples/html_viewer/html_viewer.cc b/mojo/examples/html_viewer/html_viewer.cc new file mode 100644 index 0000000..ab41d95 --- /dev/null +++ b/mojo/examples/html_viewer/html_viewer.cc @@ -0,0 +1,66 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "mojo/public/cpp/application/application.h" +#include "mojo/services/public/interfaces/launcher/launcher.mojom.h" + +namespace mojo { +namespace examples { + +class HTMLViewer; + +class LaunchableConnection : public InterfaceImpl<launcher::Launchable> { + public: + LaunchableConnection() {} + virtual ~LaunchableConnection() {} + + private: + // Overridden from launcher::Launchable: + virtual void OnLaunch( + URLResponsePtr response, + ScopedDataPipeConsumerHandle response_body_stream) MOJO_OVERRIDE { + printf("In HTMLViewer, rendering url: %s\n", response->url.data()); + printf("HTML: \n"); + for (;;) { + char buf[512]; + uint32_t num_bytes = sizeof(buf); + MojoResult result = ReadDataRaw( + response_body_stream.get(), + buf, + &num_bytes, + MOJO_READ_DATA_FLAG_NONE); + if (result == MOJO_RESULT_SHOULD_WAIT) { + Wait(response_body_stream.get(), + MOJO_WAIT_FLAG_READABLE, + MOJO_DEADLINE_INDEFINITE); + } else if (result == MOJO_RESULT_OK) { + fwrite(buf, num_bytes, 1, stdout); + } else { + break; + } + } + printf("\n>>>> EOF <<<<\n\n"); + } +}; + +class HTMLViewer : public Application { + public: + HTMLViewer() {} + virtual ~HTMLViewer() {} + + private: + // Overridden from Application: + virtual void Initialize() MOJO_OVERRIDE { + AddService<LaunchableConnection>(); + } +}; + +} + +// static +Application* Application::Create() { + return new examples::HTMLViewer; +} + +} diff --git a/mojo/mojo.gyp b/mojo/mojo.gyp index 6bbe32f..0aedfdd 100644 --- a/mojo/mojo.gyp +++ b/mojo/mojo.gyp @@ -34,9 +34,11 @@ 'mojo_common_unittests', 'mojo_cpp_bindings', 'mojo_geometry_lib', + 'mojo_html_viewer', 'mojo_js', 'mojo_js_bindings', 'mojo_js_unittests', + 'mojo_launcher', 'mojo_message_generator', 'mojo_native_viewport_service', 'mojo_network_service', diff --git a/mojo/mojo_examples.gypi b/mojo/mojo_examples.gypi index ad96198..d7b9888 100644 --- a/mojo/mojo_examples.gypi +++ b/mojo/mojo_examples.gypi @@ -92,6 +92,23 @@ 'includes': [ 'build/package_app.gypi' ], }, { + 'target_name': 'mojo_html_viewer', + 'type': 'shared_library', + 'dependencies': [ + 'mojo_application', + 'mojo_cpp_bindings', + 'mojo_environment_standalone', + 'mojo_network_bindings', + 'mojo_launcher_bindings', + 'mojo_system', + 'mojo_utility', + ], + 'sources': [ + 'examples/html_viewer/html_viewer.cc', + 'public/cpp/application/lib/mojo_main_standalone.cc', + ], + }, + { 'target_name': 'mojo_pepper_container_app', 'type': 'shared_library', 'dependencies': [ @@ -247,6 +264,7 @@ '../ui/resources/ui_resources.gyp:ui_resources', '../ui/resources/ui_resources.gyp:ui_test_pak', '../ui/views/views.gyp:views', + '../url/url.gyp:url_lib', 'mojo_application', 'mojo_aura_support', 'mojo_common_lib', @@ -254,6 +272,7 @@ 'mojo_geometry_bindings', 'mojo_geometry_lib', 'mojo_input_events_lib', + 'mojo_launcher_bindings', 'mojo_system_impl', 'mojo_views_support', 'mojo_view_manager_bindings', diff --git a/mojo/mojo_services.gypi b/mojo/mojo_services.gypi index 7fe3af6..9c407ac 100644 --- a/mojo/mojo_services.gypi +++ b/mojo/mojo_services.gypi @@ -246,6 +246,39 @@ ], }, { + 'target_name': 'mojo_launcher_bindings', + 'type': 'static_library', + 'sources': [ + 'services/public/interfaces/launcher/launcher.mojom', + ], + 'includes': [ 'public/tools/bindings/mojom_bindings_generator.gypi' ], + 'export_dependent_settings': [ + 'mojo_cpp_bindings', + ], + 'dependencies': [ + 'mojo_cpp_bindings', + 'mojo_network_bindings', + ], + }, + { + 'target_name': 'mojo_launcher', + 'type': 'shared_library', + 'dependencies': [ + '../base/base.gyp:base', + 'mojo_application', + 'mojo_cpp_bindings', + 'mojo_environment_chromium', + 'mojo_launcher_bindings', + 'mojo_network_bindings', + 'mojo_system_impl', + 'mojo_utility', + ], + 'sources': [ + 'services/launcher/launcher.cc', + 'public/cpp/application/lib/mojo_main_chromium.cc', + ], + }, + { 'target_name': 'mojo_view_manager_bindings', 'type': 'static_library', 'sources': [ diff --git a/mojo/services/launcher/DEPS b/mojo/services/launcher/DEPS new file mode 100644 index 0000000..28f1ec1 --- /dev/null +++ b/mojo/services/launcher/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+mojo/services/public", +] diff --git a/mojo/services/launcher/launcher.cc b/mojo/services/launcher/launcher.cc new file mode 100644 index 0000000..3990425 --- /dev/null +++ b/mojo/services/launcher/launcher.cc @@ -0,0 +1,159 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/compiler_specific.h" +#include "base/message_loop/message_loop.h" +#include "base/strings/string_tokenizer.h" +#include "mojo/public/cpp/application/application.h" +#include "mojo/services/public/interfaces/launcher/launcher.mojom.h" +#include "mojo/services/public/interfaces/network/network_service.mojom.h" +#include "mojo/services/public/interfaces/network/url_loader.mojom.h" + +namespace mojo { +namespace launcher { + +class LauncherApp; + +class LauncherConnection : public InterfaceImpl<Launcher> { + public: + explicit LauncherConnection(LauncherApp* app) : app_(app) {} + virtual ~LauncherConnection() {} + + private: + // Overridden from Launcher: + virtual void Launch(const String& url) OVERRIDE; + + LauncherApp* app_; + + DISALLOW_COPY_AND_ASSIGN(LauncherConnection); +}; + +class Launch : public URLLoaderClient { + public: + Launch(LauncherApp* app, const String& url); + virtual ~Launch() {} + + private: + // Overridden from URLLoaderClient: + virtual void OnReceivedRedirect(URLResponsePtr response, + const String& new_url, + const String& new_method) OVERRIDE { + } + virtual void OnReceivedResponse(URLResponsePtr response) OVERRIDE; + virtual void OnReceivedError(NetworkErrorPtr error) OVERRIDE { + ScheduleDestroy(); + } + virtual void OnReceivedEndOfResponseBody() OVERRIDE { + ScheduleDestroy(); + } + + std::string GetContentType(const Array<String>& headers) { + for (size_t i = 0; i < headers.size(); ++i) { + base::StringTokenizer t(headers[i], ": ;="); + while (t.GetNext()) { + if (!t.token_is_delim() && t.token() == "Content-Type") { + while (t.GetNext()) { + if (!t.token_is_delim()) + return t.token(); + } + } + } + } + return ""; + } + + void ScheduleDestroy() { + if (destroy_scheduled_) + return; + destroy_scheduled_ = true; + base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); + } + + LauncherApp* app_; + bool destroy_scheduled_; + URLLoaderPtr url_loader_; + ScopedDataPipeConsumerHandle response_body_stream_; + LaunchablePtr launchable_; + + DISALLOW_COPY_AND_ASSIGN(Launch); +}; + +class LauncherApp : public Application { + public: + LauncherApp() { + handler_map_["text/html"] = "mojo:mojo_html_viewer"; + handler_map_["image/png"] = "mojo:mojo_image_viewer"; + } + virtual ~LauncherApp() {} + + void LaunchURL(const String& url) { + new Launch(this, url); + } + + URLLoaderPtr CreateURLLoader() { + URLLoaderPtr loader; + network_service_->CreateURLLoader(Get(&loader)); + return loader.Pass(); + } + + std::string GetHandlerForContentType(const std::string& content_type) { + HandlerMap::const_iterator it = handler_map_.find(content_type); + return it != handler_map_.end() ? it->second : ""; + } + + private: + typedef std::map<std::string, std::string> HandlerMap; + + // Overridden from Application: + virtual void Initialize() OVERRIDE { + AddService<LauncherConnection>(this); + ConnectTo("mojo:mojo_network_service", &network_service_); + } + + HandlerMap handler_map_; + + NetworkServicePtr network_service_; + + DISALLOW_COPY_AND_ASSIGN(LauncherApp); +}; + +void LauncherConnection::Launch(const String& url) { + app_->LaunchURL(url); +} + +Launch::Launch(LauncherApp* app, const String& url) + : app_(app), + destroy_scheduled_(false) { + url_loader_ = app_->CreateURLLoader(); + url_loader_.set_client(this); + + URLRequestPtr request(URLRequest::New()); + request->url = url; + request->method = "GET"; + request->auto_follow_redirects = true; + + DataPipe data_pipe; + response_body_stream_ = data_pipe.consumer_handle.Pass(); + + url_loader_->Start(request.Pass(), data_pipe.producer_handle.Pass()); +} + +void Launch::OnReceivedResponse(URLResponsePtr response) { + std::string content_type = GetContentType(response->headers); + std::string handler_url = app_->GetHandlerForContentType(content_type); + if (!handler_url.empty()) { + app_->ConnectTo(handler_url, &launchable_); + launchable_->OnLaunch(response.Pass(), response_body_stream_.Pass()); + } + ScheduleDestroy(); +} + +} // namespace launcher + +// static +Application* Application::Create() { + return new launcher::LauncherApp; +} + +} // namespace mojo diff --git a/mojo/services/public/interfaces/launcher/launcher.mojom b/mojo/services/public/interfaces/launcher/launcher.mojom new file mode 100644 index 0000000..7668f4e --- /dev/null +++ b/mojo/services/public/interfaces/launcher/launcher.mojom @@ -0,0 +1,18 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import "../network/url_loader.mojom" + +module mojo.launcher { + +interface Launcher { + Launch(string url); +}; + +interface Launchable { + OnLaunch(mojo.URLResponse response, + handle<data_pipe_consumer> response_body_stream); +}; + +} |