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

Unified Diff: mojo/shell/context.cc

Issue 423963004: First cut at "content handling" support in Mojo. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more gn Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/services/window_manager/window_manager_api_unittest.cc ('k') | mojo/shell/dbus_service_loader_linux.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/shell/context.cc
diff --git a/mojo/shell/context.cc b/mojo/shell/context.cc
index 76cc7d6f548bf2cc4219ec0782239d8be05c304d..a6dea440434f5dcb109a1a1622eafb439b8f45e6 100644
--- a/mojo/shell/context.cc
+++ b/mojo/shell/context.cc
@@ -4,10 +4,13 @@
#include "mojo/shell/context.h"
+#include <vector>
+
#include "build/build_config.h"
#include "base/command_line.h"
#include "base/lazy_instance.h"
#include "base/memory/scoped_vector.h"
+#include "base/strings/string_split.h"
#include "mojo/embedder/embedder.h"
#include "mojo/gles2/gles2_support_impl.h"
#include "mojo/public/cpp/application/application_impl.h"
@@ -61,6 +64,32 @@ class Setup {
static base::LazyInstance<Setup>::Leaky setup = LAZY_INSTANCE_INITIALIZER;
+void InitContentHandlers(DynamicServiceLoader* loader,
+ base::CommandLine* command_line) {
+ std::string handlers_spec = command_line->GetSwitchValueASCII(
+ switches::kContentHandlers);
+ if (handlers_spec.empty())
+ return;
+
+ std::vector<std::string> parts;
+ base::SplitString(handlers_spec, ',', &parts);
+ if (parts.size() % 2 != 0) {
+ LOG(ERROR) << "Invalid value for switch " << switches::kContentHandlers
+ << ": must be a comma-separated list of mimetype/url pairs.";
+ return;
+ }
+
+ for (size_t i = 0; i < parts.size(); i += 2) {
+ GURL url(parts[i + 1]);
+ if (!url.is_valid()) {
+ LOG(ERROR) << "Invalid value for switch " << switches::kContentHandlers
+ << ": '" << parts[i + 1] << "' is not a valid URL.";
+ return;
+ }
+ loader->RegisterContentHandler(parts[i], url);
+ }
+}
+
} // namespace
class Context::NativeViewportServiceLoader : public ServiceLoader {
@@ -69,10 +98,12 @@ class Context::NativeViewportServiceLoader : public ServiceLoader {
virtual ~NativeViewportServiceLoader() {}
private:
- virtual void LoadService(ServiceManager* manager,
- const GURL& url,
- ScopedMessagePipeHandle shell_handle) OVERRIDE {
- app_.reset(services::CreateNativeViewportService(shell_handle.Pass()));
+ virtual void Load(ServiceManager* manager,
+ const GURL& url,
+ scoped_refptr<LoadCallbacks> callbacks) OVERRIDE {
+ ScopedMessagePipeHandle shell_handle = callbacks->RegisterApplication();
+ if (shell_handle.is_valid())
+ app_.reset(services::CreateNativeViewportService(shell_handle.Pass()));
}
virtual void OnServiceError(ServiceManager* manager,
@@ -95,16 +126,19 @@ void Context::Init() {
for (size_t i = 0; i < arraysize(kLocalMojoURLs); ++i)
mojo_url_resolver_.AddLocalFileMapping(GURL(kLocalMojoURLs[i]));
- base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
+ base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
scoped_ptr<DynamicServiceRunnerFactory> runner_factory;
- if (cmdline->HasSwitch(switches::kEnableMultiprocess))
+ if (command_line->HasSwitch(switches::kEnableMultiprocess))
runner_factory.reset(new OutOfProcessDynamicServiceRunnerFactory());
else
runner_factory.reset(new InProcessDynamicServiceRunnerFactory());
+ DynamicServiceLoader* dynamic_service_loader =
+ new DynamicServiceLoader(this, runner_factory.Pass());
+ InitContentHandlers(dynamic_service_loader, command_line);
service_manager_.set_default_loader(
- scoped_ptr<ServiceLoader>(
- new DynamicServiceLoader(this, runner_factory.Pass())));
+ scoped_ptr<ServiceLoader>(dynamic_service_loader));
+
// The native viewport service synchronously waits for certain messages. If we
// don't run it on its own thread we can easily deadlock. Long term native
// viewport should run its own process so that this isn't an issue.
@@ -140,9 +174,9 @@ void Context::Init() {
"dbus");
#endif // defined(OS_LINUX)
- if (cmdline->HasSwitch(switches::kSpy)) {
- spy_.reset(new mojo::Spy(&service_manager_,
- cmdline->GetSwitchValueASCII(switches::kSpy)));
+ if (command_line->HasSwitch(switches::kSpy)) {
+ spy_.reset(new mojo::Spy(
+ &service_manager_, command_line->GetSwitchValueASCII(switches::kSpy)));
}
#if defined(OS_ANDROID)
« no previous file with comments | « mojo/services/window_manager/window_manager_api_unittest.cc ('k') | mojo/shell/dbus_service_loader_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698