Skip to content
Permalink
Browse files
Add SPI to remove individual user scripts or user style sheets
https://bugs.webkit.org/show_bug.cgi?id=154046
rdar://problem/23596352

Reviewed by Sam Weinig.

* UIProcess/API/Cocoa/WKUserContentController.mm:
(-[WKUserContentController _removeUserScript:]):
(-[WKUserContentController _userStyleSheets]):
(-[WKUserContentController _addUserStyleSheet:]):
(-[WKUserContentController _removeUserStyleSheet:]):
* UIProcess/API/Cocoa/WKUserContentControllerPrivate.h:
* UIProcess/UserContent/WebUserContentControllerProxy.cpp:
(WebKit::WebUserContentControllerProxy::WebUserContentControllerProxy):
(WebKit::WebUserContentControllerProxy::addProcess):
(WebKit::WebUserContentControllerProxy::removeUserScript):
(WebKit::WebUserContentControllerProxy::addUserStyleSheet):
(WebKit::WebUserContentControllerProxy::removeUserStyleSheet):
(WebKit::WebUserContentControllerProxy::removeAllUserStyleSheets):
* UIProcess/UserContent/WebUserContentControllerProxy.h:
(WebKit::WebUserContentControllerProxy::userStyleSheets):
* WebProcess/UserContent/WebUserContentController.cpp:
(WebKit::WebUserContentController::removeUserScript):
(WebKit::WebUserContentController::removeUserStyleSheet):
* WebProcess/UserContent/WebUserContentController.h:
* WebProcess/UserContent/WebUserContentController.messages.in:

Canonical link: https://commits.webkit.org/172200@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@196399 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Anders Carlsson committed Feb 10, 2016
1 parent 14baf13 commit 961f67641393bb57370a21e0dfb0065af8ccb028
@@ -1,3 +1,32 @@
2016-02-10 Anders Carlsson <andersca@apple.com>

Add SPI to remove individual user scripts or user style sheets
https://bugs.webkit.org/show_bug.cgi?id=154046
rdar://problem/23596352

Reviewed by Sam Weinig.

* UIProcess/API/Cocoa/WKUserContentController.mm:
(-[WKUserContentController _removeUserScript:]):
(-[WKUserContentController _userStyleSheets]):
(-[WKUserContentController _addUserStyleSheet:]):
(-[WKUserContentController _removeUserStyleSheet:]):
* UIProcess/API/Cocoa/WKUserContentControllerPrivate.h:
* UIProcess/UserContent/WebUserContentControllerProxy.cpp:
(WebKit::WebUserContentControllerProxy::WebUserContentControllerProxy):
(WebKit::WebUserContentControllerProxy::addProcess):
(WebKit::WebUserContentControllerProxy::removeUserScript):
(WebKit::WebUserContentControllerProxy::addUserStyleSheet):
(WebKit::WebUserContentControllerProxy::removeUserStyleSheet):
(WebKit::WebUserContentControllerProxy::removeAllUserStyleSheets):
* UIProcess/UserContent/WebUserContentControllerProxy.h:
(WebKit::WebUserContentControllerProxy::userStyleSheets):
* WebProcess/UserContent/WebUserContentController.cpp:
(WebKit::WebUserContentController::removeUserScript):
(WebKit::WebUserContentController::removeUserStyleSheet):
* WebProcess/UserContent/WebUserContentController.h:
* WebProcess/UserContent/WebUserContentController.messages.in:

2016-02-10 Alex Christensen <achristensen@webkit.org>

Fix assertions when loading from WebProcess
@@ -126,6 +126,11 @@ - (void)removeScriptMessageHandlerForName:(NSString *)name

@implementation WKUserContentController (WKPrivate)

- (void)_removeUserScript:(WKUserScript *)userScript
{
_userContentControllerProxy->removeUserScript(*userScript->_userScript);
}

- (void)_addUserContentFilter:(_WKUserContentFilter *)userContentFilter
{
#if ENABLE(CONTENT_EXTENSIONS)
@@ -147,9 +152,19 @@ - (void)_removeAllUserContentFilters
#endif
}

- (NSArray *)_userStyleSheets
{
return wrapper(_userContentControllerProxy->userStyleSheets());
}

- (void)_addUserStyleSheet:(_WKUserStyleSheet *)userStyleSheet
{
_userContentControllerProxy->addUserStyleSheet(userStyleSheet->_userStyleSheet->userStyleSheet());
_userContentControllerProxy->addUserStyleSheet(*userStyleSheet->_userStyleSheet);
}

