[SCM] WebKit Debian packaging branch, webkit-1.2, updated. upstream/1.1.90-6072-g9a69373

dimich at chromium.org dimich at chromium.org
Wed Apr 7 23:20:35 UTC 2010


The following commit has been merged in the webkit-1.2 branch:
commit 6a13a8a3c2380972031876a5dd62d395cb8fc69c
Author: dimich at chromium.org <dimich at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Nov 3 21:12:24 2009 +0000

    WebCore: Implement window.navigator.registerProtocolHandler in webkit,
    https://bugs.webkit.org/b/29651
    
    Patch by Bradley Green <brg at chromium.org> on 2009-11-03
    Reviewed by Dmitry Titov.
    
    Also implemented its sister API window.navigator.registerContentHandler.
    
    These methods are as described in the HTML5 specification which can be
    found here,
    http://dev.w3.org/html5/spec/Overview.html#dom-navigator-registerprotocolhandler
    http://dev.w3.org/html5/spec/Overview.html#dom-navigator-registercontenthandler
    
    As specified in the document, the behavior of the browser is determined
    by the current registered handler.  The state of a registered handler
    can change at any time, with the user clearing a registered handler,
    registering a different page as handler, or deferring the hander to the
    OS.  If webkit was to track the state of the currently registered
    handlers, it would need more APIs and complexity to keep in sync with
    user actions reported to webkit from the UA.  For simplicity, the state
    of protocol handlers should be kept isolated from webkit and webkit only
    notifies the UA that a page has made the call.  The UA is then
    responsible for correctly handling the registerProtocolHandler call and
    the redirects which result from registration.
    
    We do however follow the specification in insuring that the reserved
    schemes and mimeTypes are not passed to the UA as custom handler
    registration tests.  We also insure that the "%s" token is present as
    required by the specification.
    
    Updated test expectations for window.clientInformation and navigator
    objects.
    
    Tests: fast/dom/registerContentHandler.html
           fast/dom/registerProtocolHandler.html
    
    * page/Chrome.cpp:
    (WebCore::Chrome::registerProtocolHandler):
    (WebCore::Chrome::registerContentHandler):
    * page/Chrome.h:
    * page/ChromeClient.h:
    (WebCore::ChromeClient::registerProtocolHandler):
    (WebCore::ChromeClient::registerContentHandler):
    * page/Navigator.cpp:
    (WebCore::verifyCustomHandlerURL):
    (WebCore::verifyProtocolHandlerScheme):
    (WebCore::Navigator::registerProtocolHandler):
    (WebCore::verifyProtocolHandlerMimeType):
    (WebCore::Navigator::registerContentHandler):
    * page/Navigator.h:
    * page/Navigator.idl:
    
    LayoutTests: Updating test expectations for implementation of
    window.navigator.registerProtocolHandler and
    window.navigator.registerContentHandler.
    
    Patch by Bradley Green <brg at chromium.org> on 2009-11-03
    Reviewed by Dmitry Titov.
    
    There is a default implimentation for these APIs, hence all platforms
    with the navigator-detached-no-crash-expect and
    window-properties-expected tests needed to be updated.  While
    isolatedWorlds has a window-properties-expected test, it has no window
    object and hence does not need to be updaetd.
    
    We add two fast/dom tests to insure that the proper exceptions are
    thrown when bad syntax or security violations are made by calling the
    methods.
    
    * fast/dom/Window/window-properties-expected.txt:
    * fast/dom/navigator-detached-no-crash-expected.txt:
    * fast/dom/navigator-detached-no-crash.html:
    * fast/dom/registerContentHandler-expected.txt: Added.
    * fast/dom/registerContentHandler.html: Added.
    * fast/dom/registerProtocolHandler-expected.txt: Added.
    * fast/dom/registerProtocolHandler.html: Added.
    * platform/gtk/fast/dom/Window/window-properties-expected.txt:
    * platform/gtk/fast/dom/navigator-detached-no-crash-expected.txt:
    * platform/mac-leopard/fast/dom/navigator-detached-no-crash-expected.txt:
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@50477 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 22b0100..1a3c827 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,32 @@
+2009-11-03  Bradley Green  <brg at chromium.org>
+
+        Reviewed by Dmitry Titov.
+
+        Updating test expectations for implementation of
+        window.navigator.registerProtocolHandler and
+        window.navigator.registerContentHandler.
+
+        There is a default implimentation for these APIs, hence all platforms
+        with the navigator-detached-no-crash-expect and
+        window-properties-expected tests needed to be updated.  While
+        isolatedWorlds has a window-properties-expected test, it has no window
+        object and hence does not need to be updaetd.
+
+        We add two fast/dom tests to insure that the proper exceptions are
+        thrown when bad syntax or security violations are made by calling the
+        methods.
+
+        * fast/dom/Window/window-properties-expected.txt:
+        * fast/dom/navigator-detached-no-crash-expected.txt:
+        * fast/dom/navigator-detached-no-crash.html:
+        * fast/dom/registerContentHandler-expected.txt: Added.
+        * fast/dom/registerContentHandler.html: Added.
+        * fast/dom/registerProtocolHandler-expected.txt: Added.
+        * fast/dom/registerProtocolHandler.html: Added.
+        * platform/gtk/fast/dom/Window/window-properties-expected.txt:
+        * platform/gtk/fast/dom/navigator-detached-no-crash-expected.txt:
+        * platform/mac-leopard/fast/dom/navigator-detached-no-crash-expected.txt:
+
 2009-11-03  Dan Bernstein  <mitz at apple.com>
 
         Reviewed by Anders Carlsson and Beth Dakin.
