WebCore:

2008-11-04  Sam Weinig  <sam@webkit.org>

        Reviewed by Simon Hausmann.

        Fix https://bugs.webkit.org/show_bug.cgi?id=21648
        navigator.mimeTypes and navigator.plugins don't expose item and namedItem to JS

        - Also adds constructors for Plugin, PluginArray, MimeType and MimeTypeArray.

        * bindings/js/JSMimeTypeArrayCustom.cpp:
        (WebCore::JSMimeTypeArray::nameGetter):
        * bindings/js/JSPluginArrayCustom.cpp:
        (WebCore::JSPluginArray::nameGetter):
        * page/DOMWindow.idl:
        * plugins/MimeType.idl:
        * plugins/MimeTypeArray.cpp:
        (WebCore::MimeTypeArray::namedItem):
        * plugins/MimeTypeArray.h:
        * plugins/MimeTypeArray.idl:
        * plugins/Plugin.idl:
        * plugins/PluginArray.cpp:
        (WebCore::PluginArray::namedItem):
        * plugins/PluginArray.h:
        * plugins/PluginArray.idl:

LayoutTests:

2008-11-04  Sam Weinig  <sam@webkit.org>

        Reviewed by Simon Hausmann.

        Update tests for https://bugs.webkit.org/show_bug.cgi?id=21648
        navigator.mimeTypes and navigator.plugins don't expose item and namedItem to JS

        * fast/dom/Window/window-properties-expected.txt:
        * fast/js/global-constructors-expected.txt:
        * plugins/plugin-javascript-access-expected.txt:
        * plugins/plugin-javascript-access.html:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@38129 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 0926bdd..9915a01 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,15 @@
+2008-11-04  Sam Weinig  <sam@webkit.org>
+
+        Reviewed by Simon Hausmann.
+
+        Update tests for https://bugs.webkit.org/show_bug.cgi?id=21648
+        navigator.mimeTypes and navigator.plugins don't expose item and namedItem to JS
+
+        * fast/dom/Window/window-properties-expected.txt:
+        * fast/js/global-constructors-expected.txt:
+        * plugins/plugin-javascript-access-expected.txt:
+        * plugins/plugin-javascript-access.html:
+
 2008-11-05  Pierre-Olivier Latour  <pol@apple.com>
 
         Rubber-stamped by Dan Bernstein.
diff --git a/LayoutTests/fast/dom/Window/window-properties-expected.txt b/LayoutTests/fast/dom/Window/window-properties-expected.txt
index 7561ff6..c961999 100644
--- a/LayoutTests/fast/dom/Window/window-properties-expected.txt
+++ b/LayoutTests/fast/dom/Window/window-properties-expected.txt
@@ -919,6 +919,12 @@
 window.MessagePort.prototype.removeEventListener [function]
 window.MessagePort.prototype.start [function]
 window.MessagePort.prototype.startConversation [function]
+window.MimeType [object MimeTypeConstructor]
+window.MimeType.prototype [object MimeTypePrototype]
+window.MimeTypeArray [object MimeTypeArrayConstructor]
+window.MimeTypeArray.prototype [object MimeTypeArrayPrototype]
+window.MimeTypeArray.prototype.item [function]
+window.MimeTypeArray.prototype.namedItem [function]
 window.MouseEvent [object MouseEventConstructor]
 window.MouseEvent.prototype [printed above as window.Event.prototype]
 window.MutationEvent [object MutationEventConstructor]
@@ -1034,6 +1040,13 @@
 window.OverflowEvent.HORIZONTAL [number]
 window.OverflowEvent.VERTICAL [number]
 window.OverflowEvent.prototype [printed above as window.Event.prototype]
+window.Plugin [object PluginConstructor]
+window.Plugin.prototype [object PluginPrototype]
+window.PluginArray [object PluginArrayConstructor]
+window.PluginArray.prototype [object PluginArrayPrototype]
+window.PluginArray.prototype.item [function]
+window.PluginArray.prototype.namedItem [function]
+window.PluginArray.prototype.refresh [function]
 window.ProcessingInstruction [object ProcessingInstructionConstructor]
 window.ProcessingInstruction.prototype [printed above as window.Node.prototype]
 window.ProgressEvent [object ProgressEventConstructor]
@@ -1436,13 +1449,10 @@
 window.clientInformation.cookieEnabled [boolean]
 window.clientInformation.javaEnabled [function]
 window.clientInformation.language [string]
