Changeset 228036 in webkit


Ignore:
Timestamp:
Feb 2, 2018 4:49:56 PM (6 years ago)
Author:
david_quesada@apple.com
Message:

WebAppManifest scope should default to the containing directory of start_url if 'scope' is not specified
https://bugs.webkit.org/show_bug.cgi?id=182363
rdar://problem/37093498

Reviewed by Ryosuke Niwa.

Source/WebCore:

If an app manifest doesn't specify a scope, we should default to the "parent directory" of
the start URL, rather than leaving the app unbounded. This is more reasonable than using the
entire internet as the app scope.

No new tests, updates to the existing tests verify the new behavior.

  • Modules/applicationmanifest/ApplicationManifestParser.cpp:

(WebCore::ApplicationManifestParser::parseScope):

Tools:

Updated ApplicationManifestParserTests to account for the new default scope behavior.

  • TestWebKitAPI/Tests/WebCore/ApplicationManifestParser.cpp:

(assertManifestHasDefaultValues):
(TEST_F):

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r228034 r228036  
     12018-02-02  David Quesada  <david_quesada@apple.com>
     2
     3        WebAppManifest scope should default to the containing directory of start_url if 'scope' is not specified
     4        https://bugs.webkit.org/show_bug.cgi?id=182363
     5        rdar://problem/37093498
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        If an app manifest doesn't specify a scope, we should default to the "parent directory" of
     10        the start URL, rather than leaving the app unbounded. This is more reasonable than using the
     11        entire internet as the app scope.
     12
     13        No new tests, updates to the existing tests verify the new behavior.
     14
     15        * Modules/applicationmanifest/ApplicationManifestParser.cpp:
     16        (WebCore::ApplicationManifestParser::parseScope):
     17
    1182018-02-02  Youenn Fablet  <youenn@apple.com>
    219
  • trunk/Source/WebCore/Modules/applicationmanifest/ApplicationManifestParser.cpp

    r225639 r228036  
    194194URL ApplicationManifestParser::parseScope(const JSON::Object& manifest, const URL& documentURL, const URL& startURL)
    195195{
     196    URL defaultScope { startURL, "./" };
     197
    196198    RefPtr<JSON::Value> value;
    197199    if (!manifest.getValue("scope", value))
    198         return { };
     200        return defaultScope;
    199201
    200202    String stringValue;
    201203    if (!value->asString(stringValue)) {
    202204        logManifestPropertyNotAString(ASCIILiteral("scope"));
    203         return { };
     205        return defaultScope;
    204206    }
    205207
    206208    if (stringValue.isEmpty())
    207         return { };
     209        return defaultScope;
    208210
    209211    URL scopeURL(m_manifestURL, stringValue);
    210212    if (!scopeURL.isValid()) {
    211213        logManifestPropertyInvalidURL(ASCIILiteral("scope"));
    212         return { };
     214        return defaultScope;
    213215    }
    214216
     
    217219        auto documentOrigin = SecurityOrigin::create(documentURL);
    218220        logDeveloperWarning(ASCIILiteral("The scope's origin of \"") + scopeURLOrigin->toString() + ASCIILiteral("\" is different from the document's origin of \"") + documentOrigin->toString() + ASCIILiteral("\"."));
    219         return { };
     221        return defaultScope;
    220222    }
    221223
    222224    if (!isInScope(scopeURL, startURL)) {
    223225        logDeveloperWarning(ASCIILiteral("The start URL is not within scope of the provided scope URL."));
    224         return { };
     226        return defaultScope;
    225227    }
    226228
  • trunk/Tools/ChangeLog

    r228025 r228036  
     12018-02-02  David Quesada  <david_quesada@apple.com>
     2
     3        WebAppManifest scope should default to the containing directory of start_url if 'scope' is not specified
     4        https://bugs.webkit.org/show_bug.cgi?id=182363
     5        rdar://problem/37093498
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Updated ApplicationManifestParserTests to account for the new default scope behavior.
     10
     11        * TestWebKitAPI/Tests/WebCore/ApplicationManifestParser.cpp:
     12        (assertManifestHasDefaultValues):
     13        (TEST_F):
     14
    1152018-02-02  Youenn Fablet  <youenn@apple.com>
    216
  • trunk/Tools/TestWebKitAPI/Tests/WebCore/ApplicationManifestParser.cpp

    r225699 r228036  
    136136    EXPECT_TRUE(manifest.shortName.isNull());
    137137    EXPECT_TRUE(manifest.description.isNull());
    138     EXPECT_TRUE(manifest.scope.isEmpty());
    139     EXPECT_STREQ(manifest.startURL.string().utf8().data(), documentURL.string().utf8().data());
     138    EXPECT_STREQ("https://example.com/", manifest.scope.string().utf8().data());
     139    EXPECT_STREQ(documentURL.string().utf8().data(), manifest.startURL.string().utf8().data());
    140140}
    141141
     
    248248TEST_F(ApplicationManifestParserTest, Scope)
    249249{
    250     testScope("123", String());
    251     testScope("null", String());
    252     testScope("true", String());
    253     testScope("{ }", String());
    254     testScope("[ ]", String());
    255     testScope("\"\"", String());
    256 
    257     testScope("\"http:?\"", String());
    258 
    259     // If scope URL is not same origin as document URL, return undefined.
     250    // If the scope is not a string or not a valid URL, return the default scope (the parent path of the start URL).
     251    m_documentURL = { { }, "https://example.com/a/page?queryParam=value#fragment" };
     252    m_manifestURL = { { }, "https://example.com/manifest.json" };
     253    testScope("123", "https://example.com/a/");
     254    testScope("null", "https://example.com/a/");
     255    testScope("true", "https://example.com/a/");
     256    testScope("{ }", "https://example.com/a/");
     257    testScope("[ ]", "https://example.com/a/");
     258    testScope("\"\"", "https://example.com/a/");
     259    testScope("\"http:?\"", "https://example.com/a/");
     260
     261    m_documentURL = { { }, "https://example.com/a/pageEndingWithSlash/" };
     262    testScope("null", "https://example.com/a/pageEndingWithSlash/");
     263
     264    // If scope URL is not same origin as document URL, return the default scope.
    260265    m_documentURL = { { }, "https://example.com/home" };
    261266    m_manifestURL = { { }, "https://other-site.com/manifest.json" };
    262     testScope("\"https://other-site.com/some-scope\"", String());
     267    testScope("\"https://other-site.com/some-scope\"", "https://example.com/");
    263268
    264269    m_documentURL = { { }, "https://example.com/app/home" };
    265270    m_manifestURL = { { }, "https://example.com/app/manifest.json" };
    266271
    267     // If start URL is not within scope of scope URL, return undefined
    268     testScope("\"https://example.com/subdirectory\"", String());
     272    // If start URL is not within scope of scope URL, return the default scope.
     273    testScope("\"https://example.com/subdirectory\"", "https://example.com/app/");
    269274    testScope("\"https://example.com/app\"", "https://example.com/app");
    270     testScope("\"https://example.com/APP\"", String());
     275    testScope("\"https://example.com/APP\"", "https://example.com/app/");
    271276    testScope("\"https://example.com/a\"", "https://example.com/a");
    272277
Note: See TracChangeset for help on using the changeset viewer.