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 3// found in the LICENSE file. 4 5'use strict'; 6 7/** 8 * @param {MetadataDispatcher} parent Parent object. 9 * @param {string} type Parser type. 10 * @param {RegExp} urlFilter RegExp to match URLs. 11 * @constructor 12 */ 13function MetadataParser(parent, type, urlFilter) { 14 this.parent_ = parent; 15 this.type = type; 16 this.urlFilter = urlFilter; 17 this.verbose = parent.verbose; 18 this.mimeType = 'unknown'; 19} 20 21/** 22 * Output an error message. 23 * @param {...Object} var_args Arguments. 24 */ 25MetadataParser.prototype.error = function(var_args) { 26 this.parent_.error.apply(this.parent_, arguments); 27}; 28 29/** 30 * Output a log message. 31 * @param {...Object} var_args Arguments. 32 */ 33MetadataParser.prototype.log = function(var_args) { 34 this.parent_.log.apply(this.parent_, arguments); 35}; 36 37/** 38 * Output a log message if |verbose| flag is on. 39 * @param {...Object} var_args Arguments. 40 */ 41MetadataParser.prototype.vlog = function(var_args) { 42 if (this.verbose) 43 this.parent_.log.apply(this.parent_, arguments); 44}; 45 46/** 47 * @return {Object} Metadata object with the minimal set of properties. 48 */ 49MetadataParser.prototype.createDefaultMetadata = function() { 50 return { 51 type: this.type, 52 mimeType: this.mimeType 53 }; 54}; 55 56/* Base class for image metadata parsers */ 57function ImageParser(parent, type, urlFilter) { 58 MetadataParser.apply(this, arguments); 59 this.mimeType = 'image/' + this.type; 60} 61 62ImageParser.prototype = {__proto__: MetadataParser.prototype}; 63