Title: [117793] trunk
Revision
117793
Author
[email protected]
Date
2012-05-21 09:24:06 -0700 (Mon, 21 May 2012)

Log Message

Add suggestions field to web intents API.
https://bugs.webkit.org/show_bug.cgi?id=86791

Patch by Greg Billock <[email protected]> on 2012-05-21
Reviewed by Adam Barth.

Source/WebCore:

The |suggestions| field is used by the client to avoid an empty
web intents selection window (picker). The UA can add the given
suggestions to the picker if it would otherwise be empty. See
http://dvcs.w3.org/hg/web-intents/raw-file/tip/spec/Overview.html#intent-parameters-dictionary

* Modules/intents/DeliveredIntent.cpp:
(WebCore::DeliveredIntent::DeliveredIntent):
* Modules/intents/Intent.cpp:
(WebCore::Intent::create):
(WebCore::Intent::Intent):
* Modules/intents/Intent.h:
(WebCore::Intent::suggestions):
(Intent):

Source/WebKit/chromium:

* public/WebIntent.h:
(WebIntent):
* src/WebIntent.cpp:
(WebKit::WebIntent::suggestions):
(WebKit):

Modified Paths

Diff

Modified: trunk/LayoutTests/webintents/web-intents-obj-constructor-expected.txt (117792 => 117793)


--- trunk/LayoutTests/webintents/web-intents-obj-constructor-expected.txt	2012-05-21 16:19:58 UTC (rev 117792)
+++ trunk/LayoutTests/webintents/web-intents-obj-constructor-expected.txt	2012-05-21 16:24:06 UTC (rev 117793)
@@ -5,6 +5,8 @@
 Extras[a] = b
 Received Web Intent: action="" type=text/plain+port
 Have 1 ports
+Received Web Intent: action="" type=text/plain+suggestions
+Have suggestion http://www.example.com/
 PASS successfullyParsed is true
 
 TEST COMPLETE
@@ -43,4 +45,8 @@
 * sent explicit intent
 * sent intent with extras
 * sent intent with port
+PASS new WebKitIntent(badPortIntentObj) threw exception Error: DATA_CLONE_ERR: DOM Exception 25.
+PASS new WebKitIntent(suggestionsIntent) threw exception Error: SYNTAX_ERR: DOM Exception 12.
+PASS new WebKitIntent(suggestionsIntent) threw exception Error: SYNTAX_ERR: DOM Exception 12.
+* sent intent with suggestions
 

Modified: trunk/LayoutTests/webintents/web-intents-obj-constructor.html (117792 => 117793)


--- trunk/LayoutTests/webintents/web-intents-obj-constructor.html	2012-05-21 16:19:58 UTC (rev 117792)
+++ trunk/LayoutTests/webintents/web-intents-obj-constructor.html	2012-05-21 16:24:06 UTC (rev 117793)
@@ -92,6 +92,32 @@
              "transfer":[channel.port1]});
         navigator.webkitStartActivity(portIntent);
         debug("* sent intent with port");
+
+        // Ports, if present, must be put in |transfer|.
+        var badchannel = new MessageChannel();
+        badchannel.port2._onMessage_ = function() {
+            debug("* got message");
+        }
+        badPortIntentObj = 
+            {"action":"action1",
+             "type":"text/plain+badport",
+             "data":badchannel.port1};
+        shouldThrow("new WebKitIntent(badPortIntentObj)", "'Error: DATA_CLONE_ERR: DOM Exception 25'");
+
+        suggestionsIntent =
+            {"action":"action1",
+             "type":"text/plain+suggestions",
+             "data":"message",
+             "suggestions":["www.example.com/", "http://ww2.example.com"]};
+        shouldThrow("new WebKitIntent(suggestionsIntent)", "'Error: SYNTAX_ERR: DOM Exception 12'");
+
+        suggestionsIntent.suggestions = [15];
+        shouldThrow("new WebKitIntent(suggestionsIntent)", "'Error: SYNTAX_ERR: DOM Exception 12'");
+
+        suggestionsIntent.suggestions = ["http://www.example.com/"];
+        navigator.webkitStartActivity(new WebKitIntent(suggestionsIntent));
+        debug("* sent intent with suggestions");
+
     }
     </script>
   </head>

Modified: trunk/Source/WebCore/ChangeLog (117792 => 117793)


--- trunk/Source/WebCore/ChangeLog	2012-05-21 16:19:58 UTC (rev 117792)
+++ trunk/Source/WebCore/ChangeLog	2012-05-21 16:24:06 UTC (rev 117793)
@@ -1,3 +1,24 @@
+2012-05-21  Greg Billock  <[email protected]>
+
+        Add suggestions field to web intents API.
+        https://bugs.webkit.org/show_bug.cgi?id=86791
+
+        Reviewed by Adam Barth.
+
+        The |suggestions| field is used by the client to avoid an empty
+        web intents selection window (picker). The UA can add the given
+        suggestions to the picker if it would otherwise be empty. See
+        http://dvcs.w3.org/hg/web-intents/raw-file/tip/spec/Overview.html#intent-parameters-dictionary
+
+        * Modules/intents/DeliveredIntent.cpp:
+        (WebCore::DeliveredIntent::DeliveredIntent):
+        * Modules/intents/Intent.cpp:
+        (WebCore::Intent::create):
+        (WebCore::Intent::Intent):
+        * Modules/intents/Intent.h:
+        (WebCore::Intent::suggestions):
+        (Intent):
+
 2012-05-21  Stephen Chenney  <[email protected]>
 
         SVGAnimatedPropertyTearOff does not clear a self pointer on deletion

