From: Joakim Verona Date: Thu, 12 Feb 2015 22:45:43 +0000 (+0100) Subject: Cleanup, and delete plugin removal function X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=63fbe839623b9b108950b0e3d3925193def41887;p=emacs.git Cleanup, and delete plugin removal function --- diff --git a/lisp/xwidget.el b/lisp/xwidget.el index 3a7d3c1354b..33f9a189f95 100644 --- a/lisp/xwidget.el +++ b/lisp/xwidget.el @@ -57,8 +57,8 @@ Optional argument ARGS usage depends on the xwidget." (defun xwidget-at (pos) "Return xwidget at POS." - ;;TODO this function is a bit tedious because the C layer isnt well protected yet and - ;;xwidgetp aparently doesnt work yet + ;;TODO this function is a bit tedious because the C layer isnt well + ;;protected yet and xwidgetp aparently doesnt work yet (let* ((disp (get-text-property pos 'display)) (xw (car (cdr (cdr disp))))) ;;(if ( xwidgetp xw) xw nil) @@ -66,7 +66,7 @@ Optional argument ARGS usage depends on the xwidget." -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; webkit support (require 'browse-url) (require 'image-mode);;for some image-mode alike functionality @@ -90,7 +90,8 @@ defaults to the string looking like a url around the cursor position." ;;shims for adapting image mode code to the webkit browser window (defun xwidget-image-display-size (spec &optional pixels frame) - "Image code adaptor. SPEC PIXELS FRAME like the corresponding `image-mode' fn." + "Image code adaptor. SPEC PIXELS FRAME like the corresponding +`image-mode' fn." (let ((xwi (xwidget-info (xwidget-at 1)))) (cons (aref xwi 2) (aref xwi 3)))) @@ -116,19 +117,19 @@ defaults to the string looking like a url around the cursor position." (define-key map "w" 'xwidget-webkit-current-url) ;;similar to image mode bindings - (define-key map (kbd "SPC") 'xwidget-webkit-scroll-up) - (define-key map (kbd "DEL") 'xwidget-webkit-scroll-down) + (define-key map (kbd "SPC") 'xwidget-webkit-scroll-up) + (define-key map (kbd "DEL") 'xwidget-webkit-scroll-down) - (define-key map [remap scroll-up] 'xwidget-webkit-scroll-up) - (define-key map [remap scroll-up-command] 'xwidget-webkit-scroll-up) + (define-key map [remap scroll-up] 'xwidget-webkit-scroll-up) + (define-key map [remap scroll-up-command] 'xwidget-webkit-scroll-up) - (define-key map [remap scroll-down] 'xwidget-webkit-scroll-down) - (define-key map [remap scroll-down-command] 'xwidget-webkit-scroll-down) + (define-key map [remap scroll-down] 'xwidget-webkit-scroll-down) + (define-key map [remap scroll-down-command] 'xwidget-webkit-scroll-down) - (define-key map [remap forward-char] 'xwidget-webkit-scroll-forward) - (define-key map [remap backward-char] 'xwidget-webkit-scroll-backward) - (define-key map [remap right-char] 'xwidget-webkit-scroll-forward) - (define-key map [remap left-char] 'xwidget-webkit-scroll-backward) + (define-key map [remap forward-char] 'xwidget-webkit-scroll-forward) + (define-key map [remap backward-char] 'xwidget-webkit-scroll-backward) + (define-key map [remap right-char] 'xwidget-webkit-scroll-forward) + (define-key map [remap left-char] 'xwidget-webkit-scroll-backward) ;; (define-key map [remap previous-line] 'image-previous-line) ;; (define-key map [remap next-line] 'image-next-line) @@ -188,9 +189,10 @@ defaults to the string looking like a url around the cursor position." (let* ((xwidget-event-type (nth 1 last-input-event)) (xwidget (nth 2 last-input-event)) - ;(xwidget-callback (xwidget-get xwidget 'callback));;TODO stopped working for some reason + ;;(xwidget-callback (xwidget-get xwidget 'callback)) + ;;TODO stopped working for some reason ) - ;(funcall xwidget-callback xwidget xwidget-event-type) + ;;(funcall xwidget-callback xwidget xwidget-event-type) (message "xw callback %s" xwidget) (funcall 'xwidget-webkit-callback xwidget xwidget-event-type))) @@ -202,17 +204,23 @@ XWIDGET instance, XWIDGET-EVENT-TYPE depends on the originating xwidget." (set-buffer (xwidget-buffer xwidget)) (let* ((strarg (nth 3 last-input-event))) (cond ((eq xwidget-event-type 'document-load-finished) - (xwidget-log "webkit finished loading: '%s'" (xwidget-webkit-get-title xwidget)) + (xwidget-log "webkit finished loading: '%s'" + (xwidget-webkit-get-title xwidget)) ;;TODO - check the native/internal scroll ;;(xwidget-adjust-size-to-content xwidget) - (xwidget-webkit-adjust-size-dispatch) ;;TODO send xwidget here - (rename-buffer (format "*xwidget webkit: %s *" (xwidget-webkit-get-title xwidget))) + (xwidget-webkit-adjust-size-dispatch) ;;TODO xwidget arg + (rename-buffer (format "*xwidget webkit: %s *" + (xwidget-webkit-get-title xwidget))) (pop-to-buffer (current-buffer))) - ((eq xwidget-event-type 'navigation-policy-decision-requested) + ((eq xwidget-event-type + 'navigation-policy-decision-requested) (if (string-match ".*#\\(.*\\)" strarg) - (xwidget-webkit-show-id-or-named-element xwidget (match-string 1 strarg)))) + (xwidget-webkit-show-id-or-named-element + xwidget + (match-string 1 strarg)))) (t (xwidget-log "unhandled event:%s" xwidget-event-type))))) - (t (xwidget-log "error: callback called for xwidget with dead buffer"))))) + (t (xwidget-log + "error: callback called for xwidget with dead buffer"))))) (defvar bookmark-make-record-function) (define-derived-mode xwidget-webkit-mode @@ -227,7 +235,8 @@ XWIDGET instance, XWIDGET-EVENT-TYPE depends on the originating xwidget." "Integrate Emacs bookmarks with the webkit xwidget." (nconc (bookmark-make-record-default t t) `((page . ,(xwidget-webkit-current-url)) - (handler . (lambda (bmk) (browse-url (bookmark-prop-get bmk 'page))))))) + (handler . (lambda (bmk) (browse-url + (bookmark-prop-get bmk 'page))))))) (defvar xwidget-webkit-last-session-buffer nil) @@ -240,15 +249,17 @@ XWIDGET instance, XWIDGET-EVENT-TYPE depends on the originating xwidget." nil)) (defun xwidget-webkit-current-session () - "Either the webkit in the current buffer, or the last one used, which might be nil." + "Either the webkit in the current buffer, or the last one used, +which might be nil." (if (xwidget-at 1) (xwidget-at 1) (xwidget-webkit-last-session))) (defun xwidget-adjust-size-to-content (xw) "Resize XW to content." - ;;xwidgets doesnt support widgets that have their own opinions about size well yet - ;;this reads the desired size and resizes the emacs allocated area accordingly + ;;xwidgets doesnt support widgets that have their own opinions about + ;;size well yet this reads the desired size and resizes the emacs + ;;allocated area accordingly (let ((size (xwidget-size-request xw))) (xwidget-resize xw (car size) (cadr size)))) @@ -280,8 +291,9 @@ function findactiveelement(doc){ ;;yes its ugly. because: ;; - there is aparently no way to find the active frame other than recursion ;; - the js "for each" construct missbehaved on the "frames" collection - ;; - a window with no frameset still has frames.length == 1, but frames[0].document.activeElement != document.activeElement - ;;TODO the activeelement type needs to be examined, for iframe, etc. sucks. + ;; - a window with no frameset still has frames.length == 1, but + ;; frames[0].document.activeElement != document.activeElement + ;;TODO the activeelement type needs to be examined, for iframe, etc. ) (defun xwidget-webkit-insert-string (xw str) @@ -295,8 +307,12 @@ Argument STR string." (field-value (progn (xwidget-webkit-execute-script xww xwidget-webkit-activeelement-js) - (xwidget-webkit-execute-script-rv xww "findactiveelement(document).value;" ))) - (field-type (xwidget-webkit-execute-script-rv xww "findactiveelement(document).type;" ))) + (xwidget-webkit-execute-script-rv + xww + "findactiveelement(document).value;" ))) + (field-type (xwidget-webkit-execute-script-rv + xww + "findactiveelement(document).type;" ))) (list xww (cond ((equal "text" field-type) (read-string "text:" field-value)) @@ -304,7 +320,9 @@ Argument STR string." (read-passwd "password:" nil field-value)) ((equal "textarea" field-type) (xwidget-webkit-begin-edit-textarea xww field-value)))))) - (xwidget-webkit-execute-script xw (format "findactiveelement(document).value='%s'" str))) + (xwidget-webkit-execute-script + xw + (format "findactiveelement(document).value='%s'" str))) (defvar xwidget-xwbl) (defun xwidget-webkit-begin-edit-textarea (xw text) @@ -322,8 +340,10 @@ XW is the xwidget identifier, TEXT is retrieved from the webkit." (goto-char (point-min)) (while (search-forward "\n" nil t) (replace-match "\\n" nil t)) - (xwidget-webkit-execute-script xwidget-xwbl (format "findactiveelement(document).value='%s'" - (buffer-substring (point-min) (point-max)))) + (xwidget-webkit-execute-script + xwidget-xwbl + (format "findactiveelement(document).value='%s'" + (buffer-substring (point-min) (point-max)))) ;;TODO convert linefeed to \n ) @@ -331,22 +351,27 @@ XW is the xwidget identifier, TEXT is retrieved from the webkit." "Make named-element show. for instance an anchor. Argument XW is the xwidget. Argument ELEMENT-NAME is the element name to display in the webkit xwidget." - (interactive (list (xwidget-webkit-current-session) (read-string "element name:"))) - ;;TODO - ;; since an xwidget is an Emacs object, it is not trivial to do some things that are taken for granted in a normal browser. + (interactive (list (xwidget-webkit-current-session) + (read-string "element name:"))) + ;;TODO since an xwidget is an Emacs object, it is not trivial to do + ;; some things that are taken for granted in a normal browser. ;; scrolling an anchor/named-element into view is one such thing. - ;; this function implements a proof-of-concept for this. - ;; problems remaining: - ;; - the selected window is scrolled but this is not always correct - ;; - this needs to be interfaced into browse-url somehow. the tricky part is that we need to do this in two steps: - ;; A: load the base url, wait for load signal to arrive B: navigate to the anchor when the base url is finished rendering - - ;;this part figures out the Y coordinate of the element + ;; This function implements a proof-of-concept for this. Problems + ;; remaining: - The selected window is scrolled but this is not + ;; always correct - This needs to be interfaced into browse-url + ;; somehow. the tricky part is that we need to do this in two steps: + ;; A: load the base url, wait for load signal to arrive B: navigate + ;; to the anchor when the base url is finished rendering + + ;; This part figures out the Y coordinate of the element (let ((y (string-to-number - (xwidget-webkit-execute-script-rv xw - (format "document.getElementsByName('%s')[0].getBoundingClientRect().top" element-name) - 0)))) - ;;now we need to tell emacs to scroll the element into view. + (xwidget-webkit-execute-script-rv + xw + (format + "document.getElementsByName('%s')[0].getBoundingClientRect().top" + element-name) + 0)))) + ;; Now we need to tell emacs to scroll the element into view. (xwidget-log "scroll: %d" y) (set-window-vscroll (selected-window) y t))) @@ -357,10 +382,12 @@ Argument ELEMENT-ID is the id of the element to show." (interactive (list (xwidget-webkit-current-session) (read-string "element id:"))) (let ((y (string-to-number - (xwidget-webkit-execute-script-rv xw - (format "document.getElementById('%s').getBoundingClientRect().top" element-id) - 0)))) - ;;now we need to tell emacs to scroll the element into view. + (xwidget-webkit-execute-script-rv + xw + (format "document.getElementById('%s').getBoundingClientRect().top" + element-id) + 0)))) + ;; Now we need to tell emacs to scroll the element into view. (xwidget-log "scroll: %d" y) (set-window-vscroll (selected-window) y t))) @@ -371,15 +398,17 @@ Argument ELEMENT-ID is either a name or an element id." (interactive (list (xwidget-webkit-current-session) (read-string "element id:"))) (let* ((y1 (string-to-number - (xwidget-webkit-execute-script-rv xw - (format "document.getElementsByName('%s')[0].getBoundingClientRect().top" element-id) - "0"))) + (xwidget-webkit-execute-script-rv + xw + (format "document.getElementsByName('%s')[0].getBoundingClientRect().top" element-id) + "0"))) (y2 (string-to-number - (xwidget-webkit-execute-script-rv xw - (format "document.getElementById('%s').getBoundingClientRect().top" element-id) + (xwidget-webkit-execute-script-rv + xw + (format "document.getElementById('%s').getBoundingClientRect().top" element-id) "0"))) (y3 (max y1 y2))) - ;;now we need to tell emacs to scroll the element into view. + ;; Now we need to tell emacs to scroll the element into view. (xwidget-log "scroll: %d" y3) (set-window-vscroll (selected-window) y3 t))) @@ -394,9 +423,9 @@ Argument ELEMENT-ID is either a name or an element id." (if (eq xwidget-webkit-scroll-behaviour 'native) (xwidget-webkit-adjust-size-to-window) (xwidget-webkit-adjust-size-to-content)) - ;;the recenter is intended to correct a visual glitch - ;;it errors out if the buffer isnt visible, but then we dont get the glitch, - ;;so silence errors + ;; The recenter is intended to correct a visual glitch. + ;; It errors out if the buffer isn't visible, but then we dont get the glitch, + ;; so silence errors (ignore-errors (recenter-top-bottom)) ) @@ -404,13 +433,14 @@ Argument ELEMENT-ID is either a name or an element id." (defun xwidget-webkit-adjust-size-to-window () "Adjust webkit to window." (interactive) - (xwidget-resize ( xwidget-webkit-current-session) (window-pixel-width) (window-pixel-height))) + (xwidget-resize ( xwidget-webkit-current-session) (window-pixel-width) + (window-pixel-height))) (defun xwidget-webkit-adjust-size (w h) "Manualy set webkit size. Argument W width. Argument H height." - ;;TODO shouldnt be tied to the webkit xwidget + ;; TODO shouldn't be tied to the webkit xwidget (interactive "nWidth:\nnHeight:\n") (xwidget-resize ( xwidget-webkit-current-session) w h)) @@ -426,7 +456,8 @@ Argument H height." (let* ((bufname (generate-new-buffer-name "*xwidget-webkit*")) xw) - (setq xwidget-webkit-last-session-buffer (switch-to-buffer (get-buffer-create bufname))) + (setq xwidget-webkit-last-session-buffer (switch-to-buffer + (get-buffer-create bufname))) (insert " 'a' adjusts the xwidget size.") (setq xw (xwidget-insert 1 'webkit-osr bufname 1000 1000)) (xwidget-put xw 'callback 'xwidget-webkit-callback) @@ -444,12 +475,14 @@ Argument H height." (defun xwidget-webkit-back () "Back in history." (interactive) - (xwidget-webkit-execute-script (xwidget-webkit-current-session) "history.go(-1);")) + (xwidget-webkit-execute-script (xwidget-webkit-current-session) + "history.go(-1);")) (defun xwidget-webkit-reload () "Reload current url." (interactive) - (xwidget-webkit-execute-script (xwidget-webkit-current-session) "history.go(0);")) + (xwidget-webkit-execute-script (xwidget-webkit-current-session) + "history.go(0);")) (defun xwidget-webkit-current-url () "Get the webkit url. place it on kill ring." @@ -464,15 +497,17 @@ Argument H height." "Same as 'xwidget-webkit-execute-script' but but with return value. XW is the webkit instance. SCRIPT is the script to execut. DEFAULT is the defaultreturn value." - ;;notice the fugly "title" hack. it is needed because the webkit api - ;;doesnt support returning values. this is a wrapper for the title - ;;hack so its easy to remove should webkit someday support JS return - ;;values or we find some other way to access the DOM + ;; Notice the ugly "title" hack. It is needed because the Webkit + ;; API at the time of writing didn't support returning values. This + ;; is a wrapper for the title hack so its easy to remove should + ;; Webkit someday support JS return values or we find some other way + ;; to access the DOM. - ;;reset webkit title. fugly. + ;; Reset webkit title. Not very nice. (let* ((emptytag "titlecantbewhitespaceohthehorror") title) - (xwidget-webkit-execute-script xw (format "document.title=\"%s\";" (or default emptytag))) + (xwidget-webkit-execute-script xw (format "document.title=\"%s\";" + (or default emptytag))) (xwidget-webkit-execute-script xw (format "document.title=%s;" script)) (setq title (xwidget-webkit-get-title xw)) (if (equal emptytag title) @@ -482,7 +517,7 @@ DEFAULT is the defaultreturn value." title)) -;; use declare here? +;; Use declare here? ;; (declare-function xwidget-resize-internal "xwidget.c" ) ;; check-declare-function? @@ -499,7 +534,7 @@ DEFAULT is the defaultreturn value." ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; xwidget plist management(similar to the process plist functions) +;; Xwidget plist management(similar to the process plist functions) (defun xwidget-get (xwidget propname) "Return the value of XWIDGET' PROPNAME property. @@ -525,17 +560,17 @@ It can be retrieved with `(xwidget-get XWIDGET PROPNAME)'." (defun xwidget-cleanup () "Delete zombie xwidgets." - ;;its still pretty easy to trigger bugs with xwidgets. - ;;this function tries to implement a workaround + ;; During development it was sometimes easy to wind up with zombie + ;; xwidget instances. + ;; This function tries to implement a workaround should it occur again. (interactive) - ;; kill xviews who should have been deleted but stull linger + ;; Kill xviews who should have been deleted but stull linger. (xwidget-delete-zombies) - ;; redraw display otherwise ghost of zombies will remain to haunt the screen + ;; Redraw display otherwise ghost of zombies will remain to haunt the screen (redraw-display)) -;;this is a workaround because I cant find the right place to put it in C -;;seems to work well in practice though -;;(add-hook 'window-configuration-change-hook 'xwidget-cleanup) +;; This would have felt better in C, but this seems to work well in +;; practice though. (add-hook 'window-configuration-change-hook 'xwidget-delete-zombies) (defun xwidget-kill-buffer-query-function () @@ -549,20 +584,6 @@ It can be retrieved with `(xwidget-get XWIDGET PROPNAME)'." (add-hook 'kill-buffer-query-functions 'xwidget-kill-buffer-query-function) -;;killflash is sadly not reliable yet. -(defvar xwidget-webkit-kill-flash-oneshot t) -(defun xwidget-webkit-kill-flash () - "Disable the flash plugin in webkit. -This is needed because Flash is non-free and doesnt work reliably -on 64 bit systems and offscreen rendering. Sadly not reliable -yet, so deinstall Flash instead for now." - ;;you can only call this once or webkit crashes and takes emacs with it. odd. - (unless xwidget-webkit-kill-flash-oneshot - (xwidget-disable-plugin-for-mime "application/x-shockwave-flash") - (setq xwidget-webkit-kill-flash-oneshot t))) - -(xwidget-webkit-kill-flash) - (defun report-xwidget-bug () "Report a bug in GNU Emacs about the XWidget branch. Prompts for bug subject. Leaves you in a mail buffer." @@ -571,7 +592,7 @@ Prompts for bug subject. Leaves you in a mail buffer." (reporter-submit-bug-report "submit@debbugs.gnu.org" nil nil nil nil (format "Package: emacs-xwidgets -Please describee xactly whata ctions triggered the bug, and the +Please describe exactly what actions triggered the bug, and the precise symptoms of the bug. If you can, give a recipe starting from `emacs -Q'. diff --git a/src/xwidget.c b/src/xwidget.c index fb1a98786a7..71f9cf62738 100644 --- a/src/xwidget.c +++ b/src/xwidget.c @@ -759,23 +759,6 @@ from the exec method. */ ) return build_string (str); } -DEFUN ("xwidget-disable-plugin-for-mime", - Fxwidget_disable_plugin_for_mime, Sxwidget_disable_plugin_for_mime, - 1, 1, 0, doc: /* */ ) - (Lisp_Object mime) -{ - WebKitWebPlugin *wp = webkit_web_plugin_database_get_plugin_for_mimetype - (webkit_get_web_plugin_database (), SSDATA (mime)); - if (wp == NULL) - return Qnil; - if (webkit_web_plugin_get_enabled (wp)) - { - webkit_web_plugin_set_enabled (wp, FALSE); - return Qt; - } - return Qnil; -} - DEFUN ("xwidget-resize", Fxwidget_resize, Sxwidget_resize, 3, 3, 0, doc: /* Resize XWIDGET. NEW_WIDTH NEW_HEIGHT defines the new size.) @@ -1112,7 +1095,6 @@ syms_of_xwidget (void) defsubr (&Sxwidget_size_request); defsubr (&Sdelete_xwidget_view); - defsubr (&Sxwidget_disable_plugin_for_mime); defsubr (&Sxwidget_plist); defsubr (&Sxwidget_buffer);