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

Side by Side Diff: content/browser/loader/resource_dispatcher_host_impl.h

Issue 2182633007: Avoid using ContentBrowserClient::IsIllegalOrigin in ResourceDispatcherHost. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove the IsIllegalOrigin function from ContentBrowserClient Created 4 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // This is the browser side of the resource dispatcher, it receives requests 5 // This is the browser side of the resource dispatcher, it receives requests
6 // from the child process (i.e. [Renderer, Plugin, Worker]ProcessHost), and 6 // from the child process (i.e. [Renderer, Plugin, Worker]ProcessHost), and
7 // dispatches them to URLRequests. It then forwards the messages from the 7 // dispatches them to URLRequests. It then forwards the messages from the
8 // URLRequests back to the correct process for handling. 8 // URLRequests back to the correct process for handling.
9 // 9 //
10 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading 10 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 RenderFrameHost* root_frame_host); 100 RenderFrameHost* root_frame_host);
101 101
102 // Cancels any blocked request for the frame and its subframes. 102 // Cancels any blocked request for the frame and its subframes.
103 static void CancelBlockedRequestsForFrameFromUI( 103 static void CancelBlockedRequestsForFrameFromUI(
104 RenderFrameHostImpl* root_frame_host); 104 RenderFrameHostImpl* root_frame_host);
105 105
106 // ResourceDispatcherHost implementation: 106 // ResourceDispatcherHost implementation:
107 void SetDelegate(ResourceDispatcherHostDelegate* delegate) override; 107 void SetDelegate(ResourceDispatcherHostDelegate* delegate) override;
108 void SetAllowCrossOriginAuthPrompt(bool value) override; 108 void SetAllowCrossOriginAuthPrompt(bool value) override;
109 void ClearLoginDelegateForRequest(net::URLRequest* request) override; 109 void ClearLoginDelegateForRequest(net::URLRequest* request) override;
110 110 void AddSchemeForAccessCheck(const std::string& scheme) override;
111 void RegisterOriginForAccessChecks(
112 const ResourceContext* context,
113 const std::string& origin,
114 OriginAccessCheckMask access_check_mask) override;
115 void UnregisterOriginForAccessChecks(const ResourceContext* context,
116 const std::string& origin) override;
117 void AddProcessForOrigin(const ResourceContext* context,
118 const std::string& origin,
119 int process_id,
120 bool owner_proces) override;
121 void RemoveProcessForOrigin(const ResourceContext* context,
122 const std::string& origin,
123 int process_id,
124 bool owner_process) override;
111 // Puts the resource dispatcher host in an inactive state (unable to begin 125 // Puts the resource dispatcher host in an inactive state (unable to begin
112 // new requests). Cancels all pending requests. 126 // new requests). Cancels all pending requests.
113 void Shutdown(); 127 void Shutdown();
114 128
115 // Force cancels any pending requests for the given |context|. This is 129 // Force cancels any pending requests for the given |context|. This is
116 // necessary to ensure that before |context| goes away, all requests 130 // necessary to ensure that before |context| goes away, all requests
117 // for it are dead. 131 // for it are dead.
118 void CancelRequestsForContext(ResourceContext* context); 132 void CancelRequestsForContext(ResourceContext* context);
119 133
120 // Returns true if the message was a resource message that was processed. 134 // Returns true if the message was a resource message that was processed.
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 // Turns on stale-while-revalidate support, regardless of command-line flags 299 // Turns on stale-while-revalidate support, regardless of command-line flags
286 // or experiment status. For unit tests only. 300 // or experiment status. For unit tests only.
287 void EnableStaleWhileRevalidateForTesting(); 301 void EnableStaleWhileRevalidateForTesting();
288 302
289 // Sets the LoaderDelegate, which must outlive this object. Ownership is not 303 // Sets the LoaderDelegate, which must outlive this object. Ownership is not
290 // transferred. The LoaderDelegate should be interacted with on the IO thread. 304 // transferred. The LoaderDelegate should be interacted with on the IO thread.
291 void SetLoaderDelegate(LoaderDelegate* loader_delegate); 305 void SetLoaderDelegate(LoaderDelegate* loader_delegate);
292 306
293 void OnRenderFrameDeleted(const GlobalFrameRoutingId& global_routing_id); 307 void OnRenderFrameDeleted(const GlobalFrameRoutingId& global_routing_id);
294 308
309 // Checks whether the child process identified by |child_process_id| is
310 // allowed to access the |origin| and returns true if not.
311 // 1. If the |origin| scheme is not registered then it is allowed.
312 // 2. If the |origin| host is not registered, then it is denied.
313 // 3. If the |child_process_id| is in the list of owner processes for the
314 // |origin| it is allowed. Please see OriginAccessInfo defined above for
Charlie Reis 2016/08/09 02:07:48 nit: Below?
315 // more information.
316 // 4. If the origin access mask is DENY_FOR_NON_OWNERS it is denied.
317 // 5. If the origin access mask is ALLOW_EVERYTHING it is allowed.
318 // 6. If the |child_process_id| is in the list of other processes for the
319 // |origin| and there are publicly available resources it is allowed.
Charlie Reis 2016/08/09 02:07:48 Hmm. This is hard to understand in the abstract w
320 // Please see OriginAccessInfo defined above for more information.
321 // 5. Deny if all checks above fail.
322 bool IsIllegalOrigin(ResourceContext* context,
323 const GURL& origin,
324 int child_process_id);
325
295 private: 326 private:
296 friend class ResourceDispatcherHostTest; 327 friend class ResourceDispatcherHostTest;
297 328
298 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, 329 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest,
299 TestBlockedRequestsProcessDies); 330 TestBlockedRequestsProcessDies);
300 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, 331 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest,
301 CalculateApproximateMemoryCost); 332 CalculateApproximateMemoryCost);
302 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, 333 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest,
303 DetachableResourceTimesOut); 334 DetachableResourceTimesOut);
304 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, 335 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest,
(...skipping 13 matching lines...) Expand all
318 struct LoadInfo { 349 struct LoadInfo {
319 GURL url; 350 GURL url;
320 net::LoadStateWithParam load_state; 351 net::LoadStateWithParam load_state;
321 uint64_t upload_position; 352 uint64_t upload_position;
322 uint64_t upload_size; 353 uint64_t upload_size;
323 }; 354 };
324 355
325 // Map from ProcessID+RouteID pair to the "most interesting" LoadState. 356 // Map from ProcessID+RouteID pair to the "most interesting" LoadState.
326 typedef std::map<GlobalRoutingID, LoadInfo> LoadInfoMap; 357 typedef std::map<GlobalRoutingID, LoadInfo> LoadInfoMap;
327 358
359 // Contains information about an origin which is used for access checks. This
360 // means whether a process committing a URL is allowed to do so. We determine
361 // this based on whether the process has been registered for the origin.
362 // We maintain two maps
363 // 1. A map of owner processes. These are allowed to commit the URL even if
364 // there are no publicly accessible resources.
365 // 2. A map of other processes. These are allowed to commit the URL only if
366 // there are public resources.
367 struct OriginAccessInfo {
368 // This structure is complicated enough for clang to require the ctors to
369 // be explicitly defined in the cc file.
370 OriginAccessInfo();
371 ~OriginAccessInfo();
372 OriginAccessInfo(const OriginAccessInfo& other);
373
374 // Controls which can processes can commit the origin.
375 // By default owners can commit everything.
376 OriginAccessCheckMask access_check_mask;
377 // A process may be reused across multiple SiteInstances or routing ids.
378 // This means that a process could be added and removed multiple times for
379 // an origin via the AddProcessForOrigin() an RemoveProcessForOrigin()
380 // methods. To ensure that this works correctly we maintain a map of
381 // process id to refcount. The process id is removed from the map when the
382 // refcount drops to 0.
383 std::map<int, int> owner_processes;
384 std::map<int, int> other_processes;
385 };
386
387 // Map from the origin host (std::string) to the OriginAccessInfo structure
388 // defined above.
389 // This map is per ResourceContext.
390 typedef std::map<std::string, OriginAccessInfo> OriginAccessInfoMap;
391
392 typedef std::map<const ResourceContext*,
393 std::unique_ptr<OriginAccessInfoMap>>
394 ResourceContextOriginMap;
395
328 // ResourceLoaderDelegate implementation: 396 // ResourceLoaderDelegate implementation:
329 ResourceDispatcherHostLoginDelegate* CreateLoginDelegate( 397 ResourceDispatcherHostLoginDelegate* CreateLoginDelegate(
330 ResourceLoader* loader, 398 ResourceLoader* loader,
331 net::AuthChallengeInfo* auth_info) override; 399 net::AuthChallengeInfo* auth_info) override;
332 bool HandleExternalProtocol(ResourceLoader* loader, const GURL& url) override; 400 bool HandleExternalProtocol(ResourceLoader* loader, const GURL& url) override;
333 void DidStartRequest(ResourceLoader* loader) override; 401 void DidStartRequest(ResourceLoader* loader) override;
334 void DidReceiveRedirect(ResourceLoader* loader, const GURL& new_url) override; 402 void DidReceiveRedirect(ResourceLoader* loader, const GURL& new_url) override;
335 void DidReceiveResponse(ResourceLoader* loader) override; 403 void DidReceiveResponse(ResourceLoader* loader) override;
336 void DidFinishLoading(ResourceLoader* loader) override; 404 void DidFinishLoading(ResourceLoader* loader) override;
337 std::unique_ptr<net::ClientCertStore> CreateClientCertStore( 405 std::unique_ptr<net::ClientCertStore> CreateClientCertStore(
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 // The certificate on a ResourceResponse is associated with a 598 // The certificate on a ResourceResponse is associated with a
531 // particular renderer process. As a transfer to a new process 599 // particular renderer process. As a transfer to a new process
532 // completes, the stored certificate has to be updated to reflect the 600 // completes, the stored certificate has to be updated to reflect the
533 // new renderer process. 601 // new renderer process.
534 void UpdateResponseCertificateForTransfer(ResourceResponse* response, 602 void UpdateResponseCertificateForTransfer(ResourceResponse* response,
535 const net::SSLInfo& ssl_info, 603 const net::SSLInfo& ssl_info,
536 int child_id); 604 int child_id);
537 605
538 CertStore* GetCertStore(); 606 CertStore* GetCertStore();
539 607
608 // Returns the OriginAccessInfoMap instance for the |context| passed in. This
609 // map is used to enforce access checks on web requests for some origins.
610 OriginAccessInfoMap* GetOriginAccessMapForResourceContext(
611 const ResourceContext* context);
612
540 LoaderMap pending_loaders_; 613 LoaderMap pending_loaders_;
541 614
542 // Collection of temp files downloaded for child processes via 615 // Collection of temp files downloaded for child processes via
543 // the download_to_file mechanism. We avoid deleting them until 616 // the download_to_file mechanism. We avoid deleting them until
544 // the client no longer needs them. 617 // the client no longer needs them.
545 typedef std::map<int, scoped_refptr<storage::ShareableFileReference> > 618 typedef std::map<int, scoped_refptr<storage::ShareableFileReference> >
546 DeletableFilesMap; // key is request id 619 DeletableFilesMap; // key is request id
547 typedef std::map<int, DeletableFilesMap> 620 typedef std::map<int, DeletableFilesMap>
548 RegisteredTempFiles; // key is child process id 621 RegisteredTempFiles; // key is child process id
549 RegisteredTempFiles registered_temp_files_; 622 RegisteredTempFiles registered_temp_files_;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 typedef std::map<GlobalRequestID, 697 typedef std::map<GlobalRequestID,
625 base::ObserverList<ResourceMessageDelegate>*> DelegateMap; 698 base::ObserverList<ResourceMessageDelegate>*> DelegateMap;
626 DelegateMap delegate_map_; 699 DelegateMap delegate_map_;
627 700
628 std::unique_ptr<ResourceScheduler> scheduler_; 701 std::unique_ptr<ResourceScheduler> scheduler_;
629 702
630 // Allows tests to use a mock CertStore. If set, the CertStore must 703 // Allows tests to use a mock CertStore. If set, the CertStore must
631 // outlive this ResourceDispatcherHostImpl. 704 // outlive this ResourceDispatcherHostImpl.
632 CertStore* cert_store_for_testing_; 705 CertStore* cert_store_for_testing_;
633 706
707 // Used to check whether a request to retrieve an origin resource is allowed.
708 // This is only done for origins which are to be checked for access.
709 ResourceContextOriginMap context_origin_access_info_map_;
710
711 // This contains the set of origins we need to enforce access checks on. By
712 // default everything is allowed.
713 std::set<std::string> origins_for_access_check_;
714
634 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); 715 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl);
635 }; 716 };
636 717
637 } // namespace content 718 } // namespace content
638 719
639 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ 720 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698