- (void)_removeUserStyleSheet:(_WKUserStyleSheet *)userStyleSheet
{
_userContentControllerProxy->removeUserStyleSheet(*userStyleSheet->_userStyleSheet);
}

- (void)_removeAllUserStyleSheets
@@ -27,16 +27,21 @@

#if WK_API_ENABLED

@class WKUserScript;
@class _WKUserContentFilter;
@class _WKUserStyleSheet;

@interface WKUserContentController (WKPrivate)

- (void)_removeUserScript:(WKUserScript *)userScript WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);

- (void)_addUserContentFilter:(_WKUserContentFilter *)userContentFilter WK_AVAILABLE(10_11, 9_0);
- (void)_removeUserContentFilter:(NSString *)userContentFilterName WK_AVAILABLE(10_11, 9_0);
- (void)_removeAllUserContentFilters WK_AVAILABLE(10_11, 9_0);

@property (nonatomic, readonly, copy) WK_ARRAY(_WKUserStyleSheet *) *_userStyleSheets WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
- (void)_addUserStyleSheet:(_WKUserStyleSheet *)userStyleSheet WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
- (void)_removeUserStyleSheet:(_WKUserStyleSheet *)userStyleSheet WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
- (void)_removeAllUserStyleSheets WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);

@end
@@ -28,6 +28,7 @@

#include "APIArray.h"
#include "APIUserScript.h"
#include "APIUserStyleSheet.h"
#include "DataReference.h"
#include "WebProcessProxy.h"
#include "WebScriptMessageHandler.h"
@@ -52,6 +53,7 @@ static uint64_t generateIdentifier()
WebUserContentControllerProxy::WebUserContentControllerProxy()
: m_identifier(generateIdentifier())
, m_userScripts(API::Array::create())
, m_userStyleSheets(API::Array::create())
{
}

@@ -77,7 +79,10 @@ void WebUserContentControllerProxy::addProcess(WebProcessProxy& webProcessProxy)
userScripts.append(userScript->userScript());
webProcessProxy.connection()->send(Messages::WebUserContentController::AddUserScripts(userScripts), m_identifier);

webProcessProxy.connection()->send(Messages::WebUserContentController::AddUserStyleSheets(m_userStyleSheets), m_identifier);
Vector<WebCore::UserStyleSheet> userStyleSheets;
for (const auto& userStyleSheet : m_userStyleSheets->elementsOfType<API::UserStyleSheet>())
userStyleSheets.append(userStyleSheet->userStyleSheet());
webProcessProxy.connection()->send(Messages::WebUserContentController::AddUserStyleSheets(userStyleSheets), m_identifier);

Vector<WebScriptMessageHandlerHandle> messageHandlerHandles;
for (auto& handler : m_scriptMessageHandlers.values())
@@ -108,6 +113,14 @@ void WebUserContentControllerProxy::addUserScript(API::UserScript& userScript)
process->connection()->send(Messages::WebUserContentController::AddUserScripts({ userScript.userScript() }), m_identifier);
}

void WebUserContentControllerProxy::removeUserScript(const API::UserScript& userScript)
{
for (WebProcessProxy* process : m_processes)
process->connection()->send(Messages::WebUserContentController::RemoveUserScript({ userScript.userScript().url().string() }), m_identifier);

m_userScripts->elements().removeAll(&userScript);
}

void WebUserContentControllerProxy::removeAllUserScripts()
{
m_userScripts->elements().clear();
@@ -116,17 +129,25 @@ void WebUserContentControllerProxy::removeAllUserScripts()
process->connection()->send(Messages::WebUserContentController::RemoveAllUserScripts(), m_identifier);
}

void WebUserContentControllerProxy::addUserStyleSheet(WebCore::UserStyleSheet userStyleSheet)
void WebUserContentControllerProxy::addUserStyleSheet(API::UserStyleSheet& userStyleSheet)
{
m_userStyleSheets.append(WTFMove(userStyleSheet));
m_userStyleSheets->elements().append(&userStyleSheet);

for (WebProcessProxy* process : m_processes)
process->connection()->send(Messages::WebUserContentController::AddUserStyleSheets({ m_userStyleSheets.last() }), m_identifier);
process->connection()->send(Messages::WebUserContentController::AddUserStyleSheets({ userStyleSheet.userStyleSheet() }), m_identifier);
}