diff --git a/LayoutTests/fast/dom/Window/window-properties-expected.txt b/LayoutTests/fast/dom/Window/window-properties-expected.txt
index d41b764..6d4222a 100644
--- a/LayoutTests/fast/dom/Window/window-properties-expected.txt
+++ b/LayoutTests/fast/dom/Window/window-properties-expected.txt
@@ -1688,6 +1688,8 @@ window.clientInformation.platform [string]
 window.clientInformation.plugins [printed above as window.PluginArray.prototype]
 window.clientInformation.product [string]
 window.clientInformation.productSub [string]
+window.clientInformation.registerContentHandler [function]
+window.clientInformation.registerProtocolHandler [function]
 window.clientInformation.userAgent [string]
 window.clientInformation.vendor [string]
 window.clientInformation.vendorSub [string]
diff --git a/LayoutTests/fast/dom/navigator-detached-no-crash-expected.txt b/LayoutTests/fast/dom/navigator-detached-no-crash-expected.txt
index 95712ba..885c831 100644
--- a/LayoutTests/fast/dom/navigator-detached-no-crash-expected.txt
+++ b/LayoutTests/fast/dom/navigator-detached-no-crash-expected.txt
@@ -13,6 +13,8 @@ navigator.platform is OK
 navigator.plugins is OK
 navigator.product is OK
 navigator.productSub is OK
+navigator.registerContentHandler() threw err Error: SYNTAX_ERR: DOM Exception 12
+navigator.registerProtocolHandler() threw err Error: SYNTAX_ERR: DOM Exception 12
 navigator.userAgent is OK
 navigator.vendor is OK
 navigator.vendorSub is OK
@@ -29,6 +31,8 @@ navigator.platform is OK
 navigator.plugins is OK
 navigator.product is OK
 navigator.productSub is OK
+navigator.registerContentHandler() is OK
+navigator.registerProtocolHandler() is OK
 navigator.userAgent is OK
 navigator.vendor is OK
 navigator.vendorSub is OK
