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):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@228036 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/Modules/applicationmanifest/ApplicationManifestParser.cpp b/Source/WebCore/Modules/applicationmanifest/ApplicationManifestParser.cpp
index f22842b..126538b 100644
--- a/Source/WebCore/Modules/applicationmanifest/ApplicationManifestParser.cpp
+++ b/Source/WebCore/Modules/applicationmanifest/ApplicationManifestParser.cpp
@@ -193,35 +193,37 @@
 
 URL ApplicationManifestParser::parseScope(const JSON::Object& manifest, const URL& documentURL, const URL& startURL)
 {
+    URL defaultScope { startURL, "./" };
+
     RefPtr<JSON::Value> value;
     if (!manifest.getValue("scope", value))
-        return { };
+        return defaultScope;
 
     String stringValue;
     if (!value->asString(stringValue)) {
         logManifestPropertyNotAString(ASCIILiteral("scope"));
-        return { };
+        return defaultScope;
     }
 
     if (stringValue.isEmpty())
-        return { };
+        return defaultScope;
 
     URL scopeURL(m_manifestURL, stringValue);
     if (!scopeURL.isValid()) {
         logManifestPropertyInvalidURL(ASCIILiteral("scope"));
-        return { };
+        return defaultScope;
     }
 
     if (!protocolHostAndPortAreEqual(scopeURL, documentURL)) {
         auto scopeURLOrigin = SecurityOrigin::create(scopeURL);
         auto documentOrigin = SecurityOrigin::create(documentURL);
         logDeveloperWarning(ASCIILiteral("The scope's origin of \"") + scopeURLOrigin->toString() + ASCIILiteral("\" is different from the document's origin of \"") + documentOrigin->toString() + ASCIILiteral("\"."));
-        return { };
+        return defaultScope;
     }
 
     if (!isInScope(scopeURL, startURL)) {
         logDeveloperWarning(ASCIILiteral("The start URL is not within scope of the provided scope URL."));
-        return { };
+        return defaultScope;
     }
 
     return scopeURL;