void WebUserContentControllerProxy::removeUserStyleSheet(const API::UserStyleSheet& userStyleSheet)
{
for (WebProcessProxy* process : m_processes)
process->connection()->send(Messages::WebUserContentController::RemoveUserStyleSheet({ userStyleSheet.userStyleSheet().url().string() }), m_identifier);

m_userStyleSheets->elements().removeAll(&userStyleSheet);
}

void WebUserContentControllerProxy::removeAllUserStyleSheets()
{
m_userStyleSheets.clear();
m_userStyleSheets->elements().clear();

for (WebProcessProxy* process : m_processes)
process->connection()->send(Messages::WebUserContentController::RemoveAllUserStyleSheets(), m_identifier);
@@ -41,15 +41,14 @@ namespace API {
class Array;
class UserContentExtension;
class UserScript;
class UserStyleSheet;
}

namespace IPC {
class DataReference;
}

namespace WebCore {
class UserScript;
class UserStyleSheet;
struct SecurityOriginData;
}

@@ -74,9 +73,12 @@ class WebUserContentControllerProxy : public API::ObjectImpl<API::Object::Type::

API::Array& userScripts() { return m_userScripts.get(); }
void addUserScript(API::UserScript&);
void removeUserScript(const API::UserScript&);
void removeAllUserScripts();

void addUserStyleSheet(WebCore::UserStyleSheet);
API::Array& userStyleSheets() { return m_userStyleSheets.get(); }
void addUserStyleSheet(API::UserStyleSheet&);
void removeUserStyleSheet(const API::UserStyleSheet&);
void removeAllUserStyleSheets();

// Returns false if there was a name conflict.
@@ -98,7 +100,7 @@ class WebUserContentControllerProxy : public API::ObjectImpl<API::Object::Type::
uint64_t m_identifier;
HashSet<WebProcessProxy*> m_processes;
Ref<API::Array> m_userScripts;
Vector<WebCore::UserStyleSheet> m_userStyleSheets;
Ref<API::Array> m_userStyleSheets;
HashMap<uint64_t, RefPtr<WebScriptMessageHandler>> m_scriptMessageHandlers;

#if ENABLE(CONTENT_EXTENSIONS)
@@ -90,6 +90,11 @@ void WebUserContentController::addUserScripts(const Vector<WebCore::UserScript>&
m_userContentController->addUserScript(mainThreadNormalWorld(), std::make_unique<WebCore::UserScript>(userScript));
}

void WebUserContentController::removeUserScript(const String& urlString)
{
m_userContentController->removeUserScript(mainThreadNormalWorld(), URL(URL(), urlString));
}

void WebUserContentController::removeAllUserScripts()
{
m_userContentController->removeUserScripts(mainThreadNormalWorld());
@@ -103,6 +108,11 @@ void WebUserContentController::addUserStyleSheets(const Vector<WebCore::UserStyl
}
}

void WebUserContentController::removeUserStyleSheet(const String& urlString)
{
m_userContentController->removeUserStyleSheet(mainThreadNormalWorld(), URL(URL(), urlString));
}

void WebUserContentController::removeAllUserStyleSheets()
{
m_userContentController->removeUserStyleSheets(mainThreadNormalWorld());
@@ -53,9 +53,11 @@ class WebUserContentController final : public RefCounted<WebUserContentControlle
virtual void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&) override;

void addUserScripts(const Vector<WebCore::UserScript>&);
void removeUserScript(const String& urlString);
void removeAllUserScripts();

void addUserStyleSheets(const Vector<WebCore::UserStyleSheet>&);
void removeUserStyleSheet(const String& urlString);
void removeAllUserStyleSheets();

void addUserScriptMessageHandlers(const Vector<WebScriptMessageHandlerHandle>&);
@@ -25,9 +25,11 @@

messages -> WebUserContentController {
AddUserScripts(Vector<WebCore::UserScript> userScripts);
RemoveUserScript(String url);
RemoveAllUserScripts();

AddUserStyleSheets(Vector<WebCore::UserStyleSheet> userStyleSheets);
RemoveUserStyleSheet(String url);
RemoveAllUserStyleSheets();

AddUserScriptMessageHandlers(Vector<WebKit::WebScriptMessageHandlerHandle> scriptMessageHandlers);

0 comments on commit 961f676

Please sign in to comment.