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
3 // found in the LICENSE file.
5 #import "ios/web/net/clients/crw_passkit_network_client_factory.h"
7 #import "ios/web/net/clients/crw_passkit_network_client.h"
8 #include "ios/web/net/request_tracker_impl.h"
9 #include "ios/web/public/web_thread.h"
10 #include "net/http/http_response_headers.h"
11 #include "net/url_request/url_request.h"
13 @implementation CRWPassKitNetworkClientFactory {
14 // Delegate that's passed on to any created clients.
15 id<CRWPassKitDelegate> _delegate;
16 web::RequestTrackerImpl* _tracker;
19 - (Class)clientClass {
20 return [CRWPassKitNetworkClient class];
23 - (CRNForwardingNetworkClient*)
24 clientHandlingResponse:(NSURLResponse*)response
25 request:(const net::URLRequest&)request {
26 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::IO);
28 // Some requests (e.g., for chrome:// urls) will not have response headers.
29 net::HttpResponseHeaders* responseHeaders = request.response_headers();
34 BOOL hasMimeType = responseHeaders->GetMimeType(&mimeType);
35 if (hasMimeType && mimeType == "application/vnd.apple.pkpass") {
36 return [[[CRWPassKitNetworkClient alloc]
37 initWithTracker:_tracker->GetWeakPtr()
38 delegate:_delegate] autorelease];
44 - (instancetype)initWithDelegate:(id<CRWPassKitDelegate>)delegate
45 tracker:(web::RequestTrackerImpl*)tracker {
46 if ((self = [super init])) {