Title: [127258] trunk/Source
Revision
127258
Author
[email protected]
Date
2012-08-31 07:35:14 -0700 (Fri, 31 Aug 2012)

Log Message

[EFL] Add proper support for navigator.onLine and associated events
https://bugs.webkit.org/show_bug.cgi?id=95532

Patch by Christophe Dumez <[email protected]> on 2012-08-31
Reviewed by Kenneth Rohde Christiansen.

Source/WebCore:

Add support for detecting online state in EFL port and
monitor state changes. The EFL port now has proper
support for navigator.onLine and associated events.

The implementation is based on Eeze library for
detecting network interfaces and their configuration.
Detection of online state changes relies on rtnetlink.

No new tests, no behavior change for layout tests.

* PlatformEfl.cmake: Link unconditionally against Eeze
library now.
* platform/network/NetworkStateNotifier.cpp:
(WebCore):
* platform/network/NetworkStateNotifier.h:
(NetworkStateNotifier):
(WebCore):
* platform/network/efl/NetworkStateNotifierEfl.cpp: Added.
(WebCore):
(WebCore::NetworkStateNotifier::updateState):
(WebCore::NetworkStateNotifier::networkInterfaceChanged):
(WebCore::readSocketCallback):
(WebCore::NetworkStateNotifier::~NetworkStateNotifier):
(WebCore::NetworkStateNotifier::NetworkStateNotifier):

Source/WebKit/efl:

Remove ewk_network_state_notifier_online_set() API since
the EFL port no longer relies on the client application to
provide it with the online state.

* ewk/ewk_network.cpp:
* ewk/ewk_network.h:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (127257 => 127258)


--- trunk/Source/WebCore/ChangeLog	2012-08-31 14:29:35 UTC (rev 127257)
+++ trunk/Source/WebCore/ChangeLog	2012-08-31 14:35:14 UTC (rev 127258)
@@ -1,3 +1,35 @@
+2012-08-31  Christophe Dumez  <[email protected]>
+
+        [EFL] Add proper support for navigator.onLine and associated events
+        https://bugs.webkit.org/show_bug.cgi?id=95532
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Add support for detecting online state in EFL port and
+        monitor state changes. The EFL port now has proper
+        support for navigator.onLine and associated events.
+
+        The implementation is based on Eeze library for
+        detecting network interfaces and their configuration.
+        Detection of online state changes relies on rtnetlink.
+
+        No new tests, no behavior change for layout tests.
+
+        * PlatformEfl.cmake: Link unconditionally against Eeze
+        library now.
+        * platform/network/NetworkStateNotifier.cpp:
+        (WebCore):
+        * platform/network/NetworkStateNotifier.h:
+        (NetworkStateNotifier):
+        (WebCore):
+        * platform/network/efl/NetworkStateNotifierEfl.cpp: Added.
+        (WebCore):
+        (WebCore::NetworkStateNotifier::updateState):
+        (WebCore::NetworkStateNotifier::networkInterfaceChanged):
+        (WebCore::readSocketCallback):
+        (WebCore::NetworkStateNotifier::~NetworkStateNotifier):
+        (WebCore::NetworkStateNotifier::NetworkStateNotifier):
+
 2012-08-31  Milian Wolff  <[email protected]>
 
         [Qt] QNX build fails due to missing OpenGL ES defines

Modified: trunk/Source/WebCore/PlatformEfl.cmake (127257 => 127258)


--- trunk/Source/WebCore/PlatformEfl.cmake	2012-08-31 14:29:35 UTC (rev 127257)
+++ trunk/Source/WebCore/PlatformEfl.cmake	2012-08-31 14:35:14 UTC (rev 127258)
@@ -72,6 +72,7 @@
   platform/image-decoders/webp/WEBPImageDecoder.cpp
   platform/linux/GamepadDeviceLinux.cpp
   platform/mediastream/gstreamer/MediaStreamCenterGStreamer.cpp
+  platform/network/efl/NetworkStateNotifierEfl.cpp
   platform/network/soup/CookieJarSoup.cpp
   platform/network/soup/CookieStorageSoup.cpp
   platform/network/soup/CredentialStorageSoup.cpp