-window.clientInformation.mimeTypes [object MimeTypeArray]
-window.clientInformation.mimeTypes.length [number]
+window.clientInformation.mimeTypes [printed above as window.MimeTypeArray.prototype]
 window.clientInformation.onLine [boolean]
 window.clientInformation.platform [string]
-window.clientInformation.plugins [object PluginArray]
-window.clientInformation.plugins.length [number]
-window.clientInformation.plugins.refresh [function]
+window.clientInformation.plugins [printed above as window.PluginArray.prototype]
 window.clientInformation.product [string]
 window.clientInformation.productSub [string]
 window.clientInformation.userAgent [string]
diff --git a/LayoutTests/fast/js/global-constructors-expected.txt b/LayoutTests/fast/js/global-constructors-expected.txt
index 53f3ed1b..0a19fad 100644
--- a/LayoutTests/fast/js/global-constructors-expected.txt
+++ b/LayoutTests/fast/js/global-constructors-expected.txt
@@ -108,6 +108,8 @@
 PASS MessageChannel.toString() is '[object MessageChannelConstructor]'
 PASS MessageEvent.toString() is '[object MessageEventConstructor]'
 PASS MessagePort.toString() is '[object MessagePortConstructor]'
+PASS MimeType.toString() is '[object MimeTypeConstructor]'
+PASS MimeTypeArray.toString() is '[object MimeTypeArrayConstructor]'
 PASS MouseEvent.toString() is '[object MouseEventConstructor]'
 PASS MutationEvent.toString() is '[object MutationEventConstructor]'
 PASS NamedNodeMap.toString() is '[object NamedNodeMapConstructor]'
@@ -117,6 +119,8 @@
 PASS Notation.toString() is '[object NotationConstructor]'
 PASS Option.toString() is '[object OptionConstructor]'
 PASS OverflowEvent.toString() is '[object OverflowEventConstructor]'
+PASS Plugin.toString() is '[object PluginConstructor]'
+PASS PluginArray.toString() is '[object PluginArrayConstructor]'
 PASS ProcessingInstruction.toString() is '[object ProcessingInstructionConstructor]'
 PASS ProgressEvent.toString() is '[object ProgressEventConstructor]'
 PASS Range.toString() is '[object RangeConstructor]'
diff --git a/LayoutTests/plugins/plugin-javascript-access-expected.txt b/LayoutTests/plugins/plugin-javascript-access-expected.txt
index e750227..26e7662 100644
--- a/LayoutTests/plugins/plugin-javascript-access-expected.txt
+++ b/LayoutTests/plugins/plugin-javascript-access-expected.txt
@@ -13,4 +13,16 @@
 Suffixes: testnetscape
 
 
+PluginArray.item() works.
 
+PluginArray.namedItem() works.
+
+Type: application/x-webkit-test-netscape
+
+Description: test netscape content
+
+Suffixes: testnetscape
+
+MimeTypeArray.item() works.
+
+MimeTypeArray.namedItem() works.
diff --git a/LayoutTests/plugins/plugin-javascript-access.html b/LayoutTests/plugins/plugin-javascript-access.html
index 223d928..418c6fd 100644
--- a/LayoutTests/plugins/plugin-javascript-access.html
+++ b/LayoutTests/plugins/plugin-javascript-access.html
@@ -8,15 +8,13 @@
 if (window.layoutTestController)
     layoutTestController.dumpAsText()
 
-var plugins = navigator.plugins;
-
-plugins.refresh(false); // Supposedly helps if new plug-ins were added.
+navigator.plugins.refresh(false); // Supposedly helps if new plug-ins were added.
 
 var foundTestPlugin = false;
 
