WebDataListSuggestionsDropdown should use a WeakPtr
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 19 Oct 2018 23:15:27 +0000 (23:15 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 19 Oct 2018 23:15:27 +0000 (23:15 +0000)
https://bugs.webkit.org/show_bug.cgi?id=190763
<rdar://problem/45417449>

Reviewed by Tim Horton.

Nothing suspicious here. It's just good practice to not keep raw pointers that aren't reset when the object they point to are destroyed.

* UIProcess/WebDataListSuggestionsDropdown.cpp:
(WebKit::WebDataListSuggestionsDropdown::WebDataListSuggestionsDropdown):
(WebKit::WebDataListSuggestionsDropdown::close):
* UIProcess/WebDataListSuggestionsDropdown.h:
(WebKit::WebDataListSuggestionsDropdown::Client::~Client): Deleted.
* UIProcess/WebPageProxy.h:
* UIProcess/ios/WebDataListSuggestionsDropdownIOS.h:
* UIProcess/ios/WebDataListSuggestionsDropdownIOS.mm:
(WebKit::WebDataListSuggestionsDropdownIOS::create):
(WebKit::WebDataListSuggestionsDropdownIOS::WebDataListSuggestionsDropdownIOS):
(WebKit::WebDataListSuggestionsDropdownIOS::close):
(WebKit::WebDataListSuggestionsDropdownIOS::didSelectOption):
* UIProcess/mac/WebDataListSuggestionsDropdownMac.h:
* UIProcess/mac/WebDataListSuggestionsDropdownMac.mm:
(WebKit::WebDataListSuggestionsDropdownMac::create):
(WebKit::WebDataListSuggestionsDropdownMac::WebDataListSuggestionsDropdownMac):
(WebKit::WebDataListSuggestionsDropdownMac::didSelectOption):
(WebKit::WebDataListSuggestionsDropdownMac::selectOption):

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/WebDataListSuggestionsDropdown.cpp
Source/WebKit/UIProcess/WebDataListSuggestionsDropdown.h
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/UIProcess/ios/WebDataListSuggestionsDropdownIOS.h
Source/WebKit/UIProcess/ios/WebDataListSuggestionsDropdownIOS.mm
Source/WebKit/UIProcess/mac/WebDataListSuggestionsDropdownMac.h
Source/WebKit/UIProcess/mac/WebDataListSuggestionsDropdownMac.mm

index be1fcbf..e5162dd 100644 (file)
@@ -1,3 +1,32 @@
+2018-10-19  Alex Christensen  <achristensen@webkit.org>
+
+        WebDataListSuggestionsDropdown should use a WeakPtr
+        https://bugs.webkit.org/show_bug.cgi?id=190763
+        <rdar://problem/45417449>
+
+        Reviewed by Tim Horton.
+
+        Nothing suspicious here. It's just good practice to not keep raw pointers that aren't reset when the object they point to are destroyed.
+
+        * UIProcess/WebDataListSuggestionsDropdown.cpp:
+        (WebKit::WebDataListSuggestionsDropdown::WebDataListSuggestionsDropdown):
+        (WebKit::WebDataListSuggestionsDropdown::close):
+        * UIProcess/WebDataListSuggestionsDropdown.h:
+        (WebKit::WebDataListSuggestionsDropdown::Client::~Client): Deleted.
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/ios/WebDataListSuggestionsDropdownIOS.h:
+        * UIProcess/ios/WebDataListSuggestionsDropdownIOS.mm:
+        (WebKit::WebDataListSuggestionsDropdownIOS::create):
+        (WebKit::WebDataListSuggestionsDropdownIOS::WebDataListSuggestionsDropdownIOS):
+        (WebKit::WebDataListSuggestionsDropdownIOS::close):
+        (WebKit::WebDataListSuggestionsDropdownIOS::didSelectOption):
+        * UIProcess/mac/WebDataListSuggestionsDropdownMac.h:
+        * UIProcess/mac/WebDataListSuggestionsDropdownMac.mm:
+        (WebKit::WebDataListSuggestionsDropdownMac::create):
+        (WebKit::WebDataListSuggestionsDropdownMac::WebDataListSuggestionsDropdownMac):
+        (WebKit::WebDataListSuggestionsDropdownMac::didSelectOption):
+        (WebKit::WebDataListSuggestionsDropdownMac::selectOption):
+
 2018-10-19  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         [iOS] [Datalist] Can't pick datalist suggestions in a stock WKWebView
index 2f5fac0..ee6ed8c 100644 (file)
@@ -30,8 +30,8 @@
 
 namespace WebKit {
 
-WebDataListSuggestionsDropdown::WebDataListSuggestionsDropdown(Client& client)
-    : m_client(&client)
+WebDataListSuggestionsDropdown::WebDataListSuggestionsDropdown(WebPageProxy& page)
+    : m_page(makeWeakPtr(page))
 {
 }
 
@@ -41,8 +41,8 @@ WebDataListSuggestionsDropdown::~WebDataListSuggestionsDropdown()
 
 void WebDataListSuggestionsDropdown::close()
 {
-    m_client->didCloseSuggestions();
-    m_client = nullptr;
+    if (auto page = std::exchange(m_page, nullptr))
+        page->didCloseSuggestions();
 }
 
 } // namespace WebKit
index 29e3bbf..7a5c8ac 100644 (file)
 #include <WebCore/DataListSuggestionPicker.h>
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
+#include <wtf/WeakPtr.h>
 
 namespace WebKit {
 
+class WebPageProxy;
+
 class WebDataListSuggestionsDropdown : public RefCounted<WebDataListSuggestionsDropdown> {
 public:
-    class Client {
-    protected:
-        virtual ~Client() { }
-
-    public:
-        virtual void didSelectOption(const String&) = 0;
-        virtual void didCloseSuggestions() = 0;
-    };
-
     virtual ~WebDataListSuggestionsDropdown();
 
     virtual void show(WebCore::DataListSuggestionInformation&&) = 0;
@@ -51,9 +45,9 @@ public:
     virtual void close();
 
 protected:
-    explicit WebDataListSuggestionsDropdown(Client&);
+    explicit WebDataListSuggestionsDropdown(WebPageProxy&);
 
-    Client* m_client;
+    WeakPtr<WebPageProxy> m_page;
 };
 
 } // namespace WebKit
index 7e2cc8b..9ce1e8f 100644 (file)
@@ -333,9 +333,6 @@ class WebPageProxy : public API::ObjectImpl<API::Object::Type::Page>
 #if ENABLE(INPUT_TYPE_COLOR)
     , public WebColorPicker::Client
 #endif
-#if ENABLE(DATALIST_ELEMENT)
-    , public WebDataListSuggestionsDropdown::Client
-#endif
 #if ENABLE(WIRELESS_PLAYBACK_TARGET) && !PLATFORM(IOS_FAMILY)
     , public WebCore::WebMediaSessionManagerClient
 #endif
@@ -1364,6 +1361,11 @@ public:
     Vector<String> mediaMIMETypes();
 #endif
 
+#if ENABLE(DATALIST_ELEMENT)
+    void didSelectOption(const String&);
+    void didCloseSuggestions();
+#endif
+
 private:
     WebPageProxy(PageClient&, WebProcessProxy&, uint64_t pageID, Ref<API::PageConfiguration>&&);
     void platformInitialize();
@@ -1551,8 +1553,6 @@ private:
     void showDataListSuggestions(WebCore::DataListSuggestionInformation&&);
     void handleKeydownInDataList(const String&);
     void endDataListSuggestions();
-    void didSelectOption(const String&) final;
-    void didCloseSuggestions() final;
 #endif
 
     void closeOverlayedViews();
index c899cb5..a423f28 100644 (file)
@@ -42,12 +42,12 @@ namespace WebKit {
 
 class WebDataListSuggestionsDropdownIOS : public WebDataListSuggestionsDropdown {
 public:
-    static Ref<WebDataListSuggestionsDropdownIOS> create(WebDataListSuggestionsDropdown::Client&, WKContentView *);
+    static Ref<WebDataListSuggestionsDropdownIOS> create(WebPageProxy&, WKContentView *);
 
     void didSelectOption(const String&);
 
 private:
-    WebDataListSuggestionsDropdownIOS(WebDataListSuggestionsDropdown::Client&, WKContentView *);
+    WebDataListSuggestionsDropdownIOS(WebPageProxy&, WKContentView *);
 
     void show(WebCore::DataListSuggestionInformation&&) final;
     void handleKeydownWithIdentifier(const String&) final;
index 3f58f71..6f07d89 100644 (file)
@@ -32,6 +32,7 @@
 #import "WKContentViewInteraction.h"
 #import "WKFormPeripheral.h"
 #import "WKFormPopover.h"
+#import "WebPageProxy.h"
 
 static const CGFloat maxVisibleSuggestions = 5;
 static const CGFloat suggestionsPopoverCellHeight = 44;
@@ -80,13 +81,13 @@ static NSString * const suggestionCellReuseIdentifier = @"WKDataListSuggestionCe
 
 namespace WebKit {
 
-Ref<WebDataListSuggestionsDropdownIOS> WebDataListSuggestionsDropdownIOS::create(WebDataListSuggestionsDropdown::Client& client, WKContentView *view)
+Ref<WebDataListSuggestionsDropdownIOS> WebDataListSuggestionsDropdownIOS::create(WebPageProxy& page, WKContentView *view)
 {
-    return adoptRef(*new WebDataListSuggestionsDropdownIOS(client, view));
+    return adoptRef(*new WebDataListSuggestionsDropdownIOS(page, view));
 }
 
-WebDataListSuggestionsDropdownIOS::WebDataListSuggestionsDropdownIOS(WebDataListSuggestionsDropdown::Client& client, WKContentView *view)
-    : WebDataListSuggestionsDropdown(client)
+WebDataListSuggestionsDropdownIOS::WebDataListSuggestionsDropdownIOS(WebPageProxy& page, WKContentView *view)
+    : WebDataListSuggestionsDropdown(page)
     , m_contentView(view)
 {
 }
@@ -116,15 +117,15 @@ void WebDataListSuggestionsDropdownIOS::close()
 {
     [m_suggestionsControl invalidate];
     m_suggestionsControl = nil;
-    m_client->didCloseSuggestions();
+    m_page->didCloseSuggestions();
 }
 
 void WebDataListSuggestionsDropdownIOS::didSelectOption(const String& selectedOption)
 {
-    if (!m_client)
+    if (!m_page)
         return;
 
-    m_client->didSelectOption(selectedOption);
+    m_page->didSelectOption(selectedOption);
     close();
 }
 
index 80bf948..97f1304 100644 (file)
@@ -36,13 +36,13 @@ namespace WebKit {
 
 class WebDataListSuggestionsDropdownMac final : public WebDataListSuggestionsDropdown {
 public:
-    static Ref<WebDataListSuggestionsDropdownMac> create(WebDataListSuggestionsDropdown::Client&, NSView *);
+    static Ref<WebDataListSuggestionsDropdownMac> create(WebPageProxy&, NSView *);
     ~WebDataListSuggestionsDropdownMac();
 
     void didSelectOption(const String&);
 
 private:
-    WebDataListSuggestionsDropdownMac(WebDataListSuggestionsDropdown::Client&, NSView *);
+    WebDataListSuggestionsDropdownMac(WebPageProxy&, NSView *);
 
     void show(WebCore::DataListSuggestionInformation&&) final;
     void handleKeydownWithIdentifier(const String&) final;
index 458b58b..8d4f070 100644 (file)
@@ -84,15 +84,15 @@ static NSString * const suggestionCellReuseIdentifier = @"WKDataListSuggestionCe
 
 namespace WebKit {
 
-Ref<WebDataListSuggestionsDropdownMac> WebDataListSuggestionsDropdownMac::create(WebDataListSuggestionsDropdown::Client& client, NSView *view)
+Ref<WebDataListSuggestionsDropdownMac> WebDataListSuggestionsDropdownMac::create(WebPageProxy& page, NSView *view)
 {
-    return adoptRef(*new WebDataListSuggestionsDropdownMac(client, view));
+    return adoptRef(*new WebDataListSuggestionsDropdownMac(page, view));
 }
 
 WebDataListSuggestionsDropdownMac::~WebDataListSuggestionsDropdownMac() { }
 
-WebDataListSuggestionsDropdownMac::WebDataListSuggestionsDropdownMac(WebDataListSuggestionsDropdown::Client& client, NSView *view)
-    : WebDataListSuggestionsDropdown(client)
+WebDataListSuggestionsDropdownMac::WebDataListSuggestionsDropdownMac(WebPageProxy& page, NSView *view)
+    : WebDataListSuggestionsDropdown(page)
     , m_view(view)
 {
 }
@@ -110,21 +110,21 @@ void WebDataListSuggestionsDropdownMac::show(WebCore::DataListSuggestionInformat
 
 void WebDataListSuggestionsDropdownMac::didSelectOption(const String& selectedOption)
 {
-    if (!m_client)
+    if (!m_page)
         return;
 
-    m_client->didSelectOption(selectedOption);
+    m_page->didSelectOption(selectedOption);
     close();
 }
 
 void WebDataListSuggestionsDropdownMac::selectOption()
 {
-    if (!m_client)
+    if (!m_page)
         return;
 
     String selectedOption = [m_dropdownUI currentSelectedString];
     if (!selectedOption.isNull())
-        m_client->didSelectOption(selectedOption);
+        m_page->didSelectOption(selectedOption);
 
     close();
 }