@@ -194,6 +195,7 @@
 LIST(APPEND WebCore_LIBRARIES
   ${CAIRO_LIBRARIES}
   ${ECORE_X_LIBRARIES}
+  ${EEZE_LIBRARIES}
   ${EFLDEPS_LIBRARIES}
   ${EVAS_LIBRARIES}
   ${FONTCONFIG_LIBRARIES}
@@ -214,6 +216,7 @@
 LIST(APPEND WebCore_INCLUDE_DIRECTORIES
   ${CAIRO_INCLUDE_DIRS}
   ${ECORE_X_INCLUDE_DIRS}
+  ${EEZE_INCLUDE_DIRS}
   ${EFLDEPS_INCLUDE_DIRS}
   ${EVAS_INCLUDE_DIRS}
   ${FREETYPE_INCLUDE_DIRS}
@@ -321,12 +324,3 @@
   ADD_DEFINITIONS(-DUNINSTALLED_AUDIO_RESOURCES_DIR="${WEBCORE_DIR}/platform/audio/resources")
 ENDIF ()
 
-IF (ENABLE_GAMEPAD OR ENABLE_NETWORK_INFO)
-  LIST(APPEND WebCore_INCLUDE_DIRECTORIES
-    ${EEZE_INCLUDE_DIRS}
-  )
-  LIST(APPEND WebCore_LIBRARIES
-    ${EEZE_LIBRARIES}
-  )
-ENDIF ()
-

Modified: trunk/Source/WebCore/platform/network/NetworkStateNotifier.cpp (127257 => 127258)


--- trunk/Source/WebCore/platform/network/NetworkStateNotifier.cpp	2012-08-31 14:29:35 UTC (rev 127257)
+++ trunk/Source/WebCore/platform/network/NetworkStateNotifier.cpp	2012-08-31 14:35:14 UTC (rev 127258)
@@ -46,7 +46,7 @@
     m_networkStateChangedFunction = function;
 }
 
-#if PLATFORM(CHROMIUM) || PLATFORM(EFL)
+#if PLATFORM(CHROMIUM)
 void NetworkStateNotifier::setOnLine(bool onLine)
 {
     if (m_isOnLine == onLine)

Modified: trunk/Source/WebCore/platform/network/NetworkStateNotifier.h (127257 => 127258)


--- trunk/Source/WebCore/platform/network/NetworkStateNotifier.h	2012-08-31 14:29:35 UTC (rev 127257)
+++ trunk/Source/WebCore/platform/network/NetworkStateNotifier.h	2012-08-31 14:35:14 UTC (rev 127258)
@@ -45,6 +45,10 @@
 
 #include <QtCore/qglobal.h>
 
+#elif PLATFORM(EFL)
+
+typedef struct _Ecore_Fd_Handler Ecore_Fd_Handler;
+
 #endif
 
 namespace WebCore {
@@ -57,14 +61,19 @@
     WTF_MAKE_NONCOPYABLE(NetworkStateNotifier); WTF_MAKE_FAST_ALLOCATED;
 public:
     NetworkStateNotifier();
+#if PLATFORM(EFL)
+    ~NetworkStateNotifier();
+#endif
     void setNetworkStateChangedFunction(void (*)());
 
     bool onLine() const { return m_isOnLine; }
 
 #if (PLATFORM(QT) && !defined(QT_NO_BEARERMANAGEMENT))
     void setNetworkAccessAllowed(bool);
-#elif PLATFORM(CHROMIUM) || PLATFORM(EFL)
+#elif PLATFORM(CHROMIUM)
     void setOnLine(bool);
+#elif PLATFORM(EFL)
+    void networkInterfaceChanged();
 #endif
 
 #if PLATFORM(BLACKBERRY)
@@ -94,13 +103,16 @@
     HANDLE m_waitHandle;
     OVERLAPPED m_overlapped;
 
+#elif PLATFORM(EFL)
+    Ecore_Fd_Handler* m_fdHandler;
+
 #elif (PLATFORM(QT) && !defined(QT_NO_BEARERMANAGEMENT))
     friend class NetworkStateNotifierPrivate;
     NetworkStateNotifierPrivate* p;
 #endif
 };
 
-#if !PLATFORM(MAC) && !PLATFORM(WIN) && !(PLATFORM(QT) && !defined(QT_NO_BEARERMANAGEMENT)) && !PLATFORM(BLACKBERRY)
+#if !PLATFORM(MAC) && !PLATFORM(WIN) && !(PLATFORM(QT) && !defined(QT_NO_BEARERMANAGEMENT)) && !PLATFORM(BLACKBERRY) && !PLATFORM(EFL)
 
 inline NetworkStateNotifier::NetworkStateNotifier()
     : m_isOnLine(true)

Added: trunk/Source/WebCore/platform/network/efl/NetworkStateNotifierEfl.cpp (0 => 127258)


--- trunk/Source/WebCore/platform/network/efl/NetworkStateNotifierEfl.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/network/efl/NetworkStateNotifierEfl.cpp	2012-08-31 14:35:14 UTC (rev 127258)
@@ -0,0 +1,155 @@
+/*
+ * Copyright (C) 2012 Intel Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "NetworkStateNotifier.h"
+
+#include "Logging.h"
+#include <Ecore.h>
+#include <Eeze.h>
+#include <Eeze_Net.h>
+#include <asm/types.h>
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
+static const char udevLoopBackInterfaceSysPath[] = "lo";
+static const char udevOperstateAttribute[] = "operstate";
+static const char udevOperstateUp[] = "up";
+static const size_t bufferSize = 4096;
+
+namespace WebCore {
+
+void NetworkStateNotifier::updateState()
+{
+    // Assume that we're offline until proven otherwise.
+    m_isOnLine = false;
+
+    Eina_List* networkInterfaces = eeze_net_list();
+
+    Eina_List* list;
+    void* data;
+    EINA_LIST_FOREACH(networkInterfaces, list, data) {
+        Eeze_Net* networkInterface = static_cast<Eeze_Net*>(data);
+
+        // Skip Loopback interface.
+        const char* syspath = eeze_net_syspath_get(networkInterface);
+        if (!syspath || !strcmp(syspath, udevLoopBackInterfaceSysPath))
+            continue;
+
+        // Skip interfaces that are not up.
+        const char* state = eeze_net_attribute_get(networkInterface, udevOperstateAttribute);
+        if (!state || strcmp(state, udevOperstateUp))
+            continue;
+
+        // Check if the interface has an IP address.
+        eeze_net_scan(networkInterface);
+        if (eeze_net_addr_get(networkInterface, EEZE_NET_ADDR_TYPE_IP) || eeze_net_addr_get(networkInterface, EEZE_NET_ADDR_TYPE_IP6)) {
+            m_isOnLine = true;
+            break;
+        }
+    }
+
+    EINA_LIST_FREE(networkInterfaces, data)
+        eeze_net_free(static_cast<Eeze_Net*>(data));
+}
+
+void NetworkStateNotifier::networkInterfaceChanged()
+{
+    bool wasOnline = m_isOnLine;
+    updateState();
+
+    if (wasOnline != m_isOnLine && m_networkStateChangedFunction)
+        m_networkStateChangedFunction();
+}
+
+static Eina_Bool readSocketCallback(void* userData, Ecore_Fd_Handler* handler)
+{
+    int sock = ecore_main_fd_handler_fd_get(handler);
+    char buffer[bufferSize];
+    ssize_t len;
+    nlmsghdr* nlh = reinterpret_cast<nlmsghdr*>(buffer);
+    while ((len = recv(sock, nlh, bufferSize, MSG_DONTWAIT)) > 0) {
+        while ((NLMSG_OK(nlh, len)) && (nlh->nlmsg_type != NLMSG_DONE)) {
+            if (nlh->nlmsg_type == NLMSG_ERROR) {
+                LOG_ERROR("Error while reading socket, stop monitoring onLine state.");
+                return ECORE_CALLBACK_CANCEL;
+            }
+            if (nlh->nlmsg_type == RTM_NEWADDR || nlh->nlmsg_type == RTM_DELADDR) {
+                // We detected an IP address change, recheck onLine state.
+                static_cast<NetworkStateNotifier*>(userData)->networkInterfaceChanged();
+            }
+            nlh = NLMSG_NEXT(nlh, len);
+        }
+    }
+
+    return ECORE_CALLBACK_RENEW;
+}
+
+NetworkStateNotifier::~NetworkStateNotifier()
+{
+    if (m_fdHandler) {
+        int sock = ecore_main_fd_handler_fd_get(m_fdHandler);
+        ecore_main_fd_handler_del(m_fdHandler);
+        close(sock);
+    }
+    eeze_shutdown();
+}
+
+NetworkStateNotifier::NetworkStateNotifier()
+    : m_isOnLine(false)
+    , m_networkStateChangedFunction(0)
+    , m_fdHandler(0)
+{
+    if (eeze_init() < 0) {
+        LOG_ERROR("Failed to initialize eeze library.");
+        return;
+    }
+
+    updateState();
+
+    // Watch for network address changes to keep online state up-to-date.
+    int sock;
+    if ((sock = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) == -1) {
+        LOG_ERROR("Couldn't open NETLINK_ROUTE socket.");
+        return;
+    }
+
+    sockaddr_nl addr;
+    memset(&addr, 0, sizeof(addr));
+    addr.nl_family = AF_NETLINK;
+    addr.nl_groups = RTMGRP_IPV4_IFADDR | RTMGRP_IPV6_IFADDR;
+
+    if (bind(sock, reinterpret_cast<sockaddr*>(&addr), sizeof(addr)) == -1) {
+        LOG_ERROR("Couldn't bind to NETLINK_ROUTE socket.");
+        return;
+    }
+
+    m_fdHandler = ecore_main_fd_handler_add(sock, ECORE_FD_READ, readSocketCallback, this, 0, 0);
+}
+
+} // namespace WebCore

Modified: trunk/Source/WebKit/efl/ChangeLog (127257 => 127258)


--- trunk/Source/WebKit/efl/ChangeLog	2012-08-31 14:29:35 UTC (rev 127257)
+++ trunk/Source/WebKit/efl/ChangeLog	2012-08-31 14:35:14 UTC (rev 127258)
@@ -1,3 +1,17 @@
+2012-08-31  Christophe Dumez  <[email protected]>
+
+        [EFL] Add proper support for navigator.onLine and associated events
+        https://bugs.webkit.org/show_bug.cgi?id=95532
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Remove ewk_network_state_notifier_online_set() API since
+        the EFL port no longer relies on the client application to
+        provide it with the online state.
+
+        * ewk/ewk_network.cpp:
+        * ewk/ewk_network.h:
+
 2012-08-31  Jinwoo Song  <[email protected]>
 
         [EFL] Simplify FrameLoaderClinetEfl by adding a private method.

Modified: trunk/Source/WebKit/efl/ewk/ewk_network.cpp (127257 => 127258)


--- trunk/Source/WebKit/efl/ewk/ewk_network.cpp	2012-08-31 14:29:35 UTC (rev 127257)
+++ trunk/Source/WebKit/efl/ewk/ewk_network.cpp	2012-08-31 14:35:14 UTC (rev 127258)
@@ -62,11 +62,6 @@
     return eina_stringshare_add(proxy.utf8().data());
 }
 
-void ewk_network_state_notifier_online_set(Eina_Bool online)
-{
-    WebCore::networkStateNotifier().setOnLine(online);
-}
-
 Eina_Bool ewk_network_tls_certificate_check_get()
 {
     bool checkCertificates = false;

Modified: trunk/Source/WebKit/efl/ewk/ewk_network.h (127257 => 127258)


--- trunk/Source/WebKit/efl/ewk/ewk_network.h	2012-08-31 14:29:35 UTC (rev 127257)
+++ trunk/Source/WebKit/efl/ewk/ewk_network.h	2012-08-31 14:35:14 UTC (rev 127258)
@@ -59,13 +59,6 @@
 EAPI const char      *ewk_network_proxy_uri_get(void);
 
 /**
- * Sets if network backend is online or not.
- * 
- * @param online @c EINA_FALSE if network is disconnected
- */
-EAPI void             ewk_network_state_notifier_online_set(Eina_Bool online);
-
-/**
  * Returns whether HTTPS connections should check the received certificate and error out if it is invalid.
  *
  * By default, HTTPS connections are performed regardless of the validity of the certificate provided.
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to