WebCore:
authoradele <adele@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 Sep 2006 00:17:45 +0000 (00:17 +0000)
committeradele <adele@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 Sep 2006 00:17:45 +0000 (00:17 +0000)
        Reviewed by Darin.

        WebCore part of fix for http://bugzilla.opendarwin.org/show_bug.cgi?id=10666
        Password: Disallow Spelling, Font, Speech, and Writing Direction context menu

        * bridge/mac/WebCoreFrameBridge.h:
        * bridge/mac/WebCoreFrameBridge.mm: (-[WebCoreFrameBridge isSelectionInPasswordField]): Added.
        * page/Frame.cpp: (WebCore::Frame::isSelectionInPasswordField): Added.
        * page/Frame.h:

WebKit:

        Reviewed by Darin.

        WebKit part of fix for http://bugzilla.opendarwin.org/show_bug.cgi?id=10666
        Password: Disallow Spelling, Font, Speech, and Writing Direction context menu

        * DefaultDelegates/WebDefaultContextMenuDelegate.m: (-[WebDefaultUIDelegate editingContextMenuItemsForElement:defaultMenuItems:]):
          Check that the selection isn't in a password field before adding these items to the default editing context menu.
              Search In Google, Search In Spotlight, Look up in Dictionary, Spelling, Font, Speech, Writing Direction
        * WebView/WebHTMLView.m: (-[WebHTMLView _isSelectionInPasswordField]): Added.
        * WebView/WebHTMLViewPrivate.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@16167 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/bridge/mac/WebCoreFrameBridge.h
WebCore/bridge/mac/WebCoreFrameBridge.mm
WebCore/page/Frame.cpp
WebCore/page/Frame.h
WebKit/ChangeLog
WebKit/DefaultDelegates/WebDefaultContextMenuDelegate.m
WebKit/WebView/WebHTMLView.m
WebKit/WebView/WebHTMLViewPrivate.h

index 933f341a0da43ac006ed6669ef1a79c185d9c09e..487b80632607a04658a3276dae49b83f3a689c61 100644 (file)
@@ -1,3 +1,15 @@
+2006-08-31  Adele Peterson  <adele@apple.com>
+
+        Reviewed by Darin.
+
+        WebCore part of fix for http://bugzilla.opendarwin.org/show_bug.cgi?id=10666
+        Password: Disallow Spelling, Font, Speech, and Writing Direction context menu
+
+        * bridge/mac/WebCoreFrameBridge.h:
+        * bridge/mac/WebCoreFrameBridge.mm: (-[WebCoreFrameBridge isSelectionInPasswordField]): Added.
+        * page/Frame.cpp: (WebCore::Frame::isSelectionInPasswordField): Added.
+        * page/Frame.h:
+
 2006-08-31  Anders Carlsson  <acarlsson@apple.com>
 
         Reviewed by Tim O, Hyatt.
index 5168adc108ed49cda79cd7bc463b8ee201174ca3..97c26991e47784a684fe64916e788e1092bf4d2c 100644 (file)
@@ -330,6 +330,7 @@ typedef enum {
 - (DOMDocument *)DOMDocument;
 - (DOMHTMLElement *)frameElement;
 
+- (BOOL)isSelectionInPasswordField;
 - (BOOL)isSelectionEditable;
 - (BOOL)isSelectionRichlyEditable;
 - (WebSelectionState)selectionState;
index 2684dca23adb4020e88c741327155d247579f285..a468962ade57176ad96ecb27ec36bd87bb145995 100644 (file)
@@ -741,6 +741,11 @@ static inline WebCoreFrameBridge *bridge(Frame *frame)
         frameView->setMarginHeight(mh);
 }
 
