Index: Bugzilla/Attachment.pm =================================================================== RCS file: /cvsroot/mozilla/webtools/bugzilla/Bugzilla/Attachment.pm,v retrieving revision 1.50 diff -u -r1.50 Bugzilla/Attachment.pm --- Bugzilla/Attachment.pm +++ Bugzilla/Attachment.pm @@ -238,6 +238,23 @@ =over +=item C + +Returns 1 if the attachment has a content-type that represents a zip archive + +=back + +=cut + +sub is_zip { + my $self = shift; + my $contenttype = trim($self->contenttype); + return $contenttype =~ + m{^(?:application/(?:x-|)(?:zip|xpinstall|java-archive|jar|winamp-skin)|interface/(?:x-|)winamp-skin)}; +} + +=over + =item C whether or not the attachment is a URL @@ -296,23 +313,32 @@ sub is_viewable { my $self = shift; - my $contenttype = $self->contenttype; + return $self->{is_viewable} if exists $self->{is_viewable}; + my $contenttype = trim($self->contenttype); my $cgi = Bugzilla->cgi; # We assume we can view all text and image types. - return 1 if ($contenttype =~ /^(text|image)\//); + if ($contenttype =~ m{^(text|image)/}) { + return $self->{is_viewable} = 1; + } # Mozilla can view XUL. Note the trailing slash on the Gecko detection to # avoid sending XUL to Safari. - return 1 if (($contenttype =~ /^application\/vnd\.mozilla\./) - && ($cgi->user_agent() =~ /Gecko\//)); + if (($contenttype =~ m{^application/vnd\.mozilla\.} + || $self->is_zip) + && $cgi->user_agent() =~ m{Gecko/}) { + return $self->{is_viewable} = 1; + } - # If it's not one of the above types, we check the Accept: header for any + # If it's not one of the above types, we check the Accept: header for any # types mentioned explicitly. my $accept = join(",", $cgi->Accept()); - return 1 if ($accept =~ /^(.*,)?\Q$contenttype\E(,.*)?$/); - return 0; + if ($accept =~ /^(.*,)?\Q$contenttype\E(,.*)?$/) { + return $self->{is_viewable} = 1; + } + + return $self->{is_viewable} = 0; } =over Index: template/en/default/attachment/edit.html.tmpl =================================================================== RCS file: /cvsroot/mozilla/webtools/bugzilla/template/en/default/attachment/edit.html.tmpl,v retrieving revision 1.47 diff -u -r1.47 template/en/default/attachment/edit.html.tmpl --- template/en/default/attachment/edit.html.tmpl +++ template/en/default/attachment/edit.html.tmpl @@ -105,6 +105,12 @@ } } [% END %] +[% IF attachment.is_zip %] + function viewZip() + { + switchToMode('zip'); + } +[% END %] function viewRaw() { switchToMode('raw'); @@ -121,6 +127,10 @@ if (current_mode == 'edit') { hideElementById('editFrame'); hideElementById('undoEditButton'); +[% IF attachment.is_zip %] + } else if (current_mode == 'zip') { + hideElementById('zipFrame'); +[% END %] } else if (current_mode == 'raw') { hideElementById('viewFrame'); [% IF patchviewerinstalled %] @@ -141,6 +151,10 @@ if (mode == 'edit') { showElementById('editFrame'); showElementById('undoEditButton'); +[% IF attachment.is_zip %] + } else if (mode == 'zip') { + showElementById('zipFrame'); +[% END %] } else if (mode == 'raw') { showElementById('viewFrame'); [% IF patchviewerinstalled %] @@ -307,9 +321,29 @@ cols = 80 wrap = 'soft' %] - + [% hide_viewframe = 'display:none;' %] + [% ELSE %] + [% hide_viewframe = '' %] + [% END %] +