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

Side by Side Diff: mojo/shell/application_manager.h

Issue 1311353005: Adds a way to determine id of content handler that created app (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tweaks Created 5 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef SHELL_APPLICATION_MANAGER_APPLICATION_MANAGER_H_ 5 #ifndef SHELL_APPLICATION_MANAGER_APPLICATION_MANAGER_H_
6 #define SHELL_APPLICATION_MANAGER_APPLICATION_MANAGER_H_ 6 #define SHELL_APPLICATION_MANAGER_APPLICATION_MANAGER_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "mojo/application/public/interfaces/application.mojom.h" 14 #include "mojo/application/public/interfaces/application.mojom.h"
15 #include "mojo/application/public/interfaces/service_provider.mojom.h" 15 #include "mojo/application/public/interfaces/service_provider.mojom.h"
16 #include "mojo/application/public/interfaces/shell.mojom.h"
16 #include "mojo/public/cpp/bindings/interface_ptr_info.h" 17 #include "mojo/public/cpp/bindings/interface_ptr_info.h"
17 #include "mojo/public/cpp/bindings/interface_request.h" 18 #include "mojo/public/cpp/bindings/interface_request.h"
18 #include "mojo/services/network/public/interfaces/network_service.mojom.h" 19 #include "mojo/services/network/public/interfaces/network_service.mojom.h"
19 #include "mojo/services/network/public/interfaces/url_loader_factory.mojom.h" 20 #include "mojo/services/network/public/interfaces/url_loader_factory.mojom.h"
20 #include "mojo/services/updater/updater.mojom.h" 21 #include "mojo/services/updater/updater.mojom.h"
21 #include "mojo/shell/application_loader.h" 22 #include "mojo/shell/application_loader.h"
22 #include "mojo/shell/capability_filter.h" 23 #include "mojo/shell/capability_filter.h"
23 #include "mojo/shell/fetcher.h" 24 #include "mojo/shell/fetcher.h"
24 #include "mojo/shell/identity.h" 25 #include "mojo/shell/identity.h"
25 #include "mojo/shell/native_runner.h" 26 #include "mojo/shell/native_runner.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 static bool HasCreatedInstance(); 69 static bool HasCreatedInstance();
69 // Returns true if there is a ApplicationInstance for this URL. 70 // Returns true if there is a ApplicationInstance for this URL.
70 bool HasRunningInstanceForURL(const GURL& url) const; 71 bool HasRunningInstanceForURL(const GURL& url) const;
71 72
72 private: 73 private:
73 ApplicationManager* manager_; 74 ApplicationManager* manager_;
74 75
75 DISALLOW_COPY_AND_ASSIGN(TestAPI); 76 DISALLOW_COPY_AND_ASSIGN(TestAPI);
76 }; 77 };
77 78
79 static const uint32_t kInvalidContentHandlerID = 0u;
80
78 explicit ApplicationManager(Delegate* delegate); 81 explicit ApplicationManager(Delegate* delegate);
79 ~ApplicationManager(); 82 ~ApplicationManager();
80 83
81 // Loads a service if necessary and establishes a new client connection. 84 // Loads a service if necessary and establishes a new client connection.
82 // |originator| can be NULL (e.g. for the first application or in tests), but 85 // |originator| can be NULL (e.g. for the first application or in tests), but
83 // typically is non-NULL and identifies the instance initiating the 86 // typically is non-NULL and identifies the instance initiating the
84 // connection. 87 // connection.
85 void ConnectToApplication(ApplicationInstance* originator, 88 // If this request is from a content handler then
86 URLRequestPtr requested_url, 89 // |requesting_content_handler_id| is the id of the content handler. If this
87 const std::string& qualifier, 90 // request is not from a content handler, |requesting_content_handler_id| is
88 const GURL& requestor_url, 91 // kInvalidContentHandlerID.
89 InterfaceRequest<ServiceProvider> services, 92 void ConnectToApplication(
90 ServiceProviderPtr exposed_services, 93 ApplicationInstance* originator,
91 const CapabilityFilter& capability_filter, 94 URLRequestPtr requested_url,
92 const base::Closure& on_application_end); 95 const std::string& qualifier,
96 const GURL& requestor_url,
97 uint32_t requesting_content_handler_id,
98 InterfaceRequest<ServiceProvider> services,
99 ServiceProviderPtr exposed_services,
100 const CapabilityFilter& capability_filter,
101 const base::Closure& on_application_end,
102 const Shell::ConnectToApplicationCallback& connect_callback);
93 103
94 // Must only be used by shell internals and test code as it does not forward 104 // Must only be used by shell internals and test code as it does not forward
95 // capability filters. 105 // capability filters.
96 template <typename Interface> 106 template <typename Interface>
97 inline void ConnectToService(const GURL& application_url, 107 inline void ConnectToService(const GURL& application_url,
98 InterfacePtr<Interface>* ptr) { 108 InterfacePtr<Interface>* ptr) {
99 ScopedMessagePipeHandle service_handle = 109 ScopedMessagePipeHandle service_handle =
100 ConnectToServiceByName(application_url, Interface::Name_); 110 ConnectToServiceByName(application_url, Interface::Name_);
101 ptr->Bind(InterfacePtrInfo<Interface>(service_handle.Pass(), 0u)); 111 ptr->Bind(InterfacePtrInfo<Interface>(service_handle.Pass(), 0u));
102 } 112 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 using ApplicationPackagedAlias = std::map<GURL, std::pair<GURL, std::string>>; 170 using ApplicationPackagedAlias = std::map<GURL, std::pair<GURL, std::string>>;
161 using IdentityToApplicationInstanceMap = 171 using IdentityToApplicationInstanceMap =
162 std::map<Identity, ApplicationInstance*>; 172 std::map<Identity, ApplicationInstance*>;
163 using MimeTypeToURLMap = std::map<std::string, GURL>; 173 using MimeTypeToURLMap = std::map<std::string, GURL>;
164 using SchemeToLoaderMap = std::map<std::string, ApplicationLoader*>; 174 using SchemeToLoaderMap = std::map<std::string, ApplicationLoader*>;
165 using URLToContentHandlerMap = 175 using URLToContentHandlerMap =
166 std::map<std::pair<GURL, std::string>, ContentHandlerConnection*>; 176 std::map<std::pair<GURL, std::string>, ContentHandlerConnection*>;
167 using URLToLoaderMap = std::map<GURL, ApplicationLoader*>; 177 using URLToLoaderMap = std::map<GURL, ApplicationLoader*>;
168 using URLToNativeOptionsMap = std::map<GURL, NativeRunnerFactory::Options>; 178 using URLToNativeOptionsMap = std::map<GURL, NativeRunnerFactory::Options>;
169 179
170 bool ConnectToRunningApplication(ApplicationInstance* originator, 180 bool ConnectToRunningApplication(
171 const GURL& resolved_url, 181 ApplicationInstance* originator,
172 const std::string& qualifier, 182 const GURL& resolved_url,
173 const GURL& requestor_url, 183 const std::string& qualifier,
174 InterfaceRequest<ServiceProvider>* services, 184 const GURL& requestor_url,
175 ServiceProviderPtr* exposed_services, 185 InterfaceRequest<ServiceProvider>* services,
176 const CapabilityFilter& filter); 186 ServiceProviderPtr* exposed_services,
187 const CapabilityFilter& filter,
188 const Shell::ConnectToApplicationCallback& connect_callback);
177 189
178 bool ConnectToApplicationWithLoader( 190 bool ConnectToApplicationWithLoader(
179 ApplicationInstance* originator, 191 ApplicationInstance* originator,
180 const GURL& requested_url, 192 const GURL& requested_url,
181 const std::string& qualifier, 193 const std::string& qualifier,
182 const GURL& resolved_url, 194 const GURL& resolved_url,
183 const GURL& requestor_url, 195 const GURL& requestor_url,
196 uint32_t requesting_content_handler_id,
184 InterfaceRequest<ServiceProvider>* services, 197 InterfaceRequest<ServiceProvider>* services,
185 ServiceProviderPtr* exposed_services, 198 ServiceProviderPtr* exposed_services,
186 const CapabilityFilter& filter, 199 const CapabilityFilter& filter,
187 const base::Closure& on_application_end, 200 const base::Closure& on_application_end,
201 const Shell::ConnectToApplicationCallback& connect_callback,
188 ApplicationLoader* loader); 202 ApplicationLoader* loader);
189 203
190 InterfaceRequest<Application> RegisterInstance( 204 InterfaceRequest<Application> RegisterInstance(
191 ApplicationInstance* originator, 205 ApplicationInstance* originator,
192 const GURL& app_url, 206 const GURL& app_url,
193 const std::string& qualifier, 207 const std::string& qualifier,
194 const GURL& requestor_url, 208 const GURL& requestor_url,
209 const uint32_t requesting_content_handler_id,
195 InterfaceRequest<ServiceProvider> services, 210 InterfaceRequest<ServiceProvider> services,
196 ServiceProviderPtr exposed_services, 211 ServiceProviderPtr exposed_services,
197 const CapabilityFilter& filter, 212 const CapabilityFilter& filter,
198 const base::Closure& on_application_end); 213 const base::Closure& on_application_end,
214 const Shell::ConnectToApplicationCallback& connect_callback,
215 ApplicationInstance** resulting_instance);
199 216
200 // Called once |fetcher| has found app. |requested_url| is the url of the 217 // Called once |fetcher| has found app. |requested_url| is the url of the
201 // requested application before any mappings/resolution have been applied. 218 // requested application before any mappings/resolution have been applied.
202 void HandleFetchCallback(ApplicationInstance* originator, 219 void HandleFetchCallback(
203 const GURL& requested_url, 220 ApplicationInstance* originator,
204 const std::string& qualifier, 221 const GURL& requested_url,
205 const GURL& requestor_url, 222 const std::string& qualifier,
206 InterfaceRequest<ServiceProvider> services, 223 const GURL& requestor_url,
207 ServiceProviderPtr exposed_services, 224 uint32_t requesting_content_handler_id,
208 const CapabilityFilter& filter, 225 InterfaceRequest<ServiceProvider> services,
209 const base::Closure& on_application_end, 226 ServiceProviderPtr exposed_services,
210 NativeApplicationCleanup cleanup, 227 const CapabilityFilter& filter,
211 scoped_ptr<Fetcher> fetcher); 228 const base::Closure& on_application_end,
229 const Shell::ConnectToApplicationCallback& connect_callback,
230 NativeApplicationCleanup cleanup,
231 scoped_ptr<Fetcher> fetcher);
212 232
213 void RunNativeApplication(InterfaceRequest<Application> application_request, 233 void RunNativeApplication(InterfaceRequest<Application> application_request,
214 bool start_sandboxed, 234 bool start_sandboxed,
215 const NativeRunnerFactory::Options& options, 235 const NativeRunnerFactory::Options& options,
216 NativeApplicationCleanup cleanup, 236 NativeApplicationCleanup cleanup,
217 scoped_ptr<Fetcher> fetcher, 237 scoped_ptr<Fetcher> fetcher,
218 const base::FilePath& file_path, 238 const base::FilePath& file_path,
219 bool path_exists); 239 bool path_exists);
220 240
221 void LoadWithContentHandler(ApplicationInstance* originator, 241 void LoadWithContentHandler(
222 const GURL& content_handler_url, 242 ApplicationInstance* originator,
223 const GURL& requestor_url, 243 const GURL& content_handler_url,
224 const std::string& qualifier, 244 const GURL& requestor_url,
225 const CapabilityFilter& filter, 245 const std::string& qualifier,
226 InterfaceRequest<Application> application_request, 246 const CapabilityFilter& filter,
227 URLResponsePtr url_response); 247 const Shell::ConnectToApplicationCallback& connect_callback,
248 ApplicationInstance* app,
249 InterfaceRequest<Application> application_request,
250 URLResponsePtr url_response);
228 251
229 // Returns the appropriate loader for |url|, or null if there is no loader 252 // Returns the appropriate loader for |url|, or null if there is no loader
230 // configured for the URL. 253 // configured for the URL.
231 ApplicationLoader* GetLoaderForURL(const GURL& url); 254 ApplicationLoader* GetLoaderForURL(const GURL& url);
232 255
233 void CleanupRunner(NativeRunner* runner); 256 void CleanupRunner(NativeRunner* runner);
234 257
235 ScopedMessagePipeHandle ConnectToServiceByName( 258 ScopedMessagePipeHandle ConnectToServiceByName(
236 const GURL& application_url, 259 const GURL& application_url,
237 const std::string& interface_name); 260 const std::string& interface_name);
(...skipping 12 matching lines...) Expand all
250 // Note: The keys are URLs after mapping and resolving. 273 // Note: The keys are URLs after mapping and resolving.
251 URLToNativeOptionsMap url_to_native_options_; 274 URLToNativeOptionsMap url_to_native_options_;
252 275
253 base::SequencedWorkerPool* blocking_pool_; 276 base::SequencedWorkerPool* blocking_pool_;
254 NetworkServicePtr network_service_; 277 NetworkServicePtr network_service_;
255 URLLoaderFactoryPtr url_loader_factory_; 278 URLLoaderFactoryPtr url_loader_factory_;
256 updater::UpdaterPtr updater_; 279 updater::UpdaterPtr updater_;
257 MimeTypeToURLMap mime_type_to_url_; 280 MimeTypeToURLMap mime_type_to_url_;
258 ScopedVector<NativeRunner> native_runners_; 281 ScopedVector<NativeRunner> native_runners_;
259 bool disable_cache_; 282 bool disable_cache_;
283 // Counter used to assign ids to content_handlers.
284 uint32_t content_handler_id_counter_;
260 base::WeakPtrFactory<ApplicationManager> weak_ptr_factory_; 285 base::WeakPtrFactory<ApplicationManager> weak_ptr_factory_;
261 286
262 DISALLOW_COPY_AND_ASSIGN(ApplicationManager); 287 DISALLOW_COPY_AND_ASSIGN(ApplicationManager);
263 }; 288 };
264 289
290 Shell::ConnectToApplicationCallback EmptyConnectCallback();
291
265 } // namespace shell 292 } // namespace shell
266 } // namespace mojo 293 } // namespace mojo
267 294
268 #endif // SHELL_APPLICATION_MANAGER_APPLICATION_MANAGER_H_ 295 #endif // SHELL_APPLICATION_MANAGER_APPLICATION_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698