Adding user content to a group should force that group to be created
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Dec 2014 00:23:22 +0000 (00:23 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Dec 2014 00:23:22 +0000 (00:23 +0000)
https://bugs.webkit.org/show_bug.cgi?id=139421
rdar://problem/19180108

Reviewed by Sam Weinig.

* WebCoreSupport/WebViewGroup.h:
Store the local storage database path in the group.

* WebCoreSupport/WebViewGroup.mm:
(WebViewGroup::getOrCreate):
If we have an existing group that hasn't had its storage namespace provider created, and the path passed is not empty,
set it. This will ensure that getOrCreate will still work when creating a storage namspace provider.

(WebViewGroup::WebViewGroup):
Initialize the new member variable.

(WebViewGroup::storageNamespaceProvider):
Create the namespace provider lazily.

* WebView/WebView.mm:
(+[WebView _addUserScriptToGroup:world:source:url:whitelist:blacklist:injectionTime:injectedFrames:]):
(+[WebView _addUserStyleSheetToGroup:world:source:url:whitelist:blacklist:injectedFrames:]):
Use getOrCreate instead of get.

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

Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebCoreSupport/WebViewGroup.h
Source/WebKit/mac/WebCoreSupport/WebViewGroup.mm
Source/WebKit/mac/WebView/WebView.mm

index 7c88f6b..f1e92be 100644 (file)
@@ -1,5 +1,32 @@
 2014-12-08  Anders Carlsson  <andersca@apple.com>
 
+        Adding user content to a group should force that group to be created
+        https://bugs.webkit.org/show_bug.cgi?id=139421
+        rdar://problem/19180108
+
+        Reviewed by Sam Weinig.
+
+        * WebCoreSupport/WebViewGroup.h:
+        Store the local storage database path in the group.
+
+        * WebCoreSupport/WebViewGroup.mm:
+        (WebViewGroup::getOrCreate):
+        If we have an existing group that hasn't had its storage namespace provider created, and the path passed is not empty,
+        set it. This will ensure that getOrCreate will still work when creating a storage namspace provider.
+
+        (WebViewGroup::WebViewGroup):
+        Initialize the new member variable.
+
+        (WebViewGroup::storageNamespaceProvider):
+        Create the namespace provider lazily.
+
+        * WebView/WebView.mm:
+        (+[WebView _addUserScriptToGroup:world:source:url:whitelist:blacklist:injectionTime:injectedFrames:]):
+        (+[WebView _addUserStyleSheetToGroup:world:source:url:whitelist:blacklist:injectedFrames:]):
+        Use getOrCreate instead of get.
+
+2014-12-08  Anders Carlsson  <andersca@apple.com>
+
         WebStorageNamespaceProvider should know about its local storage database path
         https://bugs.webkit.org/show_bug.cgi?id=139413
 
index 927ba53..3ee99ba 100644 (file)
@@ -46,7 +46,7 @@ public:
     void addWebView(WebView *);
     void removeWebView(WebView *);
 
-    WebCore::StorageNamespaceProvider& storageNamespaceProvider() { return m_storageNamespaceProvider.get(); }
+    WebCore::StorageNamespaceProvider& storageNamespaceProvider();
     WebCore::UserContentController& userContentController() { return m_userContentController.get(); }
     WebVisitedLinkStore& visitedLinkStore() { return m_visitedLinkStore.get(); }
 
@@ -56,7 +56,9 @@ private:
     String m_name;
     HashSet<WebView *> m_webViews;
 
-    Ref<WebCore::StorageNamespaceProvider> m_storageNamespaceProvider;
+    String m_localStorageDatabasePath;
+    RefPtr<WebCore::StorageNamespaceProvider> m_storageNamespaceProvider;
+
     Ref<WebCore::UserContentController> m_userContentController;
     Ref<WebVisitedLinkStore> m_visitedLinkStore;
 };
index 9cb7b07..8ed8c4c 100644 (file)
@@ -50,6 +50,8 @@ RefPtr<WebViewGroup> WebViewGroup::getOrCreate(const String& name, const String&
     auto& webViewGroup = webViewGroups().add(name, nullptr).iterator->value;
     if (!webViewGroup)
         webViewGroup = adoptRef(new WebViewGroup(name, localStorageDatabasePath));
+    else if (!webViewGroup->m_storageNamespaceProvider && webViewGroup->m_localStorageDatabasePath.isEmpty() && !localStorageDatabasePath.isEmpty())
+        webViewGroup->m_localStorageDatabasePath = localStorageDatabasePath;
 
     return webViewGroup;
 }
@@ -63,7 +65,7 @@ WebViewGroup* WebViewGroup::get(const String& name)
 
 WebViewGroup::WebViewGroup(const String& name, const String& localStorageDatabasePath)
     : m_name(name)
-    , m_storageNamespaceProvider(*WebStorageNamespaceProvider::create(localStorageDatabasePath))
+    , m_localStorageDatabasePath(localStorageDatabasePath)
     , m_userContentController(*UserContentController::create())
     , m_visitedLinkStore(WebVisitedLinkStore::create())
 {
@@ -88,3 +90,11 @@ void WebViewGroup::removeWebView(WebView *webView)
 
     m_webViews.remove(webView);
 }
+
+StorageNamespaceProvider& WebViewGroup::storageNamespaceProvider()
+{
+    if (!m_storageNamespaceProvider)
+        m_storageNamespaceProvider = WebStorageNamespaceProvider::create(m_localStorageDatabasePath);
+
+    return *m_storageNamespaceProvider;
+}
index af724fa..e68a77d 100644 (file)
@@ -4023,7 +4023,7 @@ static Vector<String> toStringVector(NSArray* patterns)
     if (group.isEmpty())
         return;
 
-    auto* viewGroup = WebViewGroup::get(group);
+    auto viewGroup = WebViewGroup::getOrCreate(groupName, String());
     if (!viewGroup)
         return;
 
@@ -4048,7 +4048,7 @@ static Vector<String> toStringVector(NSArray* patterns)
     if (group.isEmpty())
         return;
 
-    auto* viewGroup = WebViewGroup::get(group);
+    auto viewGroup = WebViewGroup::getOrCreate(groupName, String());
     if (!viewGroup)
         return;