+- (BOOL)isSelectionInPasswordField
+{
+    return m_frame->isSelectionInPasswordField();
+}
+
 - (BOOL)isSelectionEditable
 {
     return m_frame->selection().isContentEditable();
index b035995b021cda904ac9ffe2e46e4b6ab2665fed..21c282e42be41c62d6b5749fc244320528539523 100644 (file)
@@ -2026,6 +2026,14 @@ void Frame::textDidChangeInTextArea(Element* input)
 {
 }
 
+bool Frame::isSelectionInPasswordField()
+{
+    Node* startNode = selection().start().node();
+    if (startNode)
+        startNode = startNode->shadowAncestorNode();
+    return startNode && startNode->hasTagName(inputTag) && static_cast<HTMLInputElement*>(startNode)->inputType() == HTMLInputElement::PASSWORD;
+}
+  
 EditCommand* Frame::lastEditCommand()
 {
     return d->m_lastEditCommand.get();
index 616b9455e704d37d329abfb547d58cec2f1ceead..3b0469ba6e5e238188fc30a8e2d9be7616d33967 100644 (file)
@@ -420,6 +420,8 @@ public:
   virtual void setSecureKeyboardEntry(bool) {};
   virtual bool secureKeyboardEntry() { return false; }
   
+  bool isSelectionInPasswordField();
+  
   /**
    * Returns the most recent edit command applied.
    */
index 36a761652a0bb88758676eb2864a973910f6c396..dd1e90c5b9d991c01f3e417b164db1a7c23c64af 100644 (file)
@@ -1,3 +1,16 @@
+2006-08-31  Adele Peterson  <adele@apple.com>
+
+        Reviewed by Darin.
+
+        WebKit part of fix for http://bugzilla.opendarwin.org/show_bug.cgi?id=10666
+        Password: Disallow Spelling, Font, Speech, and Writing Direction context menu
+
+        * DefaultDelegates/WebDefaultContextMenuDelegate.m: (-[WebDefaultUIDelegate editingContextMenuItemsForElement:defaultMenuItems:]):
+          Check that the selection isn't in a password field before adding these items to the default editing context menu.
+              Search In Google, Search In Spotlight, Look up in Dictionary, Spelling, Font, Speech, Writing Direction
+        * WebView/WebHTMLView.m: (-[WebHTMLView _isSelectionInPasswordField]): Added.
+        * WebView/WebHTMLViewPrivate.h:
+
 2006-08-31  Sam Weinig  <sam.weinig@gmail.com>
 
         Reviewed by Tim H.
index 93ef90cb82ea7732c7818e48aecadb1e1562f7a4..3fa205e17198fb4cf95cfad8462185ca44f58820 100644 (file)
@@ -270,9 +270,10 @@ static NSString *localizedMenuTitleFromAppKit(NSString *key, NSString *comment)
     NSMenuItem *item;
     WebHTMLView *HTMLView = (WebHTMLView *)[[[element objectForKey:WebElementFrameKey] frameView] documentView];
     ASSERT([HTMLView isKindOfClass:[WebHTMLView class]]);
-    
+    BOOL inPasswordField = [HTMLView _isSelectionInPasswordField];
+
     // Add spelling-related context menu items.
-    if ([HTMLView _isSelectionMisspelled]) {
+    if ([HTMLView _isSelectionMisspelled] && !inPasswordField) {
         NSArray *guesses = [HTMLView _guessesForMisspelledSelection];
         unsigned count = [guesses count];
         if (count > 0) {
@@ -292,7 +293,7 @@ static NSString *localizedMenuTitleFromAppKit(NSString *key, NSString *comment)
         [menuItems addObject:[NSMenuItem separatorItem]];
     }
 
-    if ([[element objectForKey:WebElementIsSelectedKey] boolValue]) {
+    if ([[element objectForKey:WebElementIsSelectedKey] boolValue] && !inPasswordField) {
         [menuItems addObject:[self menuItemWithTag:WebMenuItemTagSearchInSpotlight target:nil representedObject:element]];
         [menuItems addObject:[self menuItemWithTag:WebMenuItemTagSearchWeb target:nil representedObject:element]];
         [menuItems addObject:[NSMenuItem separatorItem]];
@@ -321,6 +322,7 @@ static NSString *localizedMenuTitleFromAppKit(NSString *key, NSString *comment)
         item = [item copy];
         SEL action = [item action];
         int tag;
+        bool validForPassword = true;
         if (action == @selector(cut:)) {
             tag = WebMenuItemTagCut;
         } else if (action == @selector(copy:)) {
@@ -330,10 +332,15 @@ static NSString *localizedMenuTitleFromAppKit(NSString *key, NSString *comment)
         } else {
             // FIXME 4158153: we should supply tags for each known item so clients can make
             // sensible decisions, like we do with PDF context menu items (see WebPDFView.m)
+
+            // Once we have other tag names, we should reconsider if any of them are valid for password fields.
             tag = WebMenuItemTagOther;
+            validForPassword = false;
+        }
+        if (!inPasswordField || validForPassword) {
+            [item setTag:tag];
+            [menuItems addObject:item];
         }
-        [item setTag:tag];
-        [menuItems addObject:item];
         [item release];
     }
     
index 400a645ddbcd2fe6c58fc46ba018ca0e1d37d19b..2b9f42277b0c123cb2151063bff5209d41364baf 100644 (file)
@@ -1650,6 +1650,11 @@ static WebHTMLView *lastHitView = nil;
     return [[self _webView] isEditable] || [[self _bridge] isSelectionEditable];
 }
 
+- (BOOL)_isSelectionInPasswordField
+{
+    return [[self _bridge] isSelectionInPasswordField];
+}
+
 - (BOOL)_isSelectionMisspelled
 {
     NSString *selectedString = [self selectedString];
index bd1059ba04b45b354e378ad0418a3d0beb1013ab..a5ed6c58bf89425fdf549879a220e924dae4703c 100644 (file)
@@ -92,6 +92,7 @@
 - (BOOL)_hasSelectionOrInsertionPoint;
 - (BOOL)_isEditable;
 
+- (BOOL)_isSelectionInPasswordField;
 - (BOOL)_isSelectionMisspelled;
 - (NSArray *)_guessesForMisspelledSelection;