Modified: trunk/Source/WebCore/Modules/intents/DeliveredIntent.cpp (117792 => 117793)


--- trunk/Source/WebCore/Modules/intents/DeliveredIntent.cpp	2012-05-21 16:19:58 UTC (rev 117792)
+++ trunk/Source/WebCore/Modules/intents/DeliveredIntent.cpp	2012-05-21 16:24:06 UTC (rev 117793)
@@ -35,6 +35,7 @@
 #include "ExceptionCode.h"
 #include "Frame.h"
 #include "SerializedScriptValue.h"
+#include <wtf/Vector.h>
 
 namespace WebCore {
 
@@ -48,7 +49,7 @@
 DeliveredIntent::DeliveredIntent(Frame* frame, PassOwnPtr<DeliveredIntentClient> client, const String& action, const String& type,
                                  PassRefPtr<SerializedScriptValue> data, PassOwnPtr<MessagePortArray> ports,
                                  const HashMap<String, String>& extras)
-    : Intent(action, type, data, PassOwnPtr<MessagePortChannelArray>(), extras, KURL())
+    : Intent(action, type, data, PassOwnPtr<MessagePortChannelArray>(), extras, KURL(), Vector<KURL>())
     , FrameDestructionObserver(frame)
     , m_client(client)
     , m_ports(ports)

Modified: trunk/Source/WebCore/Modules/intents/Intent.cpp (117792 => 117793)


--- trunk/Source/WebCore/Modules/intents/Intent.cpp	2012-05-21 16:19:58 UTC (rev 117792)
+++ trunk/Source/WebCore/Modules/intents/Intent.cpp	2012-05-21 16:24:06 UTC (rev 117793)
@@ -34,6 +34,7 @@
 #include "ExceptionCode.h"
 #include "MessagePort.h"
 #include "SerializedScriptValue.h"
+#include <wtf/HashSet.h>
 
 namespace WebCore {
 
@@ -50,10 +51,11 @@
 
     OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(&ports, ec);
 
-    WTF::HashMap<String, String> extras;
-    KURL serviceUrl;
+    HashMap<String, String> extras;
+    KURL serviceURL;
+    Vector<KURL> suggestions;
 
-    return adoptRef(new Intent(action, type, data, channels.release(), extras, serviceUrl));
+    return adoptRef(new Intent(action, type, data, channels.release(), extras, serviceURL, suggestions));
 }
 
 PassRefPtr<Intent> Intent::create(ScriptState* scriptState, const Dictionary& options, ExceptionCode& ec)
@@ -96,22 +98,36 @@
         }
     }
 
-    WTF::HashMap<String, String> extras;
+    HashMap<String, String> extras;
     Dictionary extrasDictionary;
     if (options.get("extras", extrasDictionary))
         extrasDictionary.getOwnPropertiesAsStringHashMap(extras);
 
-    return adoptRef(new Intent(action, type, serializedData.release(), channels.release(), extras, serviceUrl));
+    HashSet<AtomicString> suggestionsStrings;
+    Vector<KURL> suggestions;
+    if (options.get("suggestions", suggestionsStrings)) {
+        for (HashSet<AtomicString>::iterator iter = suggestionsStrings.begin(); iter != suggestionsStrings.end(); ++iter) {
+            KURL suggestedURL = KURL(KURL(), *iter);
+            if (!suggestedURL.isValid()) {
+                ec = SYNTAX_ERR;
+                return 0;
+            }
+            suggestions.append(suggestedURL);
+        }
+    }
+
+    return adoptRef(new Intent(action, type, serializedData.release(), channels.release(), extras, serviceUrl, suggestions));
 }
 
 Intent::Intent(const String& action, const String& type,
                PassRefPtr<SerializedScriptValue> data, PassOwnPtr<MessagePortChannelArray> ports,
-               const WTF::HashMap<String, String>& extras, const KURL& service)
+               const HashMap<String, String>& extras, const KURL& service, const Vector<KURL>& suggestions)
     : m_action(action)
     , m_type(type)
     , m_ports(ports)
     , m_service(service)
     , m_extras(extras)
