OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #import "OmahaXMLParser.h" | 5 #import "OmahaXMLParser.h" |
6 | 6 |
7 @interface OmahaXMLParser ()<NSXMLParserDelegate> | 7 @interface OmahaXMLParser ()<NSXMLParserDelegate> |
8 @end | 8 @end |
9 | 9 |
10 @implementation OmahaXMLParser { | 10 @implementation OmahaXMLParser { |
11 NSMutableArray* chromeIncompleteDownloadURLs_; | 11 NSMutableArray* chromeIncompleteDownloadURLs_; |
12 NSString* chromeImageFilename_; | 12 NSString* chromeImageFilename_; |
13 } | 13 } |
14 | 14 |
15 // Sets up instance of NSXMLParser and calls on delegate methods to do actual | 15 // Sets up instance of NSXMLParser and calls on delegate methods to do actual |
16 // parsing work. | 16 // parsing work. |
17 + (NSArray*)parseXML:(NSData*)omahaResponseXML error:(NSError**)error { | 17 + (NSArray*)parseXML:(NSData*)omahaResponseXML error:(NSError**)error { |
18 NSXMLParser* parser = [[NSXMLParser alloc] initWithData:omahaResponseXML]; | 18 NSXMLParser* parser = [[NSXMLParser alloc] initWithData:omahaResponseXML]; |
19 | 19 |
20 OmahaXMLParser* omahaParser = [[OmahaXMLParser alloc] init]; | 20 OmahaXMLParser* omahaParser = [[OmahaXMLParser alloc] init]; |
21 [parser setDelegate:omahaParser]; | 21 [parser setDelegate:omahaParser]; |
22 if (![parser parse]) { | 22 if (![parser parse]) { |
23 *error = [parser parserError]; | 23 *error = [parser parserError]; |
24 // TODO: pass up error object to indicate error occurred so | |
25 // InstallerWindowController can create custom user error message. | |
26 return nil; | 24 return nil; |
27 } | 25 } |
28 | 26 |
29 NSMutableArray* completeDownloadURLs = [[NSMutableArray alloc] init]; | 27 NSMutableArray* completeDownloadURLs = [[NSMutableArray alloc] init]; |
30 for (NSString* URL in omahaParser->chromeIncompleteDownloadURLs_) { | 28 for (NSString* URL in omahaParser->chromeIncompleteDownloadURLs_) { |
31 [completeDownloadURLs | 29 [completeDownloadURLs |
32 addObject:[NSURL URLWithString:omahaParser->chromeImageFilename_ | 30 addObject:[NSURL URLWithString:omahaParser->chromeImageFilename_ |
33 relativeToURL:[NSURL URLWithString:URL]]]; | 31 relativeToURL:[NSURL URLWithString:URL]]]; |
34 } | 32 } |
35 | 33 |
36 if ([completeDownloadURLs count] < 1) { | 34 if ([completeDownloadURLs count] < 1) { |
| 35 // TODO: currently whatever error is passed in doesn't matter... we should |
| 36 // make it so that the type of error informs what the installer will do |
| 37 // about the error |
37 *error = [NSError errorWithDomain:@"ChromeErrorDomain" code:1 userInfo:nil]; | 38 *error = [NSError errorWithDomain:@"ChromeErrorDomain" code:1 userInfo:nil]; |
38 return nil; | 39 return nil; |
39 } | 40 } |
40 | 41 |
41 return completeDownloadURLs; | 42 return completeDownloadURLs; |
42 } | 43 } |
43 | 44 |
44 // Method implementation for XMLParserDelegate. | 45 // Method implementation for XMLParserDelegate. |
45 // Searches the XML data for the tag "URL" and the subsequent "codebase" | 46 // Searches the XML data for the tag "URL" and the subsequent "codebase" |
46 // attribute that indicates a URL follows. Copies each URL into an array. | 47 // attribute that indicates a URL follows. Copies each URL into an array. |
(...skipping 21 matching lines...) Expand all Loading... |
68 // If either component of the URL is empty then the complete URL cannot | 69 // If either component of the URL is empty then the complete URL cannot |
69 // be generated so both variables are set to nil to flag errors. | 70 // be generated so both variables are set to nil to flag errors. |
70 - (void)parserDidEndDocument:(NSXMLParser*)parser { | 71 - (void)parserDidEndDocument:(NSXMLParser*)parser { |
71 if (!chromeIncompleteDownloadURLs_ || !chromeImageFilename_) { | 72 if (!chromeIncompleteDownloadURLs_ || !chromeImageFilename_) { |
72 chromeIncompleteDownloadURLs_ = nil; | 73 chromeIncompleteDownloadURLs_ = nil; |
73 chromeImageFilename_ = nil; | 74 chromeImageFilename_ = nil; |
74 } | 75 } |
75 } | 76 } |
76 | 77 |
77 @end | 78 @end |
OLD | NEW |