| Index: chrome/installer/mac/app/parser.m
|
| diff --git a/chrome/installer/mac/app/parser.m b/chrome/installer/mac/app/parser.m
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e8d7d14602d4226088c2a6e6e71f22b7b948547e
|
| --- /dev/null
|
| +++ b/chrome/installer/mac/app/parser.m
|
| @@ -0,0 +1,60 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#import "parser.h"
|
| +
|
| +@implementation Parser
|
| +
|
| +- (id)initWithXML:(NSData*)omahaResponseXML{
|
| + if ((self = [super init])) {
|
| + omahaResponseXML_ = omahaResponseXML;
|
| + }
|
| + return self;
|
| +}
|
| +
|
| +- (NSMutableArray*)chromeIncompleteDownloadURLs{
|
| + return chromeIncompleteDownloadURLs_;
|
| +}
|
| +
|
| +- (NSString*)chromeImageFilename{
|
| + return chromeImageFilename_;
|
| +}
|
| +
|
| +// Sets up instance of NSXMLParser and calls on delegate methods to do actual
|
| +// parsing work.
|
| +- (void)parseXML{
|
| + if (omahaResponseXML_) {
|
| + NSXMLParser* parser = [[NSXMLParser alloc] initWithData:omahaResponseXML_];
|
| + [parser setDelegate:self];
|
| + [parser parse];
|
| + } else {
|
| + // TODO: error handler
|
| + }
|
| +}
|
| +
|
| +// Method implementation for XMLParserDelegate.
|
| +// Searches the XML data for the tag "URL" and the subsequent "codebase"
|
| +// attribute that indicates a URL follows. Copies each URL into an array.
|
| +// Note that the URLs in the XML file are incomplete. They need the filename
|
| +// appended to end. The second if statement checks for the tag "package" which
|
| +// contains the filename we need to complete the URLs.
|
| +- (void)parser:(NSXMLParser*)parser
|
| +didStartElement:(NSString*)elementName
|
| + namespaceURI:(NSString*)namespaceURI
|
| + qualifiedName:(NSString*)qName
|
| + attributes:(NSDictionary*)attributeDict {
|
| + if ([elementName isEqualToString:@"url"]) {
|
| + if (!chromeIncompleteDownloadURLs_) {
|
| + chromeIncompleteDownloadURLs_ = [[NSMutableArray alloc] init];
|
| + }
|
| + NSString* extractedURL = [attributeDict objectForKey:@"codebase"];
|
| + [chromeIncompleteDownloadURLs_ addObject: extractedURL];
|
| + }
|
| + if ([elementName isEqualToString:@"package"]) {
|
| + chromeImageFilename_ = [[NSString alloc] initWithFormat:@"%@",
|
| + [attributeDict objectForKey:@"name"]];
|
| + }
|
| +}
|
| +
|
| +@end
|
|
|