-for (var pi = 0; pi != plugins.length; pi++) {
-    var plugin = plugins[pi];
-    
+for (var i = 0; i < navigator.plugins.length; i++) {
+    var plugin = navigator.plugins[i];
+
     // We can only guarantee that the Test PlugIn is installed.
     if (plugin.name != "WebKit Test PlugIn")
         continue;
@@ -34,6 +32,42 @@
         document.writeln("<p>Suffixes: " + plugin[mi].suffixes + "<\/p>");
         document.writeln("<br>");
     }
+
+    if (navigator.plugins.item(i).name == plugin.name) {
+        document.writeln("<p>PluginArray.item() works.<\/p>");
+    } else {
+        document.writeln("<p>FAIL. PluginArray.item() does not work.<\/p>");
+    }
+
+    if (navigator.plugins.namedItem(plugin.name).name == plugin.name) {
+        document.writeln("<p>PluginArray.namedItem() works.<\/p>");
+    } else {
+        document.writeln("<p>FAIL. PluginArray.namedItem() does not work.<\/p>");
+    }
+}
+
+for (var i = 0; i < navigator.mimeTypes.length; i++) {
+    var mimeType = navigator.mimeTypes[i];
+
+    // We can only guarantee that the Test PlugIn is installed.
+    if (mimeType.type != "application/x-webkit-test-netscape")
+        continue;
+
+    document.writeln("<p>Type: " + mimeType.type + "<\/p>");
+    document.writeln("<p>Description: " + mimeType.description + "<\/p>");
+    document.writeln("<p>Suffixes: " + mimeType.suffixes + "<\/p>");
+
+    if (navigator.mimeTypes.item(i).type == mimeType.type) {
+        document.writeln("<p>MimeTypeArray.item() works.<\/p>");
+    } else {
+        document.writeln("<p>FAIL. MimeTypeArray.item() does not work.<\/p>");
+    }
+
+    if (navigator.mimeTypes.namedItem(mimeType.type).type == mimeType.type) {
+        document.writeln("<p>MimeTypeArray.namedItem() works.<\/p>");
+    } else {
+        document.writeln("<p>FAIL. MimeTypeArray.namedItem() does not work.<\/p>");
+    }
 }
 
 if (!foundTestPlugin)
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 14b6789..2064b77 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,28 @@
+2008-11-04  Sam Weinig  <sam@webkit.org>
+
+        Reviewed by Simon Hausmann.
+
+        Fix https://bugs.webkit.org/show_bug.cgi?id=21648
+        navigator.mimeTypes and navigator.plugins don't expose item and namedItem to JS
+
+        - Also adds constructors for Plugin, PluginArray, MimeType and MimeTypeArray.
+
+        * bindings/js/JSMimeTypeArrayCustom.cpp:
+        (WebCore::JSMimeTypeArray::nameGetter):
+        * bindings/js/JSPluginArrayCustom.cpp:
+        (WebCore::JSPluginArray::nameGetter):
+        * page/DOMWindow.idl:
+        * plugins/MimeType.idl:
+        * plugins/MimeTypeArray.cpp:
+        (WebCore::MimeTypeArray::namedItem):
+        * plugins/MimeTypeArray.h:
+        * plugins/MimeTypeArray.idl:
+        * plugins/Plugin.idl:
+        * plugins/PluginArray.cpp:
+        (WebCore::PluginArray::namedItem):
+        * plugins/PluginArray.h:
+        * plugins/PluginArray.idl:
+
 2008-11-05  Steve Falkenburg  <sfalken@apple.com>
 
         Build fix.
