Changeset 179745 in webkit
- Timestamp:
- Feb 6, 2015 6:50:20 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r179744 r179745 1 2015-02-06 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 [GTK] Remove WebKitWebView::close-notification signal 4 https://bugs.webkit.org/show_bug.cgi?id=141330 5 6 Reviewed by Gustavo Noronha Silva. 7 8 In favor of a WebKitNotification::closed signal and 9 webkit_notification_close() method that both applications and 10 WebKit can use to close a notification. This also fixes the 11 onclose event that was not fired when the notification was 12 closed. It also brings back padding space in WebKitWebViewClass. 13 14 * UIProcess/API/gtk/WebKitNotification.cpp: 15 (webkit_notification_class_init): Add WebKitNotification::closed signal. 16 (webkit_notification_close): Emit WebKitNotification::closed. 17 * UIProcess/API/gtk/WebKitNotification.h: 18 * UIProcess/API/gtk/WebKitNotificationProvider.cpp: 19 (WebKitNotificationProvider::notificationCloseCallback): Callback 20 for WebKitNotification::closed signal that notifies the WebProcess 21 and removes the notification from the map. 22 (WebKitNotificationProvider::show): Connect to WebKitNotification::closed. 23 (WebKitNotificationProvider::cancelNotificationByID): Call webkit_notification_close(). 24 * UIProcess/API/gtk/WebKitNotificationProvider.h: 25 * UIProcess/API/gtk/WebKitWebView.cpp: 26 (notifyNotificationClosed): The user closed the annotation, call 27 webkit_notification_close(). 28 (webNotificationClosed): The WebKitNotification has been closed, 29 close the libnotify notification if it hasn't been closed yet. 30 (webkitWebViewShowNotification): Create the libnotifiy 31 notification if needed and associate it to the WebKitNotification 32 as user data. Connect to the closed signal of both, the libnotifiy 33 notification and the WebKit notification. 34 (webkitWebViewCloseNotification): Deleted. 35 (webkit_web_view_class_init): Remove close-notification signal and 36 the default hanlder. 37 (webkitWebViewEmitCloseNotification): Deleted. 38 * UIProcess/API/gtk/WebKitWebView.h: 39 * UIProcess/API/gtk/WebKitWebViewPrivate.h: 40 * UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt: Add webkit_notification_close. 41 1 42 2015-02-06 Carlos Garcia Campos <cgarcia@igalia.com> 2 43 -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotification.cpp
r177073 r179745 43 43 }; 44 44 45 enum { 46 CLOSED, 47 48 LAST_SIGNAL 49 }; 50 45 51 struct _WebKitNotificationPrivate { 46 52 CString title; … … 50 56 WebKitWebView* webView; 51 57 }; 58 59 static guint signals[LAST_SIGNAL] = { 0, }; 52 60 53 61 WEBKIT_DEFINE_TYPE(WebKitNotification, webkit_notification, G_TYPE_OBJECT) … … 121 129 nullptr, 122 130 WEBKIT_PARAM_READABLE)); 131 132 /** 133 * WebKitNotification::closed: 134 * @notification: the #WebKitNotification on which the signal is emitted 135 * 136 * Emitted when a notification has been withdrawn. 137 * 138 * The default handler will close the notification using libnotify, if built with 139 * support for it. 140 * 141 * Since: 2.8 142 */ 143 signals[CLOSED] = 144 g_signal_new( 145 "closed", 146 G_TYPE_FROM_CLASS(notificationClass), 147 G_SIGNAL_RUN_LAST, 148 0, 0, 149 nullptr, 150 g_cclosure_marshal_VOID__VOID, 151 G_TYPE_NONE, 0); 123 152 } 124 153 … … 188 217 return notification->priv->body.data(); 189 218 } 219 220 /** 221 * webkit_notification_close: 222 * @notification: a #WebKitNotification 223 * 224 * Closes the notification. 225 * 226 * Since: 2.8 227 */ 228 void webkit_notification_close(WebKitNotification* notification) 229 { 230 g_return_if_fail(WEBKIT_IS_NOTIFICATION(notification)); 231 232 g_signal_emit(notification, signals[CLOSED], 0); 233 } -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotification.h
r177073 r179745 71 71 webkit_notification_get_body (WebKitNotification *notification); 72 72 73 WEBKIT_API void 74 webkit_notification_close (WebKitNotification* notification); 75 73 76 G_END_DECLS 74 77 -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.cpp
r177073 r179745 87 87 } 88 88 89 void WebKitNotificationProvider::notificationCloseCallback(WebKitNotification* notification, WebKitNotificationProvider* provider) 90 { 91 uint64_t notificationID = webkit_notification_get_id(notification); 92 Vector<RefPtr<API::Object>, 1> arrayIDs; 93 arrayIDs.uncheckedAppend(API::UInt64::create(notificationID)); 94 provider->m_notificationManager->providerDidCloseNotifications(API::Array::create(WTF::move(arrayIDs)).get()); 95 provider->m_notifications.remove(notificationID); 96 } 97 89 98 void WebKitNotificationProvider::show(WebPageProxy* page, const WebNotification& webNotification) 90 99 { … … 93 102 if (!notification) { 94 103 notification = adoptGRef(webkitNotificationCreate(WEBKIT_WEB_VIEW(page->viewWidget()), webNotification)); 104 g_signal_connect(notification.get(), "closed", G_CALLBACK(notificationCloseCallback), this); 95 105 m_notifications.set(webNotification.notificationID(), notification); 96 106 } … … 103 113 { 104 114 if (GRefPtr<WebKitNotification> notification = m_notifications.get(notificationID)) 105 webkitWebViewEmitCloseNotification(webkitNotificationGetWebView(notification.get()), notification.get()); 106 107 m_notifications.remove(notificationID); 115 webkit_notification_close(notification.get()); 108 116 } 109 117 -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.h
r177073 r179745 46 46 47 47 void cancelNotificationByID(uint64_t); 48 static void notificationCloseCallback(WebKitNotification*, WebKitNotificationProvider*); 48 49 49 50 RefPtr<WebNotificationManagerProxy> m_notificationManager; -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp
r178892 r179745 132 132 133 133 SHOW_NOTIFICATION, 134 CLOSE_NOTIFICATION,135 134 136 135 LAST_SIGNAL … … 156 155 typedef HashMap<uint64_t, GRefPtr<WebKitWebResource> > LoadingResourcesMap; 157 156 typedef HashMap<uint64_t, GRefPtr<GTask> > SnapshotResultsMap; 158 #if USE(LIBNOTIFY) 159 typedef HashMap<uint64_t, GRefPtr<NotifyNotification>> NotifyNotificationsMap; 160 #endif 157 161 158 class PageLoadStateObserver; 162 159 … … 210 207 GRefPtr<WebKitAuthenticationRequest> authenticationRequest; 211 208 212 #if USE(LIBNOTIFY)213 NotifyNotificationsMap notifyNotificationsMap;214 #endif215 209 }; 216 210 … … 584 578 } 585 579 586 static gboolean webkitWebViewShowNotification(WebKitWebView* webView, WebKitNotification* webNotification) 580 #if USE(LIBNOTIFY) 581 static const char* gNotifyNotificationID = "wk-notify-notification"; 582 583 static void notifyNotificationClosed(NotifyNotification*, WebKitNotification* webNotification) 584 { 585 g_object_set_data(G_OBJECT(webNotification), gNotifyNotificationID, nullptr); 586 webkit_notification_close(webNotification); 587 } 588 589 static void webNotificationClosed(WebKitNotification* webNotification) 590 { 591 NotifyNotification* notification = NOTIFY_NOTIFICATION(g_object_get_data(G_OBJECT(webNotification), gNotifyNotificationID)); 592 if (!notification) 593 return; 594 595 notify_notification_close(notification, nullptr); 596 g_object_set_data(G_OBJECT(webNotification), gNotifyNotificationID, nullptr); 597 } 598 #endif // USE(LIBNOTIFY) 599 600 static gboolean webkitWebViewShowNotification(WebKitWebView*, WebKitNotification* webNotification) 587 601 { 588 602 #if USE(LIBNOTIFY) … … 590 604 notify_init(g_get_prgname()); 591 605 592 GRefPtr<NotifyNotification> notification = webView->priv->notifyNotificationsMap.get(webkit_notification_get_id(webNotification));606 NotifyNotification* notification = NOTIFY_NOTIFICATION(g_object_get_data(G_OBJECT(webNotification), gNotifyNotificationID)); 593 607 if (!notification) { 594 notification = adoptGRef(notify_notification_new(webkit_notification_get_title(webNotification), 595 webkit_notification_get_body(webNotification), nullptr)); 596 597 webView->priv->notifyNotificationsMap.set(webkit_notification_get_id(webNotification), notification); 598 } else 599 notify_notification_update(notification.get(), webkit_notification_get_title(webNotification), 608 notification = notify_notification_new(webkit_notification_get_title(webNotification), 600 609 webkit_notification_get_body(webNotification), nullptr); 601 610 602 notify_notification_show(notification.get(), nullptr); 611 g_signal_connect_object(notification, "closed", G_CALLBACK(notifyNotificationClosed), webNotification, static_cast<GConnectFlags>(0)); 612 g_signal_connect(webNotification, "closed", G_CALLBACK(webNotificationClosed), nullptr); 613 g_object_set_data_full(G_OBJECT(webNotification), gNotifyNotificationID, notification, static_cast<GDestroyNotify>(g_object_unref)); 614 } else { 615 notify_notification_update(notification, webkit_notification_get_title(webNotification), 616 webkit_notification_get_body(webNotification), nullptr); 617 } 618 619 notify_notification_show(notification, nullptr); 603 620 return TRUE; 604 621 #else 605 UNUSED_PARAM(webView);606 UNUSED_PARAM(webNotification);607 return FALSE;608 #endif609 }610 611 static gboolean webkitWebViewCloseNotification(WebKitWebView* webView, WebKitNotification* webNotification)612 {613 #if USE(LIBNOTIFY)614 if (GRefPtr<NotifyNotification> notification = webView->priv->notifyNotificationsMap.get(webkit_notification_get_id(webNotification))) {615 notify_notification_close(notification.get(), nullptr);616 webView->priv->notifyNotificationsMap.remove(webkit_notification_get_id(webNotification));617 }618 return TRUE;619 #else620 UNUSED_PARAM(webView);621 622 UNUSED_PARAM(webNotification); 622 623 return FALSE; … … 785 786 webViewClass->authenticate = webkitWebViewAuthenticate; 786 787 webViewClass->show_notification = webkitWebViewShowNotification; 787 webViewClass->close_notification = webkitWebViewCloseNotification;788 788 789 789 /** … … 1715 1715 G_TYPE_BOOLEAN, 1, 1716 1716 WEBKIT_TYPE_NOTIFICATION); 1717 1718 /**1719 * WebKitNotification::close-notification:1720 * @web_view: the #WebKitWebView1721 * @notification: a #WebKitNofication1722 *1723 * This signal is emitted when a notification should be withdrawn.1724 *1725 * The default handler will close the notification using libnotify, if built with1726 * support for it.1727 *1728 * Returns: %TRUE to stop other handlers from being invoked. %FALSE otherwise.1729 *1730 * Since: 2.81731 */1732 signals[CLOSE_NOTIFICATION] =1733 g_signal_new("close-notification",1734 G_TYPE_FROM_CLASS(gObjectClass),1735 G_SIGNAL_RUN_LAST,1736 G_STRUCT_OFFSET(WebKitWebViewClass, close_notification),1737 g_signal_accumulator_true_handled, nullptr /* accumulator data */,1738 webkit_marshal_BOOLEAN__OBJECT,1739 G_TYPE_BOOLEAN, 1,1740 WEBKIT_TYPE_NOTIFICATION);1741 1717 } 1742 1718 … … 2114 2090 g_signal_emit(webView, signals[SHOW_NOTIFICATION], 0, webNotification, &handled); 2115 2091 return handled; 2116 }2117 2118 void webkitWebViewEmitCloseNotification(WebKitWebView* webView, WebKitNotification* webNotification)2119 {2120 gboolean handled;2121 g_signal_emit(webView, signals[CLOSE_NOTIFICATION], 0, webNotification, &handled);2122 2092 } 2123 2093 -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h
r178703 r179745 245 245 gboolean (* show_notification) (WebKitWebView *web_view, 246 246 WebKitNotification *notification); 247 gboolean (* close_notification) (WebKitWebView *web_view,248 WebKitNotification *notification);249 247 250 248 void (*_webkit_reserved0) (void); … … 252 250 void (*_webkit_reserved2) (void); 253 251 void (*_webkit_reserved3) (void); 252 void (*_webkit_reserved4) (void); 254 253 }; 255 254 -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewPrivate.h
r178892 r179745 60 60 void webkitWebViewInsecureContentDetected(WebKitWebView*, WebKitInsecureContentEvent); 61 61 bool webkitWebViewEmitShowNotification(WebKitWebView*, WebKitNotification*); 62 void webkitWebViewEmitCloseNotification(WebKitWebView*, WebKitNotification*);63 62 void webkitWebViewWebProcessCrashed(WebKitWebView*); 64 63 void webkitWebViewIsPlayingAudioChanged(WebKitWebView*); -
trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt
r179111 r179745 627 627 webkit_notification_get_title 628 628 webkit_notification_get_body 629 webkit_notification_close 629 630 630 631 <SUBSECTION Standard> -
trunk/Tools/ChangeLog
r179721 r179745 1 2015-02-06 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 [GTK] Remove WebKitWebView::close-notification signal 4 https://bugs.webkit.org/show_bug.cgi?id=141330 5 6 Reviewed by Gustavo Noronha Silva. 7 8 Update notifications unit tests according to the API changes, and 9 add a test case to check that onclose event is fired when a 10 notification is closed by the user. 11 12 * TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp: 13 (testWebViewNotification): 14 1 15 2015-02-05 Alexey Proskuryakov <ap@apple.com> 2 16 -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp
r179248 r179745 603 603 Permission, 604 604 Shown, 605 Cancelled 605 Closed, 606 OnClosed, 606 607 }; 607 608 … … 620 621 } 621 622 623 static gboolean notificationClosedCallback(WebKitNotification* notification, NotificationWebViewTest* test) 624 { 625 g_assert(test->m_notification == notification); 626 test->m_notification = nullptr; 627 test->m_event = Closed; 628 if (g_main_loop_is_running(test->m_mainLoop)) 629 g_main_loop_quit(test->m_mainLoop); 630 return TRUE; 631 } 632 622 633 static gboolean showNotificationCallback(WebKitWebView*, WebKitNotification* notification, NotificationWebViewTest* test) 623 634 { 624 635 test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(notification)); 625 636 test->m_notification = notification; 637 g_signal_connect(notification, "closed", G_CALLBACK(notificationClosedCallback), test); 626 638 test->m_event = Shown; 627 639 g_main_loop_quit(test->m_mainLoop); … … 629 641 } 630 642 631 static gboolean closeNotificationCallback(WebKitWebView*, WebKitNotification*, NotificationWebViewTest* test) 632 { 633 test->m_notification = nullptr; 634 test->m_event = Cancelled; 643 static void notificationsMessageReceivedCallback(WebKitUserContentManager* userContentManager, WebKitJavascriptResult*, NotificationWebViewTest* test) 644 { 645 test->m_event = OnClosed; 635 646 g_main_loop_quit(test->m_mainLoop); 636 return TRUE;637 647 } 638 648 639 649 NotificationWebViewTest() 640 : m_event(None) 650 : WebViewTest(webkit_user_content_manager_new()) 651 , m_notification(nullptr) 652 , m_event(None) 641 653 { 642 654 g_signal_connect(m_webView, "permission-request", G_CALLBACK(permissionRequestCallback), this); 643 655 g_signal_connect(m_webView, "show-notification", G_CALLBACK(showNotificationCallback), this); 644 g_signal_connect(m_webView, "close-notification", G_CALLBACK(closeNotificationCallback), this); 645 656 WebKitUserContentManager* manager = webkit_web_view_get_user_content_manager(m_webView); 657 webkit_user_content_manager_register_script_message_handler(manager, "notifications"); 658 g_signal_connect(manager, "script-message-received::notifications", G_CALLBACK(notificationsMessageReceivedCallback), this); 646 659 } 647 660 … … 649 662 { 650 663 g_signal_handlers_disconnect_matched(m_webView, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this); 664 WebKitUserContentManager* manager = webkit_web_view_get_user_content_manager(m_webView); 665 g_signal_handlers_disconnect_matched(manager, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this); 666 webkit_user_content_manager_unregister_script_message_handler(manager, "notifications"); 651 667 } 652 668 … … 668 684 } 669 685 670 void closeNotificationAndWaitUntilC ancelled()686 void closeNotificationAndWaitUntilClosed() 671 687 { 672 688 m_event = None; 673 689 webkit_web_view_run_javascript(m_webView, "n.close()", nullptr, nullptr, nullptr); 690 g_main_loop_run(m_mainLoop); 691 } 692 693 void closeNotificationAndWaitUntilOnClosed() 694 { 695 g_assert(m_notification); 696 m_event = None; 697 runJavaScriptAndWaitUntilFinished("n.onclose = function() { window.webkit.messageHandlers.notifications.postMessage('closed'); }", nullptr); 698 webkit_notification_close(m_notification); 699 g_assert(m_event == Closed); 674 700 g_main_loop_run(m_mainLoop); 675 701 } … … 686 712 687 713 test->requestPermissionAndWaitUntilGiven(); 688 689 714 g_assert(test->m_event == NotificationWebViewTest::Permission); 690 715 … … 698 723 g_assert_cmpstr(webkit_notification_get_body(test->m_notification), ==, body); 699 724 700 test->closeNotificationAndWaitUntilCancelled(); 701 702 g_assert(test->m_event == NotificationWebViewTest::Cancelled); 725 test->closeNotificationAndWaitUntilClosed(); 726 g_assert(test->m_event == NotificationWebViewTest::Closed); 703 727 704 728 test->requestNotificationAndWaitUntilShown(title, body); 705 729 g_assert(test->m_event == NotificationWebViewTest::Shown); 730 731 test->closeNotificationAndWaitUntilOnClosed(); 732 g_assert(test->m_event == NotificationWebViewTest::OnClosed); 733 734 test->requestNotificationAndWaitUntilShown(title, body); 706 735 g_assert(test->m_event == NotificationWebViewTest::Shown); 707 736 708 737 test->loadURI(gServer->getURIForPath("/").data()); 709 738 test->waitUntilLoadFinished(); 710 711 g_assert(test->m_event == NotificationWebViewTest::Cancelled); 739 g_assert(test->m_event == NotificationWebViewTest::Closed); 712 740 } 713 741
Note: See TracChangeset
for help on using the changeset viewer.