diff options
author | erg <erg@chromium.org> | 2015-05-01 11:25:55 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-01 18:27:25 +0000 |
commit | 2cf387a31df4df41581982d28d964eb9e1607496 (patch) | |
tree | 99313498115762cc500724840a8c3317b707eb53 /mojo | |
parent | 7256234c44027dc75dae1fbe31c9faeaee5aa376 (diff) | |
download | chromium_src-2cf387a31df4df41581982d28d964eb9e1607496.zip chromium_src-2cf387a31df4df41581982d28d964eb9e1607496.tar.gz chromium_src-2cf387a31df4df41581982d28d964eb9e1607496.tar.bz2 |
mojo: Use ContentHandlers to bundle multiple Applications into a module.
The previous way of implementing core_services worked by having a
ServiceProvider as the external interface. This fell down because the
boundary between Applications in mojo is meaningful and is used in the
ViewManager and the WindowManager to restrict access to some services.
The (possibly misnamed) ContentHandler interface, on the other hand,
looks like a possible avenue of attack. ContentHandler's one method
starts new Applications. So mojo:core_services should be a
ContentHandler instead of a ServiceProvider and will spawn an
Application for each internal service.
This currently hard codes the mapping in context.cc, but eventually, we
should do something more intelligent for the packaging. This patch also
doesn't handle spawning new applications on new threads as we don't have
multiple applications yet.
BUG=477435
Review URL: https://codereview.chromium.org/1115363002
Cr-Commit-Position: refs/heads/master@{#327947}
Diffstat (limited to 'mojo')
-rw-r--r-- | mojo/runner/context.cc | 5 | ||||
-rw-r--r-- | mojo/shell/application_manager.cc | 17 | ||||
-rw-r--r-- | mojo/shell/application_manager.h | 20 |
3 files changed, 36 insertions, 6 deletions
diff --git a/mojo/runner/context.cc b/mojo/runner/context.cc index 9f96cda..942b5dc 100644 --- a/mojo/runner/context.cc +++ b/mojo/runner/context.cc @@ -110,6 +110,11 @@ void InitContentHandlers(shell::ApplicationManager* manager, manager->RegisterContentHandler("image/png", GURL("mojo:png_viewer")); manager->RegisterContentHandler("text/html", GURL("mojo:html_viewer")); + // TODO(erg): We should probably handle this differently; these could be + // autogenerated from package manifests. + manager->RegisterApplicationPackageAlias(GURL("mojo:clipboard"), + GURL("mojo:core_services")); + // Command-line-specified content handlers. std::string handlers_spec = command_line.GetSwitchValueASCII(switches::kContentHandlers); diff --git a/mojo/shell/application_manager.cc b/mojo/shell/application_manager.cc index 3f51008..44a0c0d 100644 --- a/mojo/shell/application_manager.cc +++ b/mojo/shell/application_manager.cc @@ -313,6 +313,16 @@ void ApplicationManager::HandleFetchCallback( return; } + auto alias_iter = application_package_alias_.find(app_url); + if (alias_iter != application_package_alias_.end()) { + URLResponsePtr response(URLResponse::New()); + response->url = String::From(app_url.spec()); + LoadWithContentHandler(alias_iter->second, + request.Pass(), + response.Pass()); + return; + } + // TODO(aa): Sanity check that the thing we got looks vaguely like a mojo // application. That could either mean looking for the platform-specific dll // header, or looking for some specific mojo signature prepended to the @@ -370,6 +380,13 @@ void ApplicationManager::RegisterContentHandler( mime_type_to_url_[mime_type] = content_handler_url; } + +void ApplicationManager::RegisterApplicationPackageAlias( + const GURL& alias, + const GURL& content_handler_package) { + application_package_alias_[alias] = content_handler_package; +} + void ApplicationManager::LoadWithContentHandler( const GURL& content_handler_url, InterfaceRequest<Application> application_request, diff --git a/mojo/shell/application_manager.h b/mojo/shell/application_manager.h index ba1454c..5be3a41 100644 --- a/mojo/shell/application_manager.h +++ b/mojo/shell/application_manager.h @@ -89,6 +89,12 @@ class ApplicationManager { void RegisterContentHandler(const std::string& mime_type, const GURL& content_handler_url); + // Registers a package alias. When attempting to load |alias|, it will + // instead redirect to |content_handler_package|, which is a content handler + // which will be passed the |alias| as the URLResponse::url. + void RegisterApplicationPackageAlias(const GURL& alias, + const GURL& content_handler_package); + // Sets the default Loader to be used if not overridden by SetLoaderForURL() // or SetLoaderForScheme(). void set_default_loader(scoped_ptr<ApplicationLoader> loader) { @@ -128,12 +134,13 @@ class ApplicationManager { private: class ContentHandlerConnection; - typedef std::map<std::string, ApplicationLoader*> SchemeToLoaderMap; - typedef std::map<GURL, ApplicationLoader*> URLToLoaderMap; - typedef std::map<Identity, ShellImpl*> IdentityToShellImplMap; - typedef std::map<GURL, ContentHandlerConnection*> URLToContentHandlerMap; - typedef std::map<std::string, GURL> MimeTypeToURLMap; - typedef std::map<GURL, NativeRunnerFactory::Options> URLToNativeOptionsMap; + using ApplicationPackagedAlias = std::map<GURL, GURL>; + using IdentityToShellImplMap = std::map<Identity, ShellImpl*>; + using MimeTypeToURLMap = std::map<std::string, GURL>; + using SchemeToLoaderMap = std::map<std::string, ApplicationLoader*>; + using URLToContentHandlerMap = std::map<GURL, ContentHandlerConnection*>; + using URLToLoaderMap = std::map<GURL, ApplicationLoader*>; + using URLToNativeOptionsMap = std::map<GURL, NativeRunnerFactory::Options>; void ConnectToApplicationWithParameters( const GURL& application_url, @@ -213,6 +220,7 @@ class ApplicationManager { scoped_ptr<ApplicationLoader> default_loader_; scoped_ptr<NativeRunnerFactory> native_runner_factory_; + ApplicationPackagedAlias application_package_alias_; IdentityToShellImplMap identity_to_shell_impl_; URLToContentHandlerMap url_to_content_handler_; // Note: The keys are URLs after mapping and resolving. |