diff --git a/LayoutTests/fast/dom/navigator-detached-no-crash.html b/LayoutTests/fast/dom/navigator-detached-no-crash.html
index 21a3a95..afb1d92 100644
--- a/LayoutTests/fast/dom/navigator-detached-no-crash.html
+++ b/LayoutTests/fast/dom/navigator-detached-no-crash.html
@@ -53,9 +53,14 @@ function check_navigator() {
   var strings = [ ];
   for (p in old_nav) {
     if (typeof old_nav[p] == 'function') {
-      var v = old_nav[p]();
-      // no crash, it is ok
-      strings.push("navigator."+p+"() is OK");
+      try {
+        var v = old_nav[p]();
+        // no crash, it is ok
+        strings.push("navigator."+p+"() is OK");
+      } catch(err) {
+        // navigator.registerXXX will throw on invalid input.
+        strings.push("navigator."+p+"() threw err "+err);
+      }
     } else {
       var v = old_nav[p];
       // no crash, it is ok.
diff --git a/LayoutTests/fast/dom/registerContentHandler-expected.txt b/LayoutTests/fast/dom/registerContentHandler-expected.txt
new file mode 100644
index 0000000..3693571
--- /dev/null
+++ b/LayoutTests/fast/dom/registerContentHandler-expected.txt
@@ -0,0 +1,10 @@
+This test makes sure that navigator.registerContentHandler throws the proper exceptions and has no-op default implementation.
+
+Pass: window.navigator.registerContentHandler is defined.
+Pass: Invalid protocol "text/html" threw SECURITY_ERR exception.
+Pass: Invalid protocol "text/css" threw SECURITY_ERR exception.
+Pass: Invalid protocol "application/x-javascript" threw SECURITY_ERR exception.
+Pass: Invalid url "" threw SYNTAX_ERR exception.
+Pass: Invalid url "%S" threw SYNTAX_ERR exception.
+Pass: Valid call succeeded.
+
diff --git a/LayoutTests/fast/dom/registerContentHandler.html b/LayoutTests/fast/dom/registerContentHandler.html
new file mode 100644
index 0000000..dcc1fc0
--- /dev/null
+++ b/LayoutTests/fast/dom/registerContentHandler.html
@@ -0,0 +1,57 @@
+<html>
+<body>
+<p>This test makes sure that navigator.registerContentHandler throws the proper exceptions and has no-op default implementation.</p>
+<pre id="console"></pre>
+<script>
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+ }
+
+function debug(str) {
+    var c = document.getElementById('console');
+    c.appendChild(document.createTextNode(str + '\n'));
+};
+
+// Test availability of the registerContentHandler API
+if(window.navigator.registerContentHandler) {
+    debug('Pass: window.navigator.registerContentHandler is defined.')
+} else {
+    debug('Fail: window.navigator.registerContentHandler is not defined.')
+};
+
+// Test that the API regects secured protocols.
+var invalid_protocols = ['text/html', 'text/css', 'application/x-javascript'];
+invalid_protocols.forEach(function(protocol) {
+    try {
+        window.navigator.registerContentHandler(protocol, "invalid protocol %s", "title");
+        debug('Fail: Invalid protocol "' + protocol + '" allowed.');
+    } catch(e) {
+        if('SECURITY_ERR' == e.name) {
+            debug('Pass: Invalid protocol "' + protocol + '" threw SECURITY_ERR exception.');
+        }
+    };
+});
+
+// Test that the API correctly parses the url for '%s'
+var invalid_urls = ["", "%S"]
+invalid_urls.forEach(function(url) {
+    try {
+        window.navigator.registerContentHandler('myprotocol', url, 'title');
+        debug('Fail: Invalid url "' + url + '" allowed.');
+    } catch(e) {
+        if('SYNTAX_ERR' == e.name) {
+            debug('Pass: Invalid url "' + url + '" threw SYNTAX_ERR exception.');
+        }
+    };
+});
+
+// Test that the API has default no-op implementation.
+try {
+    window.navigator.registerContentHandler('myprotocol', "%s", "title");
+    debug('Pass: Valid call succeeded.');
+} catch(e) {
+    debug('Fail: Valid call did not succeed.');
+};
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/dom/registerProtocolHandler-expected.txt b/LayoutTests/fast/dom/registerProtocolHandler-expected.txt
new file mode 100644
index 0000000..55f420d
--- /dev/null
+++ b/LayoutTests/fast/dom/registerProtocolHandler-expected.txt
@@ -0,0 +1,10 @@
+This test makes sure that navigator.registerProtocolHandler throws the proper exceptions and has no-op default implementation.
+
+Pass: window.navigator.registerProtocolHandler is defined.
+Pass: Invalid protocol "http" threw SECURITY_ERR exception.
+Pass: Invalid protocol "https" threw SECURITY_ERR exception.
+Pass: Invalid protocol "file" threw SECURITY_ERR exception.
+Pass: Invalid url "" threw SYNTAX_ERR exception.
+Pass: Invalid url "%S" threw SYNTAX_ERR exception.
+Pass: Valid call succeeded.
+
diff --git a/LayoutTests/fast/dom/registerProtocolHandler.html b/LayoutTests/fast/dom/registerProtocolHandler.html
new file mode 100644
index 0000000..e4ef4b6
--- /dev/null
+++ b/LayoutTests/fast/dom/registerProtocolHandler.html
@@ -0,0 +1,57 @@
+<html>
+<body>
+<p>This test makes sure that navigator.registerProtocolHandler throws the proper exceptions and has no-op default implementation.</p>
+<pre id="console"></pre>
+<script>
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+ }
+
+function debug(str) {
+    var c = document.getElementById('console')
+    c.appendChild(document.createTextNode(str + '\n'));
+};
+
+// Test availability of the registerProtocolHandler API
+if(window.navigator.registerProtocolHandler) {
+    debug('Pass: window.navigator.registerProtocolHandler is defined.');
+} else {
+    debug('Fail: window.navigator.registerProtocolHandler is not defined.');
+};
+
+// Test that the API regects secured protocols.
+var invalid_protocols = ['http', 'https', 'file'];
+invalid_protocols.forEach(function(protocol) {
+    try {
+        window.navigator.registerProtocolHandler(protocol, "invalid protocol %s", "title");
+        debug('Fail: Invalid protocol "' + protocol + '" allowed.');
+    } catch(e) {
+        if('SECURITY_ERR' == e.name) {
+            debug('Pass: Invalid protocol "' + protocol + '" threw SECURITY_ERR exception.');
+        };
+    };
+});
+
+// Test that the API correctly parses the url for '%s'
+var invalid_urls = ["", "%S"];
+invalid_urls.forEach(function(url) {
+   try {
+        window.navigator.registerProtocolHandler('myprotocol', url, 'title');
+        debug('Fail: Invalid url "' + url + '" allowed.');
+    } catch(e) {
+        if('SYNTAX_ERR' == e.name) {
+            debug('Pass: Invalid url "' + url + '" threw SYNTAX_ERR exception.');
+        };
+    };
+});
+
+// Test that the API has default no-op implementation.
+try {
+    window.navigator.registerProtocolHandler('myprotocol', "%s", "title");
+    debug('Pass: Valid call succeeded.');
+} catch(e) {
+    debug('Fail: Valid call did not succeed.');
+};
+</script>
+</body>
+</html>
diff --git a/LayoutTests/platform/gtk/fast/dom/Window/window-properties-expected.txt b/LayoutTests/platform/gtk/fast/dom/Window/window-properties-expected.txt
index b101663..18017d6 100644
--- a/LayoutTests/platform/gtk/fast/dom/Window/window-properties-expected.txt
+++ b/LayoutTests/platform/gtk/fast/dom/Window/window-properties-expected.txt
@@ -1657,6 +1657,8 @@ window.clientInformation.platform [string]
 window.clientInformation.plugins [printed above as window.PluginArray.prototype]
 window.clientInformation.product [string]
 window.clientInformation.productSub [string]
+window.clientInformation.registerContentHandler [function]
+window.clientInformation.registerProtocolHandler [function]
 window.clientInformation.userAgent [string]
 window.clientInformation.vendor [string]
 window.clientInformation.vendorSub [string]
diff --git a/LayoutTests/platform/gtk/fast/dom/navigator-detached-no-crash-expected.txt b/LayoutTests/platform/gtk/fast/dom/navigator-detached-no-crash-expected.txt
index e9f31df..3b8020c 100644
--- a/LayoutTests/platform/gtk/fast/dom/navigator-detached-no-crash-expected.txt
+++ b/LayoutTests/platform/gtk/fast/dom/navigator-detached-no-crash-expected.txt
@@ -14,6 +14,8 @@ navigator.platform is OK
 navigator.plugins is OK
 navigator.product is OK
 navigator.productSub is OK
+navigator.registerContentHandler() threw err Error: SYNTAX_ERR: DOM Exception 12
+navigator.registerProtocolHandler() threw err Error: SYNTAX_ERR: DOM Exception 12
 navigator.userAgent is OK
 navigator.vendor is OK
 navigator.vendorSub is OK
@@ -31,6 +33,8 @@ navigator.platform is OK
 navigator.plugins is OK
 navigator.product is OK
 navigator.productSub is OK
+navigator.registerContentHandler() is OK
+navigator.registerProtocolHandler() is OK
 navigator.userAgent is OK
 navigator.vendor is OK
 navigator.vendorSub is OK
diff --git a/LayoutTests/platform/mac-leopard/fast/dom/navigator-detached-no-crash-expected.txt b/LayoutTests/platform/mac-leopard/fast/dom/navigator-detached-no-crash-expected.txt
index 95712ba..885c831 100644
--- a/LayoutTests/platform/mac-leopard/fast/dom/navigator-detached-no-crash-expected.txt
+++ b/LayoutTests/platform/mac-leopard/fast/dom/navigator-detached-no-crash-expected.txt
@@ -13,6 +13,8 @@ navigator.platform is OK
 navigator.plugins is OK
 navigator.product is OK
 navigator.productSub is OK
+navigator.registerContentHandler() threw err Error: SYNTAX_ERR: DOM Exception 12
+navigator.registerProtocolHandler() threw err Error: SYNTAX_ERR: DOM Exception 12
 navigator.userAgent is OK
 navigator.vendor is OK
 navigator.vendorSub is OK
@@ -29,6 +31,8 @@ navigator.platform is OK
 navigator.plugins is OK
 navigator.product is OK
 navigator.productSub is OK
+navigator.registerContentHandler() is OK
+navigator.registerProtocolHandler() is OK
 navigator.userAgent is OK
 navigator.vendor is OK
 navigator.vendorSub is OK
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index c554d1d..1b36046 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,56 @@
+2009-11-03  Bradley Green  <brg at chromium.org>
+
+        Reviewed by Dmitry Titov.
+
+        Implement window.navigator.registerProtocolHandler in webkit,
+        https://bugs.webkit.org/b/29651
+
+        Also implemented its sister API window.navigator.registerContentHandler.
+
+        These methods are as described in the HTML5 specification which can be
+        found here,
+        http://dev.w3.org/html5/spec/Overview.html#dom-navigator-registerprotocolhandler
+        http://dev.w3.org/html5/spec/Overview.html#dom-navigator-registercontenthandler
+
+        As specified in the document, the behavior of the browser is determined
+        by the current registered handler.  The state of a registered handler
+        can change at any time, with the user clearing a registered handler,
+        registering a different page as handler, or deferring the hander to the
+        OS.  If webkit was to track the state of the currently registered
+        handlers, it would need more APIs and complexity to keep in sync with
+        user actions reported to webkit from the UA.  For simplicity, the state
+        of protocol handlers should be kept isolated from webkit and webkit only
+        notifies the UA that a page has made the call.  The UA is then
+        responsible for correctly handling the registerProtocolHandler call and
+        the redirects which result from registration.
+
+        We do however follow the specification in insuring that the reserved
+        schemes and mimeTypes are not passed to the UA as custom handler
+        registration tests.  We also insure that the "%s" token is present as
+        required by the specification.
+
+        Updated test expectations for window.clientInformation and navigator
+        objects.
+
+        Tests: fast/dom/registerContentHandler.html
+               fast/dom/registerProtocolHandler.html
+
+        * page/Chrome.cpp:
+        (WebCore::Chrome::registerProtocolHandler):
+        (WebCore::Chrome::registerContentHandler):
+        * page/Chrome.h:
+        * page/ChromeClient.h:
+        (WebCore::ChromeClient::registerProtocolHandler):
+        (WebCore::ChromeClient::registerContentHandler):
+        * page/Navigator.cpp:
+        (WebCore::verifyCustomHandlerURL):
+        (WebCore::verifyProtocolHandlerScheme):
+        (WebCore::Navigator::registerProtocolHandler):
+        (WebCore::verifyProtocolHandlerMimeType):
+        (WebCore::Navigator::registerContentHandler):
+        * page/Navigator.h:
+        * page/Navigator.idl:
+
 2009-11-03  Brady Eidson  <beidson at apple.com>
 
         Reviewed by Darin Adler.
diff --git a/WebCore/page/Chrome.cpp b/WebCore/page/Chrome.cpp
index 62710dd..d7d1a57 100644
--- a/WebCore/page/Chrome.cpp
+++ b/WebCore/page/Chrome.cpp
@@ -307,6 +307,16 @@ bool Chrome::shouldInterruptJavaScript()
     return m_client->shouldInterruptJavaScript();
 }
 
