[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kfm-devel
Subject:    Re: [PATCH] JS Form Popups
From:       Ralf Hoelzer <ralf () well ! com>
Date:       2003-06-04 18:57:36
[Download RAW message or body]

Thanks for your comments. I gave it another shot :). The new patch is 
attached. 

> wonder if the message shouldn't be a bit different, to explain that
> answering "no" will NOT submit the form? It's a bit different from "no
> popups please" - here the form will not be posted, which in some cases is
> much worse than the resulting popup...

You are right, the wording should mention this is a form submission. I changed 
that. I guess this gives the KMessageBox code a right to be there now.

> Maybe it would also be clearer (and safer) if the if() that tests the
> windowopenpolicy was the very first thing, around all this. Just to make
> sure we don't affect the behaviour in the other cases due to some mistake
> in this code (in the future :).

All the checks are now only done, if the policy is not "allow".

> As I see it the logic should be:
> if ( policy is to ask )
> {
>  do all checks to see if we need to ask;
>   if (we need to ask) {
>      ask();
>       -> if the user chose no, return.
>   }
> }
> submit.   << the only call to submit, in fact.

This is pretty much how I've done it now, with the only difference that it 
distinguishes between "ask" and "smart/deny".

regards,
Ralf


["popup2.patch" (text/x-diff)]

Index: kjs_html.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/ecma/kjs_html.cpp,v
retrieving revision 1.245
diff -u -p -r1.245 kjs_html.cpp
--- kjs_html.cpp	23 Apr 2003 17:55:46 -0000	1.245
+++ kjs_html.cpp	4 Jun 2003 19:03:41 -0000
@@ -54,6 +54,10 @@
 #include "rendering/render_object.h"
 #include "rendering/render_root.h"
 
+#include "kmessagebox.h"
+#include <kstringhandler.h>
+#include <klocale.h>
+
 #include <kdebug.h>
 
 using namespace KJS;
@@ -2108,7 +2112,47 @@ Value KJS::HTMLElementFunction::tryCall(
     case ID_FORM: {
       DOM::HTMLFormElement form = element;
       if (id == KJS::HTMLElement::FormSubmit) {
-        form.submit();
+      
+        
+        DOM::HTMLDocument doc = element.ownerDocument();
+        KHTMLView *view = static_cast<DOM::DocumentImpl*>(doc.handle())->view();
+        KHTMLSettings::KJSWindowOpenPolicy policy =
+               view->part()->settings()->windowOpenPolicy(view->part()->url().host());
 +
+        bool block = false;
+
+        if ( policy != KHTMLSettings::KJSWindowOpenAllow ) {
+	
+          block = true;
+	
+          // if this is a form without a target, don't block
+          if( form.target().isEmpty() )
+            block = false;
+
+          // if there is a frame with the target name, don't block
+          if ( (view && view->part() && view->part()->parentPart())   ) {
+            if( view->part()->parentPart()->frameExists( form.target().string() ) ) \
{ +	      block = false;
+            }
+          }
+
+          if ( block && policy == KHTMLSettings::KJSWindowOpenAsk ) {
+       
+            if ( KMessageBox::questionYesNo(view, form.action().isEmpty() ?
+                   i18n( "This site is submitting a form which will open up a new \
browser " +                         "window via JavaScript.\n"
+                         "Do you want to allow the form to be submitted?" ) :
+                   i18n( "<qt>This site is submitting a form which will open \
<p>%1</p> in a new browser window via JavaScript.<br />" +                         \
"Do you want to allow the form to be \
submitted?</qt>").arg(KStringHandler::csqueeze(form.action().string(),  100)), +      \
i18n( "Confirmation: JavaScript Popup" ) ) == KMessageBox::Yes )  +              \
block = false; +	    
+          }
+        }
+
+        if( !block ) 
+	  form.submit();
+
         return Undefined();
       }
       else if (id == KJS::HTMLElement::FormReset) {



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic