Separate the implementation of registerProtocolHandler from Navigator.cpp
authorabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Feb 2012 07:28:04 +0000 (07:28 +0000)
committerabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Feb 2012 07:28:04 +0000 (07:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=78945

Reviewed by Eric Seidel.

The implementation of registerProtocolHandler needlessly complicates
the implementation of Navigator.cpp.  In principle,
registerProtocolHandler (and possibly registerContentHandler, when we
implement that feature) could be its own module, but that seems like
overkill for one or two files.

* CMakeLists.txt:
* GNUmakefile.list.am:
* Target.pri:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* page/Navigator.cpp:
(WebCore):
* page/Navigator.h:
(Navigator):
* page/Navigator.idl:

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

13 files changed:
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/Target.pri
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.vcproj/WebCore.vcproj
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/page/Navigator.cpp
Source/WebCore/page/Navigator.h
Source/WebCore/page/Navigator.idl
Source/WebCore/page/NavigatorRegisterProtocolHandler.cpp [new file with mode: 0644]
Source/WebCore/page/NavigatorRegisterProtocolHandler.h [new file with mode: 0644]
Source/WebCore/page/NavigatorRegisterProtocolHandler.idl [new file with mode: 0644]

index 1ce5e0b..bbdecfb 100644 (file)
@@ -1030,6 +1030,7 @@ SET(WebCore_SOURCES
     page/MouseEventWithHitTestResults.cpp
     page/Navigator.cpp
     page/NavigatorBase.cpp
+    page/NavigatorRegisterProtocolHandler.cpp
     page/NavigatorSupplement.cpp
     page/OriginAccessEntry.cpp
     page/Page.cpp
index 0e20fc0..d469cc5 100644 (file)
@@ -1,3 +1,28 @@
+2012-02-21  Adam Barth  <abarth@webkit.org>
+
+        Separate the implementation of registerProtocolHandler from Navigator.cpp
+        https://bugs.webkit.org/show_bug.cgi?id=78945
+
+        Reviewed by Eric Seidel.
+
+        The implementation of registerProtocolHandler needlessly complicates
+        the implementation of Navigator.cpp.  In principle,
+        registerProtocolHandler (and possibly registerContentHandler, when we
+        implement that feature) could be its own module, but that seems like
+        overkill for one or two files.
+
+        * CMakeLists.txt:
+        * GNUmakefile.list.am:
+        * Target.pri:
+        * WebCore.gypi:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * page/Navigator.cpp:
+        (WebCore):
+        * page/Navigator.h:
+        (Navigator):
+        * page/Navigator.idl:
+
 2012-02-21  MORITA Hajime  <morrita@google.com>
 
         HasIDFlag and HasClassFlag can be removed.
index 72852b1..bde8ab4 100644 (file)
@@ -2740,6 +2740,8 @@ webcore_sources += \
        Source/WebCore/page/Navigator.h \
        Source/WebCore/page/NavigatorBase.cpp \
        Source/WebCore/page/NavigatorBase.h \
+       Source/WebCore/page/NavigatorRegisterProtocolHandler.cpp \
+       Source/WebCore/page/NavigatorRegisterProtocolHandler.h \
        Source/WebCore/page/NavigatorSupplement.cpp \
        Source/WebCore/page/NavigatorSupplement.h \
        Source/WebCore/page/OriginAccessEntry.cpp \
index c83d082..3175900 100644 (file)
@@ -1001,6 +1001,7 @@ SOURCES += \
     page/MouseEventWithHitTestResults.cpp \
     page/Navigator.cpp \
     page/NavigatorBase.cpp \
+    page/NavigatorRegisterProtocolHandler.cpp \
     page/NavigatorSupplement.cpp \
     page/OriginAccessEntry.cpp \
     page/Page.cpp \
index f3997f8..f850fa8 100644 (file)
             'page/Location.idl',
             'page/MemoryInfo.idl',
             'page/Navigator.idl',
+            'page/NavigatorRegisterProtocolHandler.idl',
             'page/Performance.idl',
             'page/PerformanceNavigation.idl',
             'page/PerformanceTiming.idl',
             'page/Navigator.h',
             'page/NavigatorBase.cpp',
             'page/NavigatorBase.h',
+            'page/NavigatorRegisterProtocolHandler.cpp',
+            'page/NavigatorRegisterProtocolHandler.h',
             'page/NavigatorSupplement.cpp',
             'page/NavigatorSupplement.h',
             'page/OriginAccessEntry.cpp',
index 76efcea..827d11e 100755 (executable)
                                >
                        </File>
                        <File
+                               RelativePath="..\page\NavigatorRegisterProtocolHandler.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\page\NavigatorRegisterProtocolHandler.h"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\page\NavigatorSupplement.cpp"
                                >
                        </File>
index f48c2a6..858d255 100644 (file)
                97DCE20210807C750057D394 /* HistoryController.h in Headers */ = {isa = PBXBuildFile; fileRef = 97DCE20010807C750057D394 /* HistoryController.h */; settings = {ATTRIBUTES = (Private, ); }; };
                97E4028F13A696ED00913D67 /* IconController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 97E4028D13A696ED00913D67 /* IconController.cpp */; };
                97E4029013A696ED00913D67 /* IconController.h in Headers */ = {isa = PBXBuildFile; fileRef = 97E4028E13A696ED00913D67 /* IconController.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               97E4A12614F4C5D400870E43 /* NavigatorRegisterProtocolHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 9730BE1514EF286B00DF06B9 /* NavigatorRegisterProtocolHandler.h */; };
+               97E4A12714F4C5D700870E43 /* NavigatorRegisterProtocolHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9730BE1414EF286B00DF06B9 /* NavigatorRegisterProtocolHandler.cpp */; };
                97EF7DFE107E55B700D7C49C /* ScriptControllerBase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 97EF7DFD107E55B700D7C49C /* ScriptControllerBase.cpp */; };
                984264F112D5280A000D88A4 /* LinkLoaderClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 984264EF12D5280A000D88A4 /* LinkLoaderClient.h */; };
                985BB96D13A94058007A0B69 /* LinkRelAttribute.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 985BB96B13A94058007A0B69 /* LinkRelAttribute.cpp */; };
                97205ABA1239292700B17380 /* PluginDocument.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PluginDocument.h; sourceTree = "<group>"; };
                9728C3111268E4390041E89B /* MarkupAccumulator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MarkupAccumulator.cpp; sourceTree = "<group>"; };
                9728C3121268E4390041E89B /* MarkupAccumulator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MarkupAccumulator.h; sourceTree = "<group>"; };
+               9730BE1414EF286B00DF06B9 /* NavigatorRegisterProtocolHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NavigatorRegisterProtocolHandler.cpp; sourceTree = "<group>"; };
+               9730BE1514EF286B00DF06B9 /* NavigatorRegisterProtocolHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NavigatorRegisterProtocolHandler.h; sourceTree = "<group>"; };
+               9730BE1614EF286B00DF06B9 /* NavigatorRegisterProtocolHandler.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = NavigatorRegisterProtocolHandler.idl; sourceTree = "<group>"; };
                9738899E116EA9DC00ADF313 /* DocumentWriter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DocumentWriter.cpp; sourceTree = "<group>"; };
                9738899F116EA9DC00ADF313 /* DocumentWriter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DocumentWriter.h; sourceTree = "<group>"; };
                973DC63D145A9409002842C2 /* ExceptionCodeDescription.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ExceptionCodeDescription.cpp; sourceTree = "<group>"; };
                                A9C6E65D0D746694006442E9 /* Navigator.idl */,
                                E12719C90EEEC21300F61213 /* NavigatorBase.cpp */,
                                E12719C60EEEC16800F61213 /* NavigatorBase.h */,
+                               9730BE1414EF286B00DF06B9 /* NavigatorRegisterProtocolHandler.cpp */,
+                               9730BE1514EF286B00DF06B9 /* NavigatorRegisterProtocolHandler.h */,
+                               9730BE1614EF286B00DF06B9 /* NavigatorRegisterProtocolHandler.idl */,
                                97CC3AE014E8E4A200894988 /* NavigatorSupplement.cpp */,
                                97CC3AE114E8E4A200894988 /* NavigatorSupplement.h */,
                                00146288103CD1DE000B20DB /* OriginAccessEntry.cpp */,
                BC1A3790097C6F970019F3D8 /* bindings */ = {
                        isa = PBXGroup;
                        children = (
-                               A83B533814F399BB00720D9D /* IDLAttributes.txt */,
                                B5D31DF711CF60E5009F22B4 /* generic */,
                                BC1A3793097C6FB10019F3D8 /* js */,
                                BC1A3794097C6FC40019F3D8 /* objc */,
                                93F8B3050A300FE100F61AB8 /* CodeGenerator.pm */,
                                93F8B3070A300FEA00F61AB8 /* generate-bindings.pl */,
+                               A83B533814F399BB00720D9D /* IDLAttributes.txt */,
                                14813BF309EDF88E00F757E1 /* IDLParser.pm */,
                                93F8B3080A300FEA00F61AB8 /* IDLStructure.pm */,
                                C0F2A43F13869A280066C534 /* preprocessor.pm */,
                                656D373A0ADBA5DE00A4554D /* FormState.h in Headers */,
                                41885B9311B6FDA6003383BB /* FormSubmission.h in Headers */,
                                935C476D09AC4D6300A6AAB4 /* FoundationExtras.h in Headers */,
+                               144FCFE114EF2509000D17A3 /* FractionalLayoutRect.h in Headers */,
                                144FCE5D14EC79E7000D17A3 /* FractionalLayoutSize.h in Headers */,
                                144FCE5214EC79BC000D17A3 /* FractionalLayoutUnit.h in Headers */,
                                A853123D11D0471B00D4D077 /* FragmentScriptingPermission.h in Headers */,
                                A9C6E5A60D746458006442E9 /* Navigator.h in Headers */,
                                E12719C70EEEC16800F61213 /* NavigatorBase.h in Headers */,
                                9711460414EF009A00674FD9 /* NavigatorGeolocation.h in Headers */,
+                               97E4A12614F4C5D400870E43 /* NavigatorRegisterProtocolHandler.h in Headers */,
                                97CC3AE314E8E4A200894988 /* NavigatorSupplement.h in Headers */,
                                8A309C9F123950BE00CB9204 /* NestingLevelIncrementer.h in Headers */,
                                656D37430ADBA5DE00A4554D /* NetscapePlugInStreamLoader.h in Headers */,
                                E44613EC0CD681B500FADA75 /* ProgressEvent.h in Headers */,
                                A715E653134BBBEC00D8E713 /* ProgressShadowElement.h in Headers */,
                                1A2A68240B5BEDE70002A480 /* ProgressTracker.h in Headers */,
+                               E4BBED0F14F4025D003F0B98 /* PropertySetCSSStyleDeclaration.h in Headers */,
                                514C76750CE923A1007EF3CD /* ProtectionSpace.h in Headers */,
                                51A052561058874000CC9E95 /* ProtectionSpaceHash.h in Headers */,
                                1AF8E11A1256592600230FF7 /* ProxyServer.h in Headers */,
                                E1BE512E0CF6C512002EA959 /* XSLTUnicodeSort.h in Headers */,
                                977E2E0F12F0FC9C00C13379 /* XSSAuditor.h in Headers */,
                                FD537353137B651800008DCE /* ZeroPole.h in Headers */,
-                               E4BBED0F14F4025D003F0B98 /* PropertySetCSSStyleDeclaration.h in Headers */,
-                               144FCFE114EF2509000D17A3 /* FractionalLayoutRect.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                514C764F0CE9234E007EF3CD /* FormDataStreamMac.mm in Sources */,
                                656D373B0ADBA5DE00A4554D /* FormState.cpp in Sources */,
                                41885B9411B6FDA6003383BB /* FormSubmission.cpp in Sources */,
+                               144FCFE014EF2509000D17A3 /* FractionalLayoutRect.cpp in Sources */,
                                144FCE5C14EC79E7000D17A3 /* FractionalLayoutSize.cpp in Sources */,
                                65BF022E0974816300C43196 /* Frame.cpp in Sources */,
                                A7B070D2130A409C00A3763C /* FrameActionScheduler.cpp in Sources */,
                                A9C6E5A50D746458006442E9 /* Navigator.cpp in Sources */,
                                E12719CA0EEEC21300F61213 /* NavigatorBase.cpp in Sources */,
                                9711460314EF009A00674FD9 /* NavigatorGeolocation.cpp in Sources */,
+                               97E4A12714F4C5D700870E43 /* NavigatorRegisterProtocolHandler.cpp in Sources */,
                                97CC3AE214E8E4A200894988 /* NavigatorSupplement.cpp in Sources */,
                                5D874F130D161D3200796C3B /* NetscapePlugInStreamLoader.cpp in Sources */,
                                59C27F05138D28C10079B7E2 /* NetworkResourcesData.cpp in Sources */,
                                E44613EB0CD681B400FADA75 /* ProgressEvent.cpp in Sources */,
                                A715E652134BBBEC00D8E713 /* ProgressShadowElement.cpp in Sources */,
                                1A2A68230B5BEDE70002A480 /* ProgressTracker.cpp in Sources */,
+                               E4BBED0E14F4025D003F0B98 /* PropertySetCSSStyleDeclaration.cpp in Sources */,
                                514C76740CE923A1007EF3CD /* ProtectionSpace.cpp in Sources */,
                                1AF8E13312565A4400230FF7 /* ProxyServer.cpp in Sources */,
                                1AF8E1C3125673E000230FF7 /* ProxyServerCFNet.cpp in Sources */,
                                1CAF34820A6C405200ABE06E /* WebScriptObject.mm in Sources */,
                                518A34C11026C831001B6896 /* WebSocket.cpp in Sources */,
                                510D4A4E103177A20049EA54 /* WebSocketChannel.cpp in Sources */,
-                               4A957F0614E2412A0049DBFB /* WebSocketExtensionDispatcher.cpp in Sources */,
                                4AE02ABD14E8A9D200BC3BA7 /* WebSocketDeflater.cpp in Sources */,
+                               4A957F0614E2412A0049DBFB /* WebSocketExtensionDispatcher.cpp in Sources */,
                                51ABAE441043AB4A008C5260 /* WebSocketHandshake.cpp in Sources */,
                                7637C541112E7B74003D6CDC /* WebSocketHandshakeRequest.cpp in Sources */,
                                767F99BE11A1194A0080C51D /* WebSocketHandshakeResponse.cpp in Sources */,
                                E1BE512D0CF6C512002EA959 /* XSLTUnicodeSort.cpp in Sources */,
                                977E2E0E12F0FC9C00C13379 /* XSSAuditor.cpp in Sources */,
                                FD537352137B651800008DCE /* ZeroPole.cpp in Sources */,
-                               E4BBED0E14F4025D003F0B98 /* PropertySetCSSStyleDeclaration.cpp in Sources */,
-                               144FCFE014EF2509000D17A3 /* FractionalLayoutRect.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index d06e888..76328a7 100644 (file)
 #include "config.h"
 #include "Navigator.h"
 
-#include "Chrome.h"
 #include "CookieJar.h"
 #include "DOMMimeTypeArray.h"
 #include "DOMPluginArray.h"
 #include "Document.h"
-#include "ExceptionCode.h"
 #include "Frame.h"
 #include "FrameLoader.h"
 #include "FrameLoaderClient.h"
 #include "Geolocation.h"
+#include "Page.h"
 #include "PointerLock.h"
-#include "KURL.h"
 #include "Language.h"
-#include "Page.h"
-#include "PageGroup.h"
-#include "PlatformString.h"
 #include "PluginData.h"
 #include "Settings.h"
 #include "StorageNamespace.h"
@@ -159,100 +154,4 @@ void Navigator::getStorageUpdates()
     // FIXME: Remove this method or rename to yieldForStorageUpdates.
 }
 
-#if ENABLE(REGISTER_PROTOCOL_HANDLER)
-static HashSet<String>* protocolWhitelist;
-
-static void initProtocolHandlerWhitelist()
-{
-    protocolWhitelist = new HashSet<String>;
-    static const char* protocols[] = {
-        "irc",
-        "mailto",
-        "mms",
-        "news",
-        "nntp",
-        "sms",
-        "smsto",
-        "tel",
-        "urn",
-        "webcal",
-    };
-    for (size_t i = 0; i < WTF_ARRAY_LENGTH(protocols); ++i)
-        protocolWhitelist->add(protocols[i]);
-}
-
-static bool verifyCustomHandlerURL(const String& baseURL, const String& url, ExceptionCode& ec)
-{
-    // The specification requires that it is a SYNTAX_ERR if 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, WTF_ARRAY_LENGTH(token) - 1);
-
-    KURL base(ParsedURLString, baseURL);
-    KURL kurl(base, newURL);
-
-    if (kurl.isEmpty() || !kurl.isValid()) {
-        ec = SYNTAX_ERR;
-        return false;
-    }
-
-    return true;
-}
-
-static bool isProtocolWhitelisted(const String& scheme)
-{
-    if (!protocolWhitelist)
-        initProtocolHandlerWhitelist();
-    return protocolWhitelist->contains(scheme);
-}
-
-static bool verifyProtocolHandlerScheme(const String& scheme, ExceptionCode& ec)
-{
-    if (scheme.startsWith("web+")) {
-        if (isValidProtocol(scheme))
-            return true;
-        ec = SECURITY_ERR;
-        return false;
-    }
-
-    if (isProtocolWhitelisted(scheme))
-        return true;
-    ec = SECURITY_ERR;
-    return false;
-}
-
-void Navigator::registerProtocolHandler(const String& scheme, const String& url, const String& title, ExceptionCode& ec)
-{
-    if (!m_frame)
-        return;
-
-    Document* document = m_frame->document();
-    if (!document)
-        return;
-
-    String baseURL = document->baseURL().baseAsString();
-
-    if (!verifyCustomHandlerURL(baseURL, url, ec))
-        return;
-
-    if (!verifyProtocolHandlerScheme(scheme, ec))
-        return;
-
-    Page* page = m_frame->page();
-    if (!page)
-        return;
-
-    page->chrome()->registerProtocolHandler(scheme, baseURL, url, m_frame->displayStringModifiedByEncoding(title));
-}
-#endif
-
 } // namespace WebCore
index dd5c574..750eeaa 100644 (file)
@@ -60,10 +60,6 @@ public:
     // Relinquishes the storage lock, if one exists.
     void getStorageUpdates();
 
-#if ENABLE(REGISTER_PROTOCOL_HANDLER)
-    void registerProtocolHandler(const String& scheme, const String& url, const String& title, ExceptionCode&);
-#endif
-
     void provideSupplement(const AtomicString&, PassOwnPtr<NavigatorSupplement>);
     NavigatorSupplement* requireSupplement(const AtomicString&);
 
index 59cc7e7..400d8e0 100644 (file)
@@ -45,11 +45,6 @@ module window {
 #endif
 
         void getStorageUpdates(); // FIXME: Remove this method or rename to yieldForStorageUpdates.
-
-#if defined(ENABLE_REGISTER_PROTOCOL_HANDLER) && ENABLE_REGISTER_PROTOCOL_HANDLER
-        void registerProtocolHandler(in DOMString scheme, in DOMString url, in DOMString title)
-            raises(DOMException);
-#endif
     };
 
 }
diff --git a/Source/WebCore/page/NavigatorRegisterProtocolHandler.cpp b/Source/WebCore/page/NavigatorRegisterProtocolHandler.cpp
new file mode 100644 (file)
index 0000000..a773b57
--- /dev/null
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2011, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ */
+
+#include "config.h"
+#include "NavigatorRegisterProtocolHandler.h"
+
+#if ENABLE(REGISTER_PROTOCOL_HANDLER)
+
+#include "Chrome.h"
+#include "Document.h"
+#include "ExceptionCode.h"
+#include "Frame.h"
+#include "Navigator.h"
+#include "Page.h"
+#include <wtf/HashSet.h>
+
+namespace WebCore {
+
+static HashSet<String>* protocolWhitelist;
+
+static void initProtocolHandlerWhitelist()
+{
+    protocolWhitelist = new HashSet<String>;
+    static const char* protocols[] = {
+        "irc",
+        "mailto",
+        "mms",
+        "news",
+        "nntp",
+        "sms",
+        "smsto",
+        "tel",
+        "urn",
+        "webcal",
+    };
+    for (size_t i = 0; i < WTF_ARRAY_LENGTH(protocols); ++i)
+        protocolWhitelist->add(protocols[i]);
+}
+
+static bool verifyCustomHandlerURL(const String& baseURL, const String& url, ExceptionCode& ec)
+{
+    // The specification requires that it is a SYNTAX_ERR if 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, WTF_ARRAY_LENGTH(token) - 1);
+
+    KURL base(ParsedURLString, baseURL);
+    KURL kurl(base, newURL);
+
+    if (kurl.isEmpty() || !kurl.isValid()) {
+        ec = SYNTAX_ERR;
+        return false;
+    }
+
+    return true;
+}
+
+static bool isProtocolWhitelisted(const String& scheme)
+{
+    if (!protocolWhitelist)
+        initProtocolHandlerWhitelist();
+    return protocolWhitelist->contains(scheme);
+}
+
+static bool verifyProtocolHandlerScheme(const String& scheme, ExceptionCode& ec)
+{
+    if (scheme.startsWith("web+")) {
+        if (isValidProtocol(scheme))
+            return true;
+        ec = SECURITY_ERR;
+        return false;
+    }
+
+    if (isProtocolWhitelisted(scheme))
+        return true;
+    ec = SECURITY_ERR;
+    return false;
+}
+
+NavigatorRegisterProtocolHandler::NavigatorRegisterProtocolHandler()
+{
+}
+
+NavigatorRegisterProtocolHandler::~NavigatorRegisterProtocolHandler()
+{
+}
+
+void NavigatorRegisterProtocolHandler::registerProtocolHandler(Navigator* navigator, const String& scheme, const String& url, const String& title, ExceptionCode& ec)
+{
+    if (!navigator->frame())
+        return;
+
+    Document* document = navigator->frame()->document();
+    if (!document)
+        return;
+
+    String baseURL = document->baseURL().baseAsString();
+
+    if (!verifyCustomHandlerURL(baseURL, url, ec))
+        return;
+
+    if (!verifyProtocolHandlerScheme(scheme, ec))
+        return;
+
+    Page* page = navigator->frame()->page();
+    if (!page)
+        return;
+
+    page->chrome()->registerProtocolHandler(scheme, baseURL, url, navigator->frame()->displayStringModifiedByEncoding(title));
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(WEB_INTENTS)
diff --git a/Source/WebCore/page/NavigatorRegisterProtocolHandler.h b/Source/WebCore/page/NavigatorRegisterProtocolHandler.h
new file mode 100644 (file)
index 0000000..15e25ec
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2011, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ */
+
+#ifndef NavigatorRegisterProtocolHandler_h
+#define NavigatorRegisterProtocolHandler_h
+
+#if ENABLE(REGISTER_PROTOCOL_HANDLER)
+
+#include <wtf/PassRefPtr.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class Navigator;
+
+typedef int ExceptionCode;
+
+class NavigatorRegisterProtocolHandler {
+public:
+    static void registerProtocolHandler(Navigator*, const String& scheme, const String& url, const String& title, ExceptionCode&);
+
+private:
+    NavigatorRegisterProtocolHandler();
+    ~NavigatorRegisterProtocolHandler();
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(REGISTER_PROTOCOL_HANDLER)
+
+#endif // NavigatorRegisterProtocolHandler_h
diff --git a/Source/WebCore/page/NavigatorRegisterProtocolHandler.idl b/Source/WebCore/page/NavigatorRegisterProtocolHandler.idl
new file mode 100644 (file)
index 0000000..174d063
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+    Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    along with this library; see the file COPYING.LIB.  If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+*/
+
+module window {
+
+    interface [
+        Conditional=REGISTER_PROTOCOL_HANDLER,
+        Supplemental=Navigator
+    ] NavigatorRegisterProtocolHandler {
+        void registerProtocolHandler(in DOMString scheme, in DOMString url, in DOMString title)
+            raises(DOMException);
+    };
+
+}