+void Chrome::registerProtocolHandler(const String& scheme, const String& baseURL, const String& url, const String& title)
+{
+    m_client->registerProtocolHandler(scheme, baseURL, url, title);
+}
+
+void Chrome::registerContentHandler(const String& mimeType, const String& baseURL, const String& url, const String& title)
+{
+    m_client->registerContentHandler(mimeType,  baseURL, url,  title);
+}
+
 IntRect Chrome::windowResizerRect() const
 {
     return m_client->windowResizerRect();
diff --git a/WebCore/page/Chrome.h b/WebCore/page/Chrome.h
index 658b83f..542526b 100644
--- a/WebCore/page/Chrome.h
+++ b/WebCore/page/Chrome.h
@@ -117,6 +117,9 @@ namespace WebCore {
         void setStatusbarText(Frame*, const String&);
         bool shouldInterruptJavaScript();
 
+        void registerProtocolHandler(const String& scheme, const String& baseURL, const String& url, const String& title);
+        void registerContentHandler(const String& mimeType, const String& baseURL, const String& url, const String& title);
+
         IntRect windowResizerRect() const;
 
         void mouseDidMoveOverElement(const HitTestResult&, unsigned modifierFlags);
diff --git a/WebCore/page/ChromeClient.h b/WebCore/page/ChromeClient.h
index fcf5156..1052ea6 100644
--- a/WebCore/page/ChromeClient.h
+++ b/WebCore/page/ChromeClient.h
@@ -123,6 +123,9 @@ namespace WebCore {
         virtual bool shouldInterruptJavaScript() = 0;
         virtual bool tabsToLinks() const = 0;
 
+        virtual void registerProtocolHandler(const String&, const String&, const String&, const String&) { }
+        virtual void registerContentHandler(const String&, const String&, const String&, const String&) { }
+
         virtual IntRect windowResizerRect() const = 0;
 
         // Methods used by HostWindow.
diff --git a/WebCore/page/Navigator.cpp b/WebCore/page/Navigator.cpp
index 4922860..d672cef 100644
--- a/WebCore/page/Navigator.cpp
+++ b/WebCore/page/Navigator.cpp
@@ -24,10 +24,12 @@
 #include "Navigator.h"
 
 #include "CookieJar.h"
+#include "ExceptionCode.h"
 #include "Frame.h"
 #include "FrameLoader.h"
 #include "FrameLoaderClient.h"
 #include "Geolocation.h"
+#include "Kurl.h"
 #include "Language.h"
 #include "MimeTypeArray.h"
 #include "Page.h"
@@ -169,4 +171,93 @@ void Navigator::getStorageUpdates()
 }
 #endif
 
+static bool verifyCustomHandlerURL(const String& baseURL, const String& url, ExceptionCode& ec)
+{
+    // The specification requires that it is a SYNTAX_ERR if the the "%s" token is not present.
+    static const char token[] = "%s";
+    int index = url.find(token);
+    if (-1 == index) {
+        ec = SYNTAX_ERR;
+        return false;
+    }
+
+    // It is also a SYNTAX_ERR if the custom handler URL, as created by removing
+    // the "%s" token and prepending the base url, does not resolve.
+    String newURL = url;
+    newURL.remove(index, sizeof(token) / sizeof(token[0]));
+
+    KURL base(ParsedURLString, baseURL);
+    KURL kurl(base, newURL);
+
+    if (kurl.isEmpty() || !kurl.isValid()) {
+        ec = SYNTAX_ERR;
+        return false;
+    }
+
+    return true;
+}
+
+static bool verifyProtocolHandlerScheme(const String& scheme, ExceptionCode& ec)
+{
+    // It is a SECURITY_ERR for these schemes to be handled by a custom handler.
+    if (equalIgnoringCase(scheme, "http") || equalIgnoringCase(scheme, "https") || equalIgnoringCase(scheme, "file")) {
+        ec = SECURITY_ERR;
+        return false;
+    }
+    return true;
+}
+
+void Navigator::registerProtocolHandler(const String& scheme, const String& url, const String& title, ExceptionCode& ec)
+{
+    if (!verifyProtocolHandlerScheme(scheme, ec))
+        return;
+
+    if (!m_frame)
+        return;
+
+    Document* document = m_frame->document();
+    if (!document)
+        return;
+
+    String baseURL = document->baseURL().baseAsString();
+
+    if (!verifyCustomHandlerURL(baseURL, url, ec))
+        return;
+
+    if (Page* page = m_frame->page())
+        page->chrome()->registerProtocolHandler(scheme, baseURL, url, m_frame->displayStringModifiedByEncoding(title));
+}
+
+static bool verifyProtocolHandlerMimeType(const String& type, ExceptionCode& ec)
+{
+    // It is a SECURITY_ERR for these mime types to be assigned to a custom
+    // handler.
+    if (equalIgnoringCase(type, "text/html") || equalIgnoringCase(type, "text/css") || equalIgnoringCase(type, "application/x-javascript")) {
+        ec = SECURITY_ERR;
+        return false;
+    }
+    return true;
+}
+
+void Navigator::registerContentHandler(const String& mimeType, const String& url, const String& title, ExceptionCode& ec)
+{
+    if (!verifyProtocolHandlerMimeType(mimeType, ec))
+        return;
+
+    if (!m_frame)
+        return;
+
+    Document* document = m_frame->document();
+    if (!document)
+        return;
+
+    String baseURL = document->baseURL().baseAsString();
+
+    if (!verifyCustomHandlerURL(baseURL, url, ec))
+        return;
+
+    if (Page* page = m_frame->page())
+        page->chrome()->registerContentHandler(mimeType, baseURL, url, m_frame->displayStringModifiedByEncoding(title));
+}
+
 } // namespace WebCore
diff --git a/WebCore/page/Navigator.h b/WebCore/page/Navigator.h
index 4adebe1..107082b 100644
--- a/WebCore/page/Navigator.h
+++ b/WebCore/page/Navigator.h
@@ -34,6 +34,8 @@ namespace WebCore {
     class PluginArray;
     class String;
 
+    typedef int ExceptionCode;
+
     class Navigator : public NavigatorBase, public RefCounted<Navigator> {
     public:
         static PassRefPtr<Navigator> create(Frame* frame) { return adoptRef(new Navigator(frame)); }
@@ -60,6 +62,9 @@ namespace WebCore {
         void getStorageUpdates();
 #endif
 
+        void registerProtocolHandler(const String& scheme, const String& url, const String& title, ExceptionCode& ec);
+        void registerContentHandler(const String& mimeType, const String& url, const String& title, ExceptionCode& ec);
+
     private:
         Navigator(Frame*);
         Frame* m_frame;
diff --git a/WebCore/page/Navigator.idl b/WebCore/page/Navigator.idl
index 80ef4fb..99b22af 100644
--- a/WebCore/page/Navigator.idl
+++ b/WebCore/page/Navigator.idl
@@ -46,6 +46,11 @@ module window {
 #if defined(ENABLE_DOM_STORAGE) && ENABLE_DOM_STORAGE
         void getStorageUpdates();
 #endif
+
+        void registerProtocolHandler(in DOMString scheme, in DOMString url, in DOMString title)
+            raises(DomException);
+        void registerContentHandler(in DOMString mimeType, in DOMString url, in DOMString title)
+            raises(DomException);
     };
 
 }

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list