1 // Copyright 2015 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.
5 #ifndef MOJO_PACKAGE_MANAGER_PACKAGE_MANAGER_IMPL_H_
6 #define MOJO_PACKAGE_MANAGER_PACKAGE_MANAGER_IMPL_H_
8 #include "base/files/file_path.h"
9 #include "mojo/fetcher/url_resolver.h"
10 #include "mojo/services/network/public/interfaces/network_service.mojom.h"
11 #include "mojo/services/network/public/interfaces/url_loader_factory.mojom.h"
12 #include "mojo/shell/package_manager.h"
18 namespace package_manager
{
20 // This is the default implementation of shell::PackageManager. It loads
21 // http/s urls off the network as well as providing special handling for mojo:
23 class PackageManagerImpl
: public shell::PackageManager
{
25 // mojo: urls are only supported if |shell_file_root| is non-empty.
26 explicit PackageManagerImpl(const base::FilePath
& shell_file_root
);
27 ~PackageManagerImpl() override
;
29 // Register a content handler to handle content of |mime_type|.
30 void RegisterContentHandler(const std::string
& mime_type
,
31 const GURL
& content_handler_url
);
33 // Registers a package alias. When attempting to load |alias|, it will
34 // instead redirect to |content_handler_package|, which is a content handler
35 // which will be passed the |alias| as the URLResponse::url. Different values
36 // of |alias| with the same |qualifier| that are in the same
37 // |content_handler_package| will run in the same process in multi-process
39 void RegisterApplicationPackageAlias(
41 const GURL
& content_handler_package
,
42 const std::string
& qualifier
);
45 using ApplicationPackagedAlias
= std::map
<GURL
, std::pair
<GURL
, std::string
>>;
46 using MimeTypeToURLMap
= std::map
<std::string
, GURL
>;
48 // Overridden from shell::PackageManager:
49 void SetApplicationManager(shell::ApplicationManager
* manager
) override
;
51 URLRequestPtr request
,
52 const shell::Fetcher::FetchCallback
& loader_callback
) override
;
53 bool HandleWithContentHandler(shell::Fetcher
* fetcher
,
55 base::TaskRunner
* task_runner
,
56 URLResponsePtr
* new_response
,
57 GURL
* content_handler_url
,
58 std::string
* qualifier
) override
;
60 GURL
ResolveURL(const GURL
& url
);
62 shell::ApplicationManager
* application_manager_
;
63 scoped_ptr
<fetcher::URLResolver
> url_resolver_
;
64 const bool disable_cache_
;
65 NetworkServicePtr network_service_
;
66 URLLoaderFactoryPtr url_loader_factory_
;
67 ApplicationPackagedAlias application_package_alias_
;
68 MimeTypeToURLMap mime_type_to_url_
;
70 DISALLOW_COPY_AND_ASSIGN(PackageManagerImpl
);
73 } // namespace package_manager
76 #endif // MOJO_PACKAGE_MANAGER_PACKAGE_MANAGER_IMPL_H_