[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ssl暗号化通信を採用しているサイトでの画像表示
青田です。
From: Katsumi Yamaoka <yamaoka@xxxxxxx>
Subject: [emacs-w3m:09790] Re: ssl暗号化通信を採用しているサイトでの画像表示
Date: Thu, 29 Nov 2007 12:18:06 +0900
> >>>>> In [emacs-w3m : No.09788] 山岡さん wrote:
>
> 結局 w3m-create-image() にパーサを入れてみました (w3m-ems.el と
> w3m-xmas.el)。似たものがあちこちにあるのは気持ち悪いんですが。
> 野宮さん、試してみて下さいますか?
いっそのこと、w3m-create-image()(などの末端)だけで判別してしまうのはだ
めでしょうか? データ圧縮されていても、されていなくても
w3m-w3m-retrieve() で判定を通るのでどうにしろ w3m-w3m-dump-extra() のほ
うは消してしまえますし。
現在の実装ですと
- gif,jpeg,png => content-type に関係なく表示可能
- それ以外のサポートされている画像 => content-type が正しければ表示可能
となっていますから、末端で判定できたらその type を使い、判定できなけれ
ば contnt-type を使う、というコードでも同じ動作になると思います。
ついでに、shimbun-mime-replace-image-tags() の判定も拡張子ではなくデー
タの中身で行なうようにしてみました。
Index: ChangeLog
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/ChangeLog,v
retrieving revision 1.3083
diff -u -r1.3083 ChangeLog
--- ChangeLog 29 Nov 2007 04:10:06 -0000 1.3083
+++ ChangeLog 29 Nov 2007 05:27:48 -0000
@@ -1,3 +1,13 @@
+2007-11-29 Naohiro Aota <nao.aota@xxxxxxxxx>
+
+ * w3m.el (w3m-w3m-dump-extra, w3m-w3m-retrieve): Removed image data
+ type tests.
+
+ * w3m-xmas.el (w3m-create-image): Parse image data first, use server's
+ content-type when it failed to identify type.
+
+ * w3m-ems.el (w3m-create-image): Ditto.
+
2007-11-29 Katsumi Yamaoka <yamaoka@xxxxxxx>
* w3m-search.el (w3m-search-engine-alist): Fix google news entry.
Index: w3m-ems.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m-ems.el,v
retrieving revision 1.27
diff -u -r1.27 w3m-ems.el
--- w3m-ems.el 29 Nov 2007 03:18:04 -0000 1.27
+++ w3m-ems.el 29 Nov 2007 05:27:53 -0000
@@ -217,19 +217,17 @@
(type (progn
(set-buffer-multibyte nil)
(w3m-retrieve url nil no-cache nil referer handler)))
- (when (or (w3m-image-type-available-p
- (setq type (w3m-image-type type)))
- (progn
- (goto-char (point-min))
- (and (prog2
- (setq case-fold-search nil)
- (looking-at
- "\\(GIF8\\)\\|\\(\377\330\\)\\|\211PNG\r\n")
- (setq case-fold-search t))
- (w3m-image-type-available-p
- (setq type (cond ((match-beginning 1) 'gif)
- ((match-beginning 2) 'jpeg)
- (t 'png)))))))
+ (goto-char (point-min))
+ (when (w3m-image-type-available-p
+ (setq type
+ (or (and (prog2
+ (setq case-fold-search nil)
+ (looking-at "\\(GIF8\\)\\|\\(\377\330\\)\\|\211PNG\r\n")
+ (setq case-fold-search t))
+ (cond ((match-beginning 1) 'gif)
+ ((match-beginning 2) 'jpeg)
+ (t 'png)))
+ (w3m-image-type type))))
(setq image (create-image (buffer-string) type t :ascent 'center))
(if (and w3m-resize-images set-size)
(progn
Index: w3m-xmas.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m-xmas.el,v
retrieving revision 1.147
diff -u -r1.147 w3m-xmas.el
--- w3m-xmas.el 29 Nov 2007 03:18:04 -0000 1.147
+++ w3m-xmas.el 29 Nov 2007 05:27:56 -0000
@@ -418,19 +418,16 @@
(type (condition-case err
(w3m-retrieve url nil no-cache nil referer handler)
(error (message "While retrieving %s: %s" url err) nil)))
- (when (or (w3m-image-type-available-p
- (setq type (w3m-image-type type)))
- (progn
- (goto-char (point-min))
- (and (prog2
- (setq case-fold-search nil)
- (looking-at
- "\\(GIF8\\)\\|\\(\377\330\\)\\|\211PNG\r\n")
- (setq case-fold-search t))
- (w3m-image-type-available-p
- (setq type (cond ((match-beginning 1) 'gif)
- ((match-beginning 2) 'jpeg)
- (t 'png)))))))
+ (when (w3m-image-type-available-p
+ (setq type
+ (or (and (prog2
+ (setq case-fold-search nil)
+ (looking-at "\\(GIF8\\)\\|\\(\377\330\\)\\|\211PNG\r\n")
+ (setq case-fold-search t))
+ (cond ((match-beginning 1) 'gif)
+ ((match-beginning 2) 'jpeg)
+ (t 'png)))
+ (w3m-image-type type))))
(let ((data (buffer-string))
glyph)
(setq glyph (or (and (eq type 'gif)
Index: w3m.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m.el,v
retrieving revision 1.1330
diff -u -r1.1330 w3m.el
--- w3m.el 27 Nov 2007 11:21:02 -0000 1.1330
+++ w3m.el 29 Nov 2007 05:28:31 -0000
@@ -4734,21 +4734,6 @@
(progn
(delete-region (point-min) (match-beginning 0))
(search-forward "\n\n" nil t)))
- ;; Asahi-shimbun sometimes says gif as jpeg mistakenly, for
- ;; example. So, we cannot help trusting the data itself.
- (when (prog2
- (setq case-fold-search nil)
- (looking-at "\\(GIF8\\)\\|\\(\377\330\\)\\|\211PNG\r\n")
- (setq case-fold-search t))
- (let ((type (cond ((match-beginning 1) "gif")
- ((match-beginning 2) "jpeg")
- (t "png"))))
- (save-excursion
- (when (re-search-backward "^content-type: image/\\(.+\\)$"
- nil t)
- (delete-region (goto-char (match-beginning 1))
- (match-end 1))
- (insert type)))))
(let ((header (buffer-substring (point-min) (point))))
(when w3m-use-cookies
(w3m-cookie-set url (point-min) (point)))
@@ -4907,20 +4892,7 @@
(with-current-buffer current-buffer
(insert-buffer-substring temp-buffer))
(goto-char (point-min))
- ;; Hatena diary sometimes specifies Content-Type mistakenly,
- ;; so we cannot help trusting the data itself.
- (if (and (string-match "^image/" (cadr attr))
- (prog2
- (setq case-fold-search nil)
- (looking-at
- "\\(GIF8\\)\\|\\(\377\330\\)\\|\211PNG\r\n")
- (setq case-fold-search t)))
- (progn
- (concat "image/"
- (cond ((match-beginning 1) "gif")
- ((match-beginning 2) "jpeg")
- (t "png"))))
- (cadr attr)))
+ (cadr attr))
(ding)
(w3m-message "Can't decode encoded contents: %s" url)
nil)))))
Index: shimbun/ChangeLog
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/shimbun/ChangeLog,v
retrieving revision 1.96
diff -u -r1.96 ChangeLog
--- shimbun/ChangeLog 27 Nov 2007 02:32:20 -0000 1.96
+++ shimbun/ChangeLog 29 Nov 2007 05:28:57 -0000
@@ -1,3 +1,8 @@
+2007-11-29 Naohiro Aota <nao.aota@xxxxxxxxx>
+
+ * shimbun.el (shimbun-mime-replace-image-tags): Identify image type not
+ by its filename but its data.
+
2007-11-27 TSUCHIYA Masatoshi <tsuchiya@xxxxxxxxxx>
* sb-cnet-jp.el (shimbun-cnet-jp-content-start): Relaxed.
Index: shimbun/shimbun.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/shimbun/shimbun.el,v
retrieving revision 1.187
diff -u -r1.187 shimbun.el
--- shimbun/shimbun.el 22 Nov 2007 09:03:51 -0000 1.187
+++ shimbun/shimbun.el 29 Nov 2007 05:29:03 -0000
@@ -629,16 +629,15 @@
(with-temp-buffer
(set-buffer-multibyte nil)
(setq type (shimbun-fetch-url shimbun url nil t base-url))
- (when (and
- type
- (or (string-match "\\`image/" type)
- ;; headlines.yahoo.co.jp often specifies it mistakenly.
- (and (string-match "\\.\\(gif\\|jpe?g\\|png\\)\\'" url)
- (setq type (cdr (assoc (match-string 1 url)
- '(("gif" . "image/gif")
- ("jpeg" . "image/jpeg")
- ("jpg" . "image/jpeg")
- ("png" . "image/png"))))))))
+ (when (or (and (prog2
+ (setq case-fold-search nil)
+ (looking-at "\\(GIF8\\)\\|\\(\377\330\\)\\|\211PNG\r\n")
+ (setq case-fold-search t))
+ (setq type (concat "image/"
+ (cond ((match-beginning 1) "gif")
+ ((match-beginning 2) "jpeg")
+ (t "png")))))
+ (string-match "\\`image/" type))
(push (setq img (cons url
(shimbun-make-image-entity
type