Changeset 257289 in webkit


Ignore:
Timestamp:
Feb 24, 2020 5:22:00 PM (4 years ago)
Author:
commit-queue@webkit.org
Message:

Add canShare function for Web Share API v2
https://bugs.webkit.org/show_bug.cgi?id=207491

Patch by Nikos Mouchtaris <Nikos Mouchtaris> on 2020-02-24
Reviewed by Tim Horton.

LayoutTests/imported/w3c:

Imported new web platform tests for canShare function.

  • resources/import-expectations.json:
  • web-platform-tests/web-share/OWNERS: Removed.
  • web-platform-tests/web-share/idlharness.https.html: Removed.
  • web-platform-tests/web-share/resources/manual-helper.js:

(setupManualShareTest):
(callWhenButtonClicked):

  • web-platform-tests/web-share/resources/w3c-import.log:
  • web-platform-tests/web-share/share-empty.https.html:
  • web-platform-tests/web-share/share-url-invalid.https.html:
  • web-platform-tests/web-share/share-without-user-gesture.https.html:
  • web-platform-tests/web-share/w3c-import.log:

Source/WebCore:

Added files member to share data and canShare function to
navigator.cpp. Can share function should always be used
before call to share, and can be used to check if file
sharing is implemented by passing a share data object with
only files.

Imported new Web Platform Tests to test new function.

  • page/Navigator.cpp:

(WebCore::Navigator::canShare): Will currently return false for
only file share data objects, since file sharing is currently
not implemented.
(WebCore::Navigator::share): Changed to use canShare to
determine if data is shareable.

  • page/Navigator.h:
  • page/NavigatorShare.idl:
  • page/ShareData.h:
  • page/ShareData.idl:
