Changeset 50477 in webkit


Ignore:
Timestamp:
Nov 3, 2009 1:12:24 PM (14 years ago)
Author:
dimich@chromium.org
Message:

WebCore: Implement window.navigator.registerProtocolHandler in webkit,
https://bugs.webkit.org/b/29651

Patch by Bradley Green <brg@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@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:
Location:
trunk
Files:
4 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r50470 r50477  
     12009-11-03  Bradley Green  <brg@chromium.org>
     2
     3        Reviewed by Dmitry Titov.
     4
     5        Updating test expectations for implementation of
     6        window.navigator.registerProtocolHandler and
     7        window.navigator.registerContentHandler.
     8
     9        There is a default implimentation for these APIs, hence all platforms
     10        with the navigator-detached-no-crash-expect and
     11        window-properties-expected tests needed to be updated.  While
     12        isolatedWorlds has a window-properties-expected test, it has no window
     13        object and hence does not need to be updaetd.
     14
     15        We add two fast/dom tests to insure that the proper exceptions are
     16        thrown when bad syntax or security violations are made by calling the
     17        methods.
     18
     19        * fast/dom/Window/window-properties-expected.txt:
     20        * fast/dom/navigator-detached-no-crash-expected.txt:
     21        * fast/dom/navigator-detached-no-crash.html:
     22        * fast/dom/registerContentHandler-expected.txt: Added.
     23        * fast/dom/registerContentHandler.html: Added.
     24        * fast/dom/registerProtocolHandler-expected.txt: Added.
     25        * fast/dom/registerProtocolHandler.html: Added.
     26        * platform/gtk/fast/dom/Window/window-properties-expected.txt:
     27        * platform/gtk/fast/dom/navigator-detached-no-crash-expected.txt:
     28        * platform/mac-leopard/fast/dom/navigator-detached-no-crash-expected.txt:
     29
    1302009-11-03  Dan Bernstein  <mitz@apple.com>
    231
  • trunk/LayoutTests/fast/dom/Window/window-properties-expected.txt

    r49998 r50477  
    16891689window.clientInformation.product [string]
    16901690window.clientInformation.productSub [string]
     1691window.clientInformation.registerContentHandler [function]
     1692window.clientInformation.registerProtocolHandler [function]
    16911693window.clientInformation.userAgent [string]
    16921694window.clientInformation.vendor [string]
  • trunk/LayoutTests/fast/dom/navigator-detached-no-crash-expected.txt

    r47397 r50477  
    1414navigator.product is OK
    1515navigator.productSub is OK
     16navigator.registerContentHandler() threw err Error: SYNTAX_ERR: DOM Exception 12
     17navigator.registerProtocolHandler() threw err Error: SYNTAX_ERR: DOM Exception 12
    1618navigator.userAgent is OK
    1719navigator.vendor is OK
     
    3032navigator.product is OK
    3133navigator.productSub is OK
     34navigator.registerContentHandler() is OK
     35navigator.registerProtocolHandler() is OK
    3236navigator.userAgent is OK
    3337navigator.vendor is OK
  • trunk/LayoutTests/fast/dom/navigator-detached-no-crash.html

    r41087 r50477  
    5454  for (p in old_nav) {
    5555    if (typeof old_nav[p] == 'function') {
    56       var v = old_nav[p]();
    57       // no crash, it is ok
    58       strings.push("navigator."+p+"() is OK");
     56      try {
     57        var v = old_nav[p]();
     58        // no crash, it is ok
     59        strings.push("navigator."+p+"() is OK");
     60      } catch(err) {
     61        // navigator.registerXXX will throw on invalid input.
     62        strings.push("navigator."+p+"() threw err "+err);
     63      }
    5964    } else {
    6065      var v = old_nav[p];
  • trunk/LayoutTests/platform/gtk/fast/dom/Window/window-properties-expected.txt

    r48362 r50477  
    16581658window.clientInformation.product [string]
    16591659window.clientInformation.productSub [string]
     1660window.clientInformation.registerContentHandler [function]
     1661window.clientInformation.registerProtocolHandler [function]
    16601662window.clientInformation.userAgent [string]
    16611663window.clientInformation.vendor [string]
  • trunk/LayoutTests/platform/gtk/fast/dom/navigator-detached-no-crash-expected.txt

    r47864 r50477  
    1515navigator.product is OK
    1616navigator.productSub is OK
     17navigator.registerContentHandler() threw err Error: SYNTAX_ERR: DOM Exception 12
     18navigator.registerProtocolHandler() threw err Error: SYNTAX_ERR: DOM Exception 12
    1719navigator.userAgent is OK
    1820navigator.vendor is OK
     
    3234navigator.product is OK
    3335navigator.productSub is OK
     36navigator.registerContentHandler() is OK
     37navigator.registerProtocolHandler() is OK
    3438navigator.userAgent is OK
    3539navigator.vendor is OK
  • trunk/LayoutTests/platform/mac-leopard/fast/dom/navigator-detached-no-crash-expected.txt

    r47397 r50477  
    1414navigator.product is OK
    1515navigator.productSub is OK
     16navigator.registerContentHandler() threw err Error: SYNTAX_ERR: DOM Exception 12
     17navigator.registerProtocolHandler() threw err Error: SYNTAX_ERR: DOM Exception 12
    1618navigator.userAgent is OK
    1719navigator.vendor is OK
     
    3032navigator.product is OK
    3133navigator.productSub is OK
     34navigator.registerContentHandler() is OK
     35navigator.registerProtocolHandler() is OK
    3236navigator.userAgent is OK
    3337navigator.vendor is OK
  • trunk/WebCore/ChangeLog

    r50476 r50477  
     12009-11-03  Bradley Green  <brg@chromium.org>
     2
     3        Reviewed by Dmitry Titov.
     4
     5        Implement window.navigator.registerProtocolHandler in webkit,
     6        https://bugs.webkit.org/b/29651
     7
     8        Also implemented its sister API window.navigator.registerContentHandler.
     9
     10        These methods are as described in the HTML5 specification which can be
     11        found here,
     12        http://dev.w3.org/html5/spec/Overview.html#dom-navigator-registerprotocolhandler
     13        http://dev.w3.org/html5/spec/Overview.html#dom-navigator-registercontenthandler
     14
     15        As specified in the document, the behavior of the browser is determined
     16        by the current registered handler.  The state of a registered handler
     17        can change at any time, with the user clearing a registered handler,
     18        registering a different page as handler, or deferring the hander to the
     19        OS.  If webkit was to track the state of the currently registered
     20        handlers, it would need more APIs and complexity to keep in sync with
     21        user actions reported to webkit from the UA.  For simplicity, the state
     22        of protocol handlers should be kept isolated from webkit and webkit only
     23        notifies the UA that a page has made the call.  The UA is then
     24        responsible for correctly handling the registerProtocolHandler call and
     25        the redirects which result from registration.
     26
     27        We do however follow the specification in insuring that the reserved
     28        schemes and mimeTypes are not passed to the UA as custom handler
     29        registration tests.  We also insure that the "%s" token is present as
     30        required by the specification.
     31
     32        Updated test expectations for window.clientInformation and navigator
     33        objects.
     34
     35        Tests: fast/dom/registerContentHandler.html
     36               fast/dom/registerProtocolHandler.html
     37
     38        * page/Chrome.cpp:
     39        (WebCore::Chrome::registerProtocolHandler):
     40        (WebCore::Chrome::registerContentHandler):
     41        * page/Chrome.h:
     42        * page/ChromeClient.h:
     43        (WebCore::ChromeClient::registerProtocolHandler):
     44        (WebCore::ChromeClient::registerContentHandler):
     45        * page/Navigator.cpp:
     46        (WebCore::verifyCustomHandlerURL):
     47        (WebCore::verifyProtocolHandlerScheme):
     48        (WebCore::Navigator::registerProtocolHandler):
     49        (WebCore::verifyProtocolHandlerMimeType):
     50        (WebCore::Navigator::registerContentHandler):
     51        * page/Navigator.h:
     52        * page/Navigator.idl:
     53
    1542009-11-03  Brady Eidson  <beidson@apple.com>
    255
  • trunk/WebCore/page/Chrome.cpp

    r50351 r50477  
    308308}
    309309
     310void Chrome::registerProtocolHandler(const String& scheme, const String& baseURL, const String& url, const String& title)
     311{
     312    m_client->registerProtocolHandler(scheme, baseURL, url, title);
     313}
     314
     315void Chrome::registerContentHandler(const String& mimeType, const String& baseURL, const String& url, const String& title)
     316{
     317    m_client->registerContentHandler(mimeType,  baseURL, url,  title);
     318}
     319
    310320IntRect Chrome::windowResizerRect() const
    311321{
  • trunk/WebCore/page/Chrome.h

    r50351 r50477  
    118118        bool shouldInterruptJavaScript();
    119119
     120        void registerProtocolHandler(const String& scheme, const String& baseURL, const String& url, const String& title);
     121        void registerContentHandler(const String& mimeType, const String& baseURL, const String& url, const String& title);
     122
    120123        IntRect windowResizerRect() const;
    121124
  • trunk/WebCore/page/ChromeClient.h

    r50351 r50477  
    124124        virtual bool tabsToLinks() const = 0;
    125125
     126        virtual void registerProtocolHandler(const String&, const String&, const String&, const String&) { }
     127        virtual void registerContentHandler(const String&, const String&, const String&, const String&) { }
     128
    126129        virtual IntRect windowResizerRect() const = 0;
    127130
  • trunk/WebCore/page/Navigator.cpp

    r47397 r50477  
    2525
    2626#include "CookieJar.h"
     27#include "ExceptionCode.h"
    2728#include "Frame.h"
    2829#include "FrameLoader.h"
    2930#include "FrameLoaderClient.h"
    3031#include "Geolocation.h"
     32#include "Kurl.h"
    3133#include "Language.h"
    3234#include "MimeTypeArray.h"
     
    170172#endif
    171173
     174static bool verifyCustomHandlerURL(const String& baseURL, const String& url, ExceptionCode& ec)
     175{
     176    // The specification requires that it is a SYNTAX_ERR if the the "%s" token is not present.
     177    static const char token[] = "%s";
     178    int index = url.find(token);
     179    if (-1 == index) {
     180        ec = SYNTAX_ERR;
     181        return false;
     182    }
     183
     184    // It is also a SYNTAX_ERR if the custom handler URL, as created by removing
     185    // the "%s" token and prepending the base url, does not resolve.
     186    String newURL = url;
     187    newURL.remove(index, sizeof(token) / sizeof(token[0]));
     188
     189    KURL base(ParsedURLString, baseURL);
     190    KURL kurl(base, newURL);
     191
     192    if (kurl.isEmpty() || !kurl.isValid()) {
     193        ec = SYNTAX_ERR;
     194        return false;
     195    }
     196
     197    return true;
     198}
     199
     200static bool verifyProtocolHandlerScheme(const String& scheme, ExceptionCode& ec)
     201{
     202    // It is a SECURITY_ERR for these schemes to be handled by a custom handler.
     203    if (equalIgnoringCase(scheme, "http") || equalIgnoringCase(scheme, "https") || equalIgnoringCase(scheme, "file")) {
     204        ec = SECURITY_ERR;
     205        return false;
     206    }
     207    return true;
     208}
     209
     210void Navigator::registerProtocolHandler(const String& scheme, const String& url, const String& title, ExceptionCode& ec)
     211{
     212    if (!verifyProtocolHandlerScheme(scheme, ec))
     213        return;
     214
     215    if (!m_frame)
     216        return;
     217
     218    Document* document = m_frame->document();
     219    if (!document)
     220        return;
     221
     222    String baseURL = document->baseURL().baseAsString();
     223
     224    if (!verifyCustomHandlerURL(baseURL, url, ec))
     225        return;
     226
     227    if (Page* page = m_frame->page())
     228        page->chrome()->registerProtocolHandler(scheme, baseURL, url, m_frame->displayStringModifiedByEncoding(title));
     229}
     230
     231static bool verifyProtocolHandlerMimeType(const String& type, ExceptionCode& ec)
     232{
     233    // It is a SECURITY_ERR for these mime types to be assigned to a custom
     234    // handler.
     235    if (equalIgnoringCase(type, "text/html") || equalIgnoringCase(type, "text/css") || equalIgnoringCase(type, "application/x-javascript")) {
     236        ec = SECURITY_ERR;
     237        return false;
     238    }
     239    return true;
     240}
     241
     242void Navigator::registerContentHandler(const String& mimeType, const String& url, const String& title, ExceptionCode& ec)
     243{
     244    if (!verifyProtocolHandlerMimeType(mimeType, ec))
     245        return;
     246
     247    if (!m_frame)
     248        return;
     249
     250    Document* document = m_frame->document();
     251    if (!document)
     252        return;
     253
     254    String baseURL = document->baseURL().baseAsString();
     255
     256    if (!verifyCustomHandlerURL(baseURL, url, ec))
     257        return;
     258
     259    if (Page* page = m_frame->page())
     260        page->chrome()->registerContentHandler(mimeType, baseURL, url, m_frame->displayStringModifiedByEncoding(title));
     261}
     262
    172263} // namespace WebCore
  • trunk/WebCore/page/Navigator.h

    r47397 r50477  
    3535    class String;
    3636
     37    typedef int ExceptionCode;
     38
    3739    class Navigator : public NavigatorBase, public RefCounted<Navigator> {
    3840    public:
     
    6163#endif
    6264
     65        void registerProtocolHandler(const String& scheme, const String& url, const String& title, ExceptionCode& ec);
     66        void registerContentHandler(const String& mimeType, const String& url, const String& title, ExceptionCode& ec);
     67
    6368    private:
    6469        Navigator(Frame*);
  • trunk/WebCore/page/Navigator.idl

    r47397 r50477  
    4747        void getStorageUpdates();
    4848#endif
     49
     50        void registerProtocolHandler(in DOMString scheme, in DOMString url, in DOMString title)
     51            raises(DomException);
     52        void registerContentHandler(in DOMString mimeType, in DOMString url, in DOMString title)
     53            raises(DomException);
    4954    };
    5055
Note: See TracChangeset for help on using the changeset viewer.