diff --git a/WebCore/bindings/js/JSMimeTypeArrayCustom.cpp b/WebCore/bindings/js/JSMimeTypeArrayCustom.cpp
index 7cbba53..2dbb811 100644
--- a/WebCore/bindings/js/JSMimeTypeArrayCustom.cpp
+++ b/WebCore/bindings/js/JSMimeTypeArrayCustom.cpp
@@ -1,5 +1,6 @@
 /*
  *  Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+ *  Copyright (C) 2008 Apple Inc. All rights reserved.
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Lesser General Public
@@ -20,6 +21,7 @@
 #include "JSMimeTypeArray.h"
 
 #include "AtomicString.h"
+#include "JSMimeType.h"
 #include "MimeTypeArray.h"
 
 namespace WebCore {
@@ -34,7 +36,7 @@
 JSValue* JSMimeTypeArray::nameGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot)
 {
     JSMimeTypeArray* thisObj = static_cast<JSMimeTypeArray*>(asObject(slot.slotBase()));
-    return toJS(exec, thisObj->impl()->nameGetter(propertyName));
+    return toJS(exec, thisObj->impl()->namedItem(propertyName));
 }
 
-}
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSPluginArrayCustom.cpp b/WebCore/bindings/js/JSPluginArrayCustom.cpp
index eb379a7..c753e57 100644
--- a/WebCore/bindings/js/JSPluginArrayCustom.cpp
+++ b/WebCore/bindings/js/JSPluginArrayCustom.cpp
@@ -1,5 +1,6 @@
 /*
  *  Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+ *  Copyright (C) 2008 Apple Inc. All rights reserved.
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Lesser General Public
@@ -20,6 +21,7 @@
 #include "JSPluginArray.h"
 
 #include "AtomicString.h"
+#include "JSPlugin.h"
 #include "PluginArray.h"
 
 namespace WebCore {
@@ -34,7 +36,7 @@
 JSValue* JSPluginArray::nameGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot)
 {
     JSPluginArray* thisObj = static_cast<JSPluginArray*>(asObject(slot.slotBase()));
-    return toJS(exec, thisObj->impl()->nameGetter(propertyName));
+    return toJS(exec, thisObj->impl()->namedItem(propertyName));
 }
 
-}
+} // namespace WebCore
diff --git a/WebCore/page/DOMWindow.idl b/WebCore/page/DOMWindow.idl
index ca935ecb..39f261d 100644
--- a/WebCore/page/DOMWindow.idl
+++ b/WebCore/page/DOMWindow.idl
@@ -364,6 +364,12 @@
         attribute XMLHttpRequestUploadConstructor XMLHttpRequestUpload;
         attribute XMLHttpRequestExceptionConstructor XMLHttpRequestException;
 
+        attribute PluginConstructor Plugin;
+        attribute PluginArrayConstructor PluginArray;
+
+        attribute MimeTypeConstructor MimeType;
+        attribute MimeTypeArrayConstructor MimeTypeArray;
+
 #if ENABLE_DOM_STORAGE
         attribute StorageConstructor Storage;
         attribute StorageEventConstructor StorageEvent;
diff --git a/WebCore/plugins/MimeType.idl b/WebCore/plugins/MimeType.idl
index ac75cc2..71fcca2 100644
--- a/WebCore/plugins/MimeType.idl
+++ b/WebCore/plugins/MimeType.idl
@@ -1,5 +1,6 @@
 /*
     Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+    Copyright (C) 2008 Apple Inc. All rights reserved.
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Library General Public
@@ -19,7 +20,9 @@
 
 module window {
 
-    interface MimeType {
+    interface [
+        GenerateConstructor
+    ] MimeType {
         readonly attribute DOMString type;
         readonly attribute DOMString suffixes;
         readonly attribute DOMString description;
diff --git a/WebCore/plugins/MimeTypeArray.cpp b/WebCore/plugins/MimeTypeArray.cpp
index 9bc4fcf..7fabad7 100644
--- a/WebCore/plugins/MimeTypeArray.cpp
+++ b/WebCore/plugins/MimeTypeArray.cpp
@@ -1,5 +1,6 @@
 /*
  *  Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+ *  Copyright (C) 2008 Apple Inc. All rights reserved.
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Lesser General Public
@@ -68,7 +69,7 @@
     return false;
 }
 
-PassRefPtr<MimeType> MimeTypeArray::nameGetter(const AtomicString& propertyName)
+PassRefPtr<MimeType> MimeTypeArray::namedItem(const AtomicString& propertyName)
 {
     PluginData *data = getPluginData();
     if (!data)
diff --git a/WebCore/plugins/MimeTypeArray.h b/WebCore/plugins/MimeTypeArray.h
index 392a812..a1e3d52 100644
--- a/WebCore/plugins/MimeTypeArray.h
+++ b/WebCore/plugins/MimeTypeArray.h
@@ -1,5 +1,6 @@
 /*
     Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+    Copyright (C) 2008 Apple Inc. All rights reserved.
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Library General Public
@@ -25,19 +26,12 @@
 #include <wtf/RefCounted.h>
 #include <wtf/Vector.h>
 
-namespace JSC {
-    class ExecState;
-};
-
 namespace WebCore {
 
     class AtomicString;
     class Frame;
     class PluginData;
 
-    // FIXME: Generated JSMimeTypeArray.cpp doesn't include JSMimeType.h for toJS
-    JSC::JSValue* toJS(JSC::ExecState*, MimeType*);
-
     class MimeTypeArray : public RefCounted<MimeTypeArray> {
     public:
         static PassRefPtr<MimeTypeArray> create(Frame* frame) { return adoptRef(new MimeTypeArray(frame)); }
@@ -48,13 +42,15 @@
         unsigned length() const;
         PassRefPtr<MimeType> item(unsigned index);
         bool canGetItemsForName(const AtomicString& propertyName);
-        PassRefPtr<MimeType> nameGetter(const AtomicString& propertyName);
+        PassRefPtr<MimeType> namedItem(const AtomicString& propertyName);
+
     private:
         MimeTypeArray(Frame*);
         PluginData* getPluginData() const;
 
         Frame* m_frame;
     };
-}
 
-#endif
+} // namespace WebCore
+
+#endif // MimeTypeArray_h
diff --git a/WebCore/plugins/MimeTypeArray.idl b/WebCore/plugins/MimeTypeArray.idl
index 067f2a8..5316d567 100644
--- a/WebCore/plugins/MimeTypeArray.idl
+++ b/WebCore/plugins/MimeTypeArray.idl
@@ -1,5 +1,6 @@
 /*
     Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+    Copyright (C) 2008 Apple Inc. All rights reserved.
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Library General Public
@@ -19,8 +20,14 @@
 
 module window {
 
-    interface [HasNameGetter, HasIndexGetter] MimeTypeArray {
+    interface [
+        GenerateConstructor,
+        HasNameGetter,
+        HasIndexGetter
+    ] MimeTypeArray {
         readonly attribute unsigned long length;
+        MimeType item(in unsigned long index);
+        MimeType namedItem(in DOMString name);
     };
 
 }
diff --git a/WebCore/plugins/Plugin.idl b/WebCore/plugins/Plugin.idl
index 988f371..22debca 100644
--- a/WebCore/plugins/Plugin.idl
+++ b/WebCore/plugins/Plugin.idl
@@ -1,5 +1,6 @@
 /*
     Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+    Copyright (C) 2008 Apple Inc. All rights reserved.
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Library General Public
@@ -19,7 +20,11 @@
 
 module window {
 
-    interface [HasNameGetter, HasIndexGetter] Plugin {
+    interface [
+        GenerateConstructor,
+        HasNameGetter,
+        HasIndexGetter
+    ] Plugin {
         readonly attribute DOMString name;
         readonly attribute DOMString filename;
         readonly attribute DOMString description;
diff --git a/WebCore/plugins/PluginArray.cpp b/WebCore/plugins/PluginArray.cpp
index d304829..b37d3c0 100644
--- a/WebCore/plugins/PluginArray.cpp
+++ b/WebCore/plugins/PluginArray.cpp
@@ -1,5 +1,6 @@
 /*
  *  Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+ *  Copyright (C) 2008 Apple Inc. All rights reserved.
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Lesser General Public
@@ -68,7 +69,7 @@
     return false;
 }
 
-PassRefPtr<Plugin> PluginArray::nameGetter(const AtomicString& propertyName)
+PassRefPtr<Plugin> PluginArray::namedItem(const AtomicString& propertyName)
 {
     PluginData* data = getPluginData();
     if (!data)
diff --git a/WebCore/plugins/PluginArray.h b/WebCore/plugins/PluginArray.h
index e51775d..197ac88f 100644
--- a/WebCore/plugins/PluginArray.h
+++ b/WebCore/plugins/PluginArray.h
@@ -1,5 +1,6 @@
 /*
     Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+    Copyright (C) 2008 Apple Inc. All rights reserved.
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Library General Public
@@ -25,19 +26,12 @@
 #include <wtf/RefCounted.h>
 #include <wtf/Vector.h>
 
-namespace JSC {
-    class ExecState;
-}
-
 namespace WebCore {
 
     class AtomicString;
     class Frame;
     class PluginData;
 
-    // FIXME: Generated JSPluginArray.cpp doesn't include JSPlugin.h for toJS
-    JSC::JSValue* toJS(JSC::ExecState*, Plugin*);
-
     class PluginArray : public RefCounted<PluginArray> {
     public:
         static PassRefPtr<PluginArray> create(Frame* frame) { return adoptRef(new PluginArray(frame)); }
@@ -48,15 +42,17 @@
         unsigned length() const;
         PassRefPtr<Plugin> item(unsigned index);
         bool canGetItemsForName(const AtomicString& propertyName);
-        PassRefPtr<Plugin> nameGetter(const AtomicString& propertyName);
+        PassRefPtr<Plugin> namedItem(const AtomicString& propertyName);
 
         void refresh(bool reload);
+
     private:
         PluginArray(Frame*);
         PluginData* getPluginData() const;
 
         Frame* m_frame;
     };
-}
 
-#endif
+} // namespace WebCore
+
+#endif // PluginArray_h
diff --git a/WebCore/plugins/PluginArray.idl b/WebCore/plugins/PluginArray.idl
index 58f68b5..4a55c56 100644
--- a/WebCore/plugins/PluginArray.idl
+++ b/WebCore/plugins/PluginArray.idl
@@ -1,5 +1,6 @@
 /*
     Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+    Copyright (C) 2008 Apple Inc. All rights reserved.
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Library General Public
@@ -19,8 +20,14 @@
 
 module window {
 
-    interface [HasNameGetter, HasIndexGetter] PluginArray {
+    interface [
+        GenerateConstructor,
+        HasNameGetter, 
+        HasIndexGetter
+    ] PluginArray {
         readonly attribute unsigned long length;
+        Plugin item(in unsigned long index);
+        Plugin namedItem(in DOMString name);
         void refresh(in boolean reload);
     };