Location:
trunk
Files:
30 added
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/TestExpectations

    r257283 r257289  
    734734imported/w3c/web-platform-tests/content-security-policy/worker-src/shared-worker-src-script-fallback.sub.html
    735735imported/w3c/web-platform-tests/content-security-policy/worker-src/shared-worker-src-self-fallback.sub.html
     736
     737# Web platform test infrastructure unable to support insecure connection
     738imported/w3c/web-platform-tests/web-share/canShare-insecure.http.html
     739imported/w3c/web-platform-tests/web-share/share-securecontext.http.html
     740
     741# Web platform tests produce wrong failing results- https://bugs.webkit.org/show_bug.cgi?id=208083
     742imported/w3c/web-platform-tests/web-share/idlharness.https.window.html
     743imported/w3c/web-platform-tests/web-share/share-empty.https.html
     744imported/w3c/web-platform-tests/web-share/share-url-invalid.https.html
     745imported/w3c/web-platform-tests/web-share/share-without-user-gesture.https.html
     746imported/w3c/web-platform-tests/web-share/canShare.https.html
     747imported/w3c/web-platform-tests/web-share/canShare-files.https.html
    736748
    737749# Only relevant on macOS
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r257206 r257289  
     12020-02-24  Nikos Mouchtaris  <nmouchtaris@apple.com>
     2
     3        Add canShare function for Web Share API v2
     4        https://bugs.webkit.org/show_bug.cgi?id=207491
     5
     6        Reviewed by Tim Horton.
     7
     8        Imported new web platform tests for canShare function.
     9
     10        * resources/import-expectations.json:
     11        * web-platform-tests/web-share/OWNERS: Removed.
     12        * web-platform-tests/web-share/idlharness.https.html: Removed.
     13        * web-platform-tests/web-share/resources/manual-helper.js:
     14        (setupManualShareTest):
     15        (callWhenButtonClicked):
     16        * web-platform-tests/web-share/resources/w3c-import.log:
     17        * web-platform-tests/web-share/share-empty.https.html:
     18        * web-platform-tests/web-share/share-url-invalid.https.html:
     19        * web-platform-tests/web-share/share-without-user-gesture.https.html:
     20        * web-platform-tests/web-share/w3c-import.log:
     21
    1222020-02-24  Rob Buis  <rbuis@igalia.com>
    223
  • trunk/LayoutTests/imported/w3c/resources/import-expectations.json

    r256786 r257289  
    383383    "web-platform-tests/web-animations": "import",
    384384    "web-platform-tests/web-nfc": "skip",
     385    "web-platform-tests/web-share": "import",
    385386    "web-platform-tests/webaudio": "import",
    386387    "web-platform-tests/webauthn": "skip",
  • trunk/LayoutTests/imported/w3c/web-platform-tests/web-share/resources/manual-helper.js

    r222307 r257289  
    2929// instructions (based on the parameters) and the share button.
    3030function setupManualShareTest(expected_share_data) {
    31   const {title, text, url} = expected_share_data;
     31  const {title, text, url, files} = expected_share_data;
    3232  let [instruction, list] = setupManualShareTestCommon();
    3333  let item = document.createElement('li');
     
    5151  list.appendChild(item);
    5252  item.innerText = `url = "${url}"`;
     53  if (files) {
     54    item = document.createElement('li');
     55    list.appendChild(item);
     56    item.innerText = `files = ${files.length} file(s)`;
     57    for (let file of files) {
     58      const div = document.createElement('div');
     59      if (file.type.startsWith('text/')) {
     60        const reader = new FileReader();
     61        reader.onload = () => {
     62          div.textContent = reader.result;
     63        };
     64        reader.readAsText(file);
     65      } else if (file.type.startsWith('image/')) {
     66        const image = document.createElement('img');
     67        image.src = URL.createObjectURL(file);
     68        image.alt = file.name;
     69        div.appendChild(image);
     70      }
     71      item.appendChild(div);
     72    }
     73  }
    5374}
    5475
     
    6687    document.querySelector('#share_button').onclick = () => {
    6788      try {
    68         resolve(click_handler());
     89        const result = click_handler();
     90        resolve(result);
    6991      } catch (e) {
    7092        reject(e);
  • trunk/LayoutTests/imported/w3c/web-platform-tests/web-share/resources/w3c-import.log

    r222307 r257289  
    22Do NOT modify these tests directly in WebKit.
    33Instead, create a pull request on the WPT github:
    4         https://github.com/w3c/web-platform-tests
     4        https://github.com/web-platform-tests/wpt
    55
    66Then run the Tools/Scripts/import-w3c-tests in WebKit to reimport
  • trunk/LayoutTests/imported/w3c/web-platform-tests/web-share/share-empty.https.html

    r222307 r257289  
    1111    <script>
    1212        promise_test(t => {
    13           return promise_rejects(t, new TypeError(), navigator.share());
     13          return promise_rejects_js(t, TypeError, navigator.share());
    1414        }, 'share with no arguments (same as empty dictionary)');
    1515
    1616        promise_test(t => {
    17           return promise_rejects(t, new TypeError(), navigator.share({}));
     17          return promise_rejects_js(t, TypeError, navigator.share({}));
    1818        }, 'share with an empty dictionary');
    1919
    2020        promise_test(t => {
    21           return promise_rejects(t, new TypeError(), navigator.share(undefined));
     21          return promise_rejects_js(t, TypeError, navigator.share(undefined));
    2222        }, 'share with a undefined argument (same as empty dictionary)');
    2323
    2424        promise_test(t => {
    25           return promise_rejects(t, new TypeError(), navigator.share(null));
     25          return promise_rejects_js(t, TypeError, navigator.share(null));
    2626        }, 'share with a null argument (same as empty dictionary)');
    2727
    2828        promise_test(t => {
    29           return promise_rejects(t,
    30               new TypeError(), navigator.share({unused: 'unexpected field'}));
     29          return promise_rejects_js(t,
     30              TypeError, navigator.share({unused: 'unexpected field'}));
    3131        }, 'share with a dictionary containing only surplus fields');
    3232    </script>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/web-share/share-url-invalid.https.html

    r222307 r257289  
    1313          // large).
    1414          const url = 'http://example.com:65536';
    15           return promise_rejects(
    16               t, new TypeError(), navigator.share({url}));
     15          return promise_rejects_js(
     16              t, TypeError, navigator.share({url}));
    1717        }, 'share with an invalid URL');
    1818    </script>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/web-share/share-without-user-gesture.https.html

    r222307 r257289  
    1313              t, 'NotAllowedError',
    1414              navigator.share({title: 'the title', text: 'the message',
    15                                url: 'data:the url'}));
     15                               url: 'https://example.com'}));
    1616        }, 'share without a user gesture');
    1717    </script>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/web-share/w3c-import.log

    r222307 r257289  
    22Do NOT modify these tests directly in WebKit.
    33Instead, create a pull request on the WPT github:
    4         https://github.com/w3c/web-platform-tests
     4        https://github.com/web-platform-tests/wpt
    55
    66Then run the Tools/Scripts/import-w3c-tests in WebKit to reimport
     
    1515------------------------------------------------------------------------
    1616List of files:
    17 /LayoutTests/imported/w3c/web-platform-tests/web-share/OWNERS
    18 /LayoutTests/imported/w3c/web-platform-tests/web-share/idlharness.https.html
     17/LayoutTests/imported/w3c/web-platform-tests/web-share/META.yml
     18/LayoutTests/imported/w3c/web-platform-tests/web-share/canShare-files.tentative.https.html
     19/LayoutTests/imported/w3c/web-platform-tests/web-share/canShare-insecure.tentative.http.html
     20/LayoutTests/imported/w3c/web-platform-tests/web-share/canShare.tentative.https.html
     21/LayoutTests/imported/w3c/web-platform-tests/web-share/idlharness.https.window.js
     22/LayoutTests/imported/w3c/web-platform-tests/web-share/share-cancel-manual.https.html
    1923/LayoutTests/imported/w3c/web-platform-tests/web-share/share-empty.https.html
     24/LayoutTests/imported/w3c/web-platform-tests/web-share/share-extra-argument-manual.https.html
     25/LayoutTests/imported/w3c/web-platform-tests/web-share/share-extra-field-manual.https.html
     26/LayoutTests/imported/w3c/web-platform-tests/web-share/share-files-manual.tentative.https.html
     27/LayoutTests/imported/w3c/web-platform-tests/web-share/share-image-manual.tentative.https.html
     28/LayoutTests/imported/w3c/web-platform-tests/web-share/share-non-string-manual.https.html
     29/LayoutTests/imported/w3c/web-platform-tests/web-share/share-null-manual.https.html
    2030/LayoutTests/imported/w3c/web-platform-tests/web-share/share-securecontext.http.html
     31/LayoutTests/imported/w3c/web-platform-tests/web-share/share-sharePromise-internal-slot.https.html
     32/LayoutTests/imported/w3c/web-platform-tests/web-share/share-simple-manual.https.html
     33/LayoutTests/imported/w3c/web-platform-tests/web-share/share-unicode-strings-manual.https.html
     34/LayoutTests/imported/w3c/web-platform-tests/web-share/share-unicode-strings-nonutf8-manual.https.html
     35/LayoutTests/imported/w3c/web-platform-tests/web-share/share-url-data-manual.https.html
     36/LayoutTests/imported/w3c/web-platform-tests/web-share/share-url-empty-manual.https.html
     37/LayoutTests/imported/w3c/web-platform-tests/web-share/share-url-encoding-manual.https.html
    2138/LayoutTests/imported/w3c/web-platform-tests/web-share/share-url-invalid.https.html
     39/LayoutTests/imported/w3c/web-platform-tests/web-share/share-url-noscheme-manual.https.html
     40/LayoutTests/imported/w3c/web-platform-tests/web-share/share-url-pathonly-manual.https.html
     41/LayoutTests/imported/w3c/web-platform-tests/web-share/share-url-relative-manual.https.html
    2242/LayoutTests/imported/w3c/web-platform-tests/web-share/share-without-user-gesture.https.html
  • trunk/Source/WebCore/ChangeLog

    r257285 r257289  
     12020-02-24  Nikos Mouchtaris  <nmouchtaris@apple.com>
     2
     3        Add canShare function for Web Share API v2
     4        https://bugs.webkit.org/show_bug.cgi?id=207491
     5
     6        Reviewed by Tim Horton.
     7
     8        Added files member to share data and canShare function to
     9        navigator.cpp. Can share function should always be used
     10        before call to share, and can be used to check if file
     11        sharing is implemented by passing a share data object with
     12        only files.
     13
     14        Imported new Web Platform Tests to test new function.
     15
     16        * page/Navigator.cpp:
     17        (WebCore::Navigator::canShare): Will currently return false for
     18        only file share data objects, since file sharing is currently
     19        not implemented.
     20        (WebCore::Navigator::share): Changed to use canShare to
     21        determine if data is shareable.
     22        * page/Navigator.h:
     23        * page/NavigatorShare.idl:
     24        * page/ShareData.h:
     25        * page/ShareData.idl:
     26
    1272020-02-24  Yusuke Suzuki  <ysuzuki@apple.com>
    228
  • trunk/Source/WebCore/page/Navigator.cpp

    r254178 r257289  
    4343#include "SecurityOrigin.h"
    4444#include "Settings.h"
     45#include "ShareData.h"
    4546#include <wtf/IsoMallocInlines.h>
    4647#include <wtf/Language.h>
     
    106107}
    107108
    108 void Navigator::share(ScriptExecutionContext& context, ShareData data, Ref<DeferredPromise>&& promise)
    109 {
    110     auto* frame = this->frame();
    111     if (!frame || !frame->page()) {
     109bool Navigator::canShare(ScriptExecutionContext& context, const ShareData& data)
     110{
     111    auto* frame = this->frame();
     112    if (!frame || !frame->page())
     113        return false;
     114    if (data.title.isNull() && data.url.isNull() && data.text.isNull()) {
     115        if (!data.files.isEmpty())
     116            return false;
     117        return false;
     118    }
     119
     120    Optional<URL> url;
     121    if (!data.url.isNull()) {
     122        url = context.completeURL(data.url);
     123        if (!url->isValid())
     124            return false;
     125    }
     126    return true;
     127}
     128
     129void Navigator::share(ScriptExecutionContext& context, const ShareData& data, Ref<DeferredPromise>&& promise)
     130{
     131    if (!canShare(context, data)) {
    112132        promise->reject(TypeError);
    113133        return;
    114134    }
    115135   
    116     if (data.title.isEmpty() && data.url.isEmpty() && data.text.isEmpty()) {
    117         promise->reject(TypeError);
    118         return;
    119     }
    120 
    121136    Optional<URL> url;
    122     if (!data.url.isEmpty()) {
     137    if (!data.url.isEmpty())
    123138        url = context.completeURL(data.url);
    124         if (!url->isValid()) {
    125             promise->reject(TypeError);
    126             return;
    127         }
    128     }
    129139   
    130140    auto* window = this->window();
     
    139149        url,
    140150    };
    141 
     151   
     152    auto* frame = this->frame();
    142153    frame->page()->chrome().showShareSheet(shareData, [promise = WTFMove(promise)] (bool completed) {
    143154        if (completed) {
  • trunk/Source/WebCore/page/Navigator.h

    r250735 r257289  
    2323#include "NavigatorBase.h"
    2424#include "ScriptWrappable.h"
    25 #include "ShareData.h"
    2625#include "Supplementable.h"
    2726#include <wtf/IsoMalloc.h>
     
    3231class DOMMimeTypeArray;
    3332class DOMPluginArray;
     33struct ShareData;
    3434
    3535class Navigator final : public NavigatorBase, public ScriptWrappable, public DOMWindowProperty, public Supplementable<Navigator> {
     
    4848    void userAgentChanged();
    4949    bool onLine() const final;
    50     void share(ScriptExecutionContext&, ShareData, Ref<DeferredPromise>&&);
     50    bool canShare(ScriptExecutionContext&, const ShareData&);
     51    void share(ScriptExecutionContext&, const ShareData&, Ref<DeferredPromise>&&);
    5152   
    5253#if PLATFORM(IOS_FAMILY)
  • trunk/Source/WebCore/page/NavigatorShare.idl

    r235489 r257289  
    2929    EnabledAtRuntime=WebShare
    3030] interface NavigatorShare {
     31    [CallWith=ScriptExecutionContext, SecureContext] boolean canShare(optional ShareData shareData);
    3132    [CallWith=ScriptExecutionContext, SecureContext] Promise<void> share(optional ShareData shareData);
    3233};
  • trunk/Source/WebCore/page/RuntimeEnabledFeatures.h

    r257234 r257289  
    402402    bool isAccessibilityIsolatedTreeEnabled() const { return m_accessibilityIsolatedTree; }
    403403#endif
     404   
     405    void setWebShareFileAPIEnabled(bool isEnabled) { m_webShareFileAPIEnabled = isEnabled; }
     406    bool webShareFileAPIEnabled() const { return m_webShareFileAPIEnabled; }
    404407
    405408private:
     
    608611    bool m_accessibilityIsolatedTree { false };
    609612#endif
     613    bool m_webShareFileAPIEnabled { false };
    610614
    611615    friend class WTF::NeverDestroyed<RuntimeEnabledFeatures>;
  • trunk/Source/WebCore/page/ShareData.h

    r239427 r257289  
    2525
    2626#pragma once
     27#include "File.h"
    2728#include <wtf/URL.h>
    2829
     
    3334    String text;
    3435    String url;
     36    Vector<RefPtr<File>> files;
    3537};
    3638   
  • trunk/Source/WebCore/page/ShareData.idl

    r235489 r257289  
    2828    USVString text;
    2929    USVString url;
     30    FrozenArray<File> files;
    3031};
  • trunk/Source/WebKit/Shared/WebPreferences.yaml

    r257254 r257289  
    19601960    condition: ENABLE(ACCESSIBILITY_ISOLATED_TREE)
    19611961
     1962WebShareFileAPIEnabled:
     1963    type: bool
     1964    defaultValue: false
     1965    humanReadableName: "Web Share API Level 2"
     1966    humanReadableDescription: "Enable level 2 of Web Share API"
     1967    webcoreBinding: RuntimeEnabledFeatures
     1968    category: experimental
     1969
    19621970# Deprecated
    19631971
  • trunk/Source/WebKit/UIProcess/API/C/WKPreferencesRefPrivate.h

    r256512 r257289  
    6161// Defaults to EditableLinkNeverLive.
    6262WK_EXPORT void WKPreferencesSetEditableLinkBehavior(WKPreferencesRef preferencesRef, WKEditableLinkBehavior);
    63 WK_EXPORT WKEditableLinkBehavior WKPreferencesGetEditableLinkBehavior(WKPreferencesRef preferencesRef);   
     63WK_EXPORT WKEditableLinkBehavior WKPreferencesGetEditableLinkBehavior(WKPreferencesRef preferencesRef);
    6464   
    6565// Defaults to false.
Note: See TracChangeset for help on using the changeset viewer.