Title: [237307] trunk/Source/WebKit
Revision
237307
Author
[email protected]
Date
2018-10-19 16:15:27 -0700 (Fri, 19 Oct 2018)

Log Message

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

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (237306 => 237307)


--- trunk/Source/WebKit/ChangeLog	2018-10-19 22:19:12 UTC (rev 237306)
+++ trunk/Source/WebKit/ChangeLog	2018-10-19 23:15:27 UTC (rev 237307)
@@ -1,3 +1,32 @@
+2018-10-19  Alex Christensen  <[email protected]>
+
+        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  <[email protected]>
 
         [iOS] [Datalist] Can't pick datalist suggestions in a stock WKWebView

Modified: trunk/Source/WebKit/UIProcess/WebDataListSuggestionsDropdown.cpp (237306 => 237307)


--- trunk/Source/WebKit/UIProcess/WebDataListSuggestionsDropdown.cpp	2018-10-19 22:19:12 UTC (rev 237306)
+++ trunk/Source/WebKit/UIProcess/WebDataListSuggestionsDropdown.cpp	2018-10-19 23:15:27 UTC (rev 237307)
@@ -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 @@
 
 void WebDataListSuggestionsDropdown::close()
 {
-    m_client->didCloseSuggestions();
-    m_client = nullptr;
+    if (auto page = std::exchange(m_page, nullptr))
+        page->didCloseSuggestions();
 }
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/UIProcess/WebDataListSuggestionsDropdown.h (237306 => 237307)


--- trunk/Source/WebKit/UIProcess/WebDataListSuggestionsDropdown.h	2018-10-19 22:19:12 UTC (rev 237306)
+++ trunk/Source/WebKit/UIProcess/WebDataListSuggestionsDropdown.h	2018-10-19 23:15:27 UTC (rev 237307)
@@ -30,20 +30,14 @@
 #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 @@
     virtual void close();
 
 protected:
-    explicit WebDataListSuggestionsDropdown(Client&);
+    explicit WebDataListSuggestionsDropdown(WebPageProxy&);
 
-    Client* m_client;
+    WeakPtr<WebPageProxy> m_page;
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (237306 => 237307)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2018-10-19 22:19:12 UTC (rev 237306)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2018-10-19 23:15:27 UTC (rev 237307)
@@ -333,9 +333,6 @@
 #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 @@
     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 @@
     void showDataListSuggestions(WebCore::DataListSuggestionInformation&&);
     void handleKeydownInDataList(const String&);
     void endDataListSuggestions();
-    void didSelectOption(const String&) final;
-    void didCloseSuggestions() final;
 #endif
 
     void closeOverlayedViews();

Modified: trunk/Source/WebKit/UIProcess/ios/WebDataListSuggestionsDropdownIOS.h (237306 => 237307)


--- trunk/Source/WebKit/UIProcess/ios/WebDataListSuggestionsDropdownIOS.h	2018-10-19 22:19:12 UTC (rev 237306)
+++ trunk/Source/WebKit/UIProcess/ios/WebDataListSuggestionsDropdownIOS.h	2018-10-19 23:15:27 UTC (rev 237307)
@@ -42,12 +42,12 @@
 
 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;

Modified: trunk/Source/WebKit/UIProcess/ios/WebDataListSuggestionsDropdownIOS.mm (237306 => 237307)


--- trunk/Source/WebKit/UIProcess/ios/WebDataListSuggestionsDropdownIOS.mm	2018-10-19 22:19:12 UTC (rev 237306)
+++ trunk/Source/WebKit/UIProcess/ios/WebDataListSuggestionsDropdownIOS.mm	2018-10-19 23:15:27 UTC (rev 237307)
@@ -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 @@
 
 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 @@
 {
     [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();
 }
 

Modified: trunk/Source/WebKit/UIProcess/mac/WebDataListSuggestionsDropdownMac.h (237306 => 237307)


--- trunk/Source/WebKit/UIProcess/mac/WebDataListSuggestionsDropdownMac.h	2018-10-19 22:19:12 UTC (rev 237306)
+++ trunk/Source/WebKit/UIProcess/mac/WebDataListSuggestionsDropdownMac.h	2018-10-19 23:15:27 UTC (rev 237307)
@@ -36,13 +36,13 @@
 
 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;

Modified: trunk/Source/WebKit/UIProcess/mac/WebDataListSuggestionsDropdownMac.mm (237306 => 237307)


--- trunk/Source/WebKit/UIProcess/mac/WebDataListSuggestionsDropdownMac.mm	2018-10-19 22:19:12 UTC (rev 237306)
+++ trunk/Source/WebKit/UIProcess/mac/WebDataListSuggestionsDropdownMac.mm	2018-10-19 23:15:27 UTC (rev 237307)
@@ -84,15 +84,15 @@
 
 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::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();
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to