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

Unified Diff: chrome/installer/mac/app/OmahaXMLParser.m

Issue 2094583004: Initial commit for Chrome metainstaller on Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Made small changes according to LGTM comments Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/installer/mac/app/OmahaXMLParser.h ('k') | chrome/installer/mac/app/OmahaXMLRequest.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/installer/mac/app/OmahaXMLParser.m
diff --git a/chrome/installer/mac/app/OmahaXMLParser.m b/chrome/installer/mac/app/OmahaXMLParser.m
new file mode 100644
index 0000000000000000000000000000000000000000..4986e0040145c7901928ec2e54fdc24097817841
--- /dev/null
+++ b/chrome/installer/mac/app/OmahaXMLParser.m
@@ -0,0 +1,54 @@
+// 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 "OmahaXMLParser.h"
+
+@implementation OmahaXMLParser
+
+- (NSMutableArray*)chromeIncompleteDownloadURLs {
+ return chromeIncompleteDownloadURLs_;
+}
+
+- (NSString*)chromeImageFilename {
+ return chromeImageFilename_;
+}
+
+// Sets up instance of NSXMLParser and calls on delegate methods to do actual
+// parsing work.
+- (NSArray*)parseXML:(NSData*)omahaResponseXML error:(NSError**)error {
+ NSXMLParser* parser = [[NSXMLParser alloc] initWithData:omahaResponseXML];
+ [parser setDelegate:self];
+ BOOL success = [parser parse];
+ if (!success) {
+ *error = [parser parserError];
+ }
+
+ return chromeIncompleteDownloadURLs_;
+}
+
+// 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
« no previous file with comments | « chrome/installer/mac/app/OmahaXMLParser.h ('k') | chrome/installer/mac/app/OmahaXMLRequest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698