+    , m_suggestions(suggestions)
 {
     if (data)
         m_data = data;

Modified: trunk/Source/WebCore/Modules/intents/Intent.h (117792 => 117793)


--- trunk/Source/WebCore/Modules/intents/Intent.h	2012-05-21 16:19:58 UTC (rev 117792)
+++ trunk/Source/WebCore/Modules/intents/Intent.h	2012-05-21 16:24:06 UTC (rev 117793)
@@ -40,6 +40,7 @@
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
+#include <wtf/Vector.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
@@ -61,12 +62,13 @@
 
     MessagePortChannelArray* messagePorts() const { return m_ports.get(); }
     const KURL& service() const { return m_service; }
-    const WTF::HashMap<String, String>& extras() const { return m_extras; }
+    const HashMap<String, String>& extras() const { return m_extras; }
+    const Vector<KURL>& suggestions() const { return m_suggestions; }
 
 protected:
     Intent(const String& action, const String& type,
            PassRefPtr<SerializedScriptValue> data, PassOwnPtr<MessagePortChannelArray> ports,
-           const WTF::HashMap<String, String>& extras, const KURL& service);
+           const HashMap<String, String>& extras, const KURL& service, const Vector<KURL>& suggestions);
 
 private:
     String m_action;
@@ -74,7 +76,8 @@
     RefPtr<SerializedScriptValue> m_data;
     OwnPtr<MessagePortChannelArray> m_ports;
     KURL m_service;
-    WTF::HashMap<String, String> m_extras;
+    HashMap<String, String> m_extras;
+    Vector<KURL> m_suggestions;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebKit/chromium/ChangeLog (117792 => 117793)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-05-21 16:19:58 UTC (rev 117792)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-05-21 16:24:06 UTC (rev 117793)
@@ -1,3 +1,16 @@
+2012-05-21  Greg Billock  <[email protected]>
+
+        Add suggestions field to web intents API.
+        https://bugs.webkit.org/show_bug.cgi?id=86791
+
+        Reviewed by Adam Barth.
+
+        * public/WebIntent.h:
+        (WebIntent):
+        * src/WebIntent.cpp:
+        (WebKit::WebIntent::suggestions):
+        (WebKit):
+
 2012-05-20  Kinuko Yasuda  <[email protected]>
 
         Cleanup: Remove WebCore::revealFolderInOS() which is no longer used anywhere

Modified: trunk/Source/WebKit/chromium/public/WebIntent.h (117792 => 117793)


--- trunk/Source/WebKit/chromium/public/WebIntent.h	2012-05-21 16:19:58 UTC (rev 117792)
+++ trunk/Source/WebKit/chromium/public/WebIntent.h	2012-05-21 16:24:06 UTC (rev 117793)
@@ -66,6 +66,7 @@
     WEBKIT_EXPORT WebString type() const;
     WEBKIT_EXPORT WebString data() const;
     WEBKIT_EXPORT WebURL service() const;
+    WEBKIT_EXPORT WebVector<WebURL> suggestions() const;
 
     // Retrieve a list of the names of extra metadata associated with the
     // intent.

Modified: trunk/Source/WebKit/chromium/src/WebIntent.cpp (117792 => 117793)


--- trunk/Source/WebKit/chromium/src/WebIntent.cpp	2012-05-21 16:19:58 UTC (rev 117792)
+++ trunk/Source/WebKit/chromium/src/WebIntent.cpp	2012-05-21 16:24:06 UTC (rev 117793)
@@ -127,6 +127,18 @@
 #endif
 }
 
+WebVector<WebURL> WebIntent::suggestions() const
+{
+#if ENABLE(WEB_INTENTS)
+    WebVector<WebURL> suggestions(m_private->suggestions().size());
+    for (size_t i = 0; i < m_private->suggestions().size(); ++i)
+        suggestions[i] = m_private->suggestions().at(i);
+    return suggestions;
+#else
+    return WebVector<WebURL>();
+#endif
+}
+
 WebMessagePortChannelArray* WebIntent::messagePortChannelsRelease() const
 {
     // Note: see PlatformMessagePortChannel::postMessageToRemote.

Modified: trunk/Tools/DumpRenderTree/chromium/WebViewHost.cpp (117792 => 117793)


--- trunk/Tools/DumpRenderTree/chromium/WebViewHost.cpp	2012-05-21 16:19:58 UTC (rev 117792)
+++ trunk/Tools/DumpRenderTree/chromium/WebViewHost.cpp	2012-05-21 16:24:06 UTC (rev 117793)
@@ -1346,13 +1346,19 @@
             (*ports)[i]->destroy();
         delete ports;
     }
+
     if (!request.intent().service().isEmpty())
         printf("Explicit intent service: %s\n", request.intent().service().spec().data());
+
     WebVector<WebString> extras = request.intent().extrasNames();
     for (size_t i = 0; i < extras.size(); ++i) {
         printf("Extras[%s] = %s\n", extras[i].utf8().data(),
                request.intent().extrasValue(extras[i]).utf8().data());
     }
+
+    WebVector<WebURL> suggestions = request.intent().suggestions();
+    for (size_t i = 0; i < suggestions.size(); ++i)
+        printf("Have suggestion %s\n", suggestions[i].spec().data());
 }
 
 void WebViewHost::deliveredIntentResult(WebFrame* frame, int id, const WebSerializedScriptValue& data)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to