Title: [149600] trunk/Source/WebKit2
Revision
149600
Author
zandober...@gmail.com
Date
2013-05-06 09:17:40 -0700 (Mon, 06 May 2013)

Log Message

[WK2] Make the WebBatteryManagerProxy a supplement to the WebContext
https://bugs.webkit.org/show_bug.cgi?id=115625

Reviewed by Andreas Kling.

Rather than holding a RefPtr to the WebBatteryManagerProxy object in WebContext, change the WebBatteryManagerProxy
to implement the WebContextSupplement interface and handle the object as such in WebContext, simplifying its
construction and cleanup, removing the specific RefPtr member variable and its correlating getter method.

* UIProcess/API/C/WKContext.cpp:
(WKContextGetBatteryManager): Retrieve the WebBatteryManagerProxy object from the supplements of the WebContext.
* UIProcess/WebBatteryManagerProxy.cpp:
(WebKit::WebBatteryManagerProxy::supplementName): Specify the supplement's name.
(WebKit::WebBatteryManagerProxy::WebBatteryManagerProxy): Initialize as a WebContextSupplementable.
(WebKit::WebBatteryManagerProxy::providerDidChangeBatteryStatus): Adjust to use the context() method instead of accessing
the private m_context directly.
(WebKit::WebBatteryManagerProxy::providerUpdateBatteryStatus): Ditto.
(WebKit::WebBatteryManagerProxy::contextDestroyed): Stop updating when invoked.
(WebKit::WebBatteryManagerProxy::processDidClose): Ditto.
(WebKit::WebBatteryManagerProxy::refWebContextSupplement): Call APIObject::ref.
(WebKit::WebBatteryManagerProxy::derefWebContextSupplement): Call APIObject::deref.
(WebKit::WebBatteryManagerProxy::startUpdating): Fire up the provider if not yet updating.
(WebKit::WebBatteryManagerProxy::stopUpdating): Wind down the provider if updating.
* UIProcess/WebBatteryManagerProxy.h:
(WebBatteryManagerProxy): Inherit from WebContextSupplement, declare the newly-inherited methods.
* UIProcess/WebContext.cpp:
(WebKit::WebContext::WebContext): Add the WebBatteryManagerProxy object as a supplement instead of assigning it to
the now-removed member variable.
(WebKit::WebContext::~WebContext): No need for the specific cleanup, the equivalent is achieved when iterating through the
supplements vector.
(WebKit::WebContext::disconnectProcess): Ditto.
* UIProcess/WebContext.h:
(WebContext): Remove the WebBatteryManagerProxy RefPtr member variable and its getter method.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (149599 => 149600)


--- trunk/Source/WebKit2/ChangeLog	2013-05-06 15:43:36 UTC (rev 149599)
+++ trunk/Source/WebKit2/ChangeLog	2013-05-06 16:17:40 UTC (rev 149600)
@@ -1,3 +1,39 @@
+2013-05-06  Zan Dobersek  <zdober...@igalia.com>
+
+        [WK2] Make the WebBatteryManagerProxy a supplement to the WebContext
+        https://bugs.webkit.org/show_bug.cgi?id=115625
+
+        Reviewed by Andreas Kling.
+
+        Rather than holding a RefPtr to the WebBatteryManagerProxy object in WebContext, change the WebBatteryManagerProxy
+        to implement the WebContextSupplement interface and handle the object as such in WebContext, simplifying its
+        construction and cleanup, removing the specific RefPtr member variable and its correlating getter method.
+
+        * UIProcess/API/C/WKContext.cpp:
+        (WKContextGetBatteryManager): Retrieve the WebBatteryManagerProxy object from the supplements of the WebContext.
+        * UIProcess/WebBatteryManagerProxy.cpp:
+        (WebKit::WebBatteryManagerProxy::supplementName): Specify the supplement's name.
+        (WebKit::WebBatteryManagerProxy::WebBatteryManagerProxy): Initialize as a WebContextSupplementable.
+        (WebKit::WebBatteryManagerProxy::providerDidChangeBatteryStatus): Adjust to use the context() method instead of accessing
+        the private m_context directly.
+        (WebKit::WebBatteryManagerProxy::providerUpdateBatteryStatus): Ditto.
+        (WebKit::WebBatteryManagerProxy::contextDestroyed): Stop updating when invoked.
+        (WebKit::WebBatteryManagerProxy::processDidClose): Ditto.
+        (WebKit::WebBatteryManagerProxy::refWebContextSupplement): Call APIObject::ref.
+        (WebKit::WebBatteryManagerProxy::derefWebContextSupplement): Call APIObject::deref.
+        (WebKit::WebBatteryManagerProxy::startUpdating): Fire up the provider if not yet updating.
+        (WebKit::WebBatteryManagerProxy::stopUpdating): Wind down the provider if updating.
+        * UIProcess/WebBatteryManagerProxy.h:
+        (WebBatteryManagerProxy): Inherit from WebContextSupplement, declare the newly-inherited methods.
+        * UIProcess/WebContext.cpp:
+        (WebKit::WebContext::WebContext): Add the WebBatteryManagerProxy object as a supplement instead of assigning it to
+        the now-removed member variable.
+        (WebKit::WebContext::~WebContext): No need for the specific cleanup, the equivalent is achieved when iterating through the
+        supplements vector.
+        (WebKit::WebContext::disconnectProcess): Ditto.
+        * UIProcess/WebContext.h:
+        (WebContext): Remove the WebBatteryManagerProxy RefPtr member variable and its getter method.
+
 2013-05-06  Antoine Quint  <grao...@apple.com>
 
         Manage the presentation of the snapshotted plug-in using _javascript_

Modified: trunk/Source/WebKit2/UIProcess/API/C/WKContext.cpp (149599 => 149600)


--- trunk/Source/WebKit2/UIProcess/API/C/WKContext.cpp	2013-05-06 15:43:36 UTC (rev 149599)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKContext.cpp	2013-05-06 16:17:40 UTC (rev 149600)
@@ -46,6 +46,9 @@
 #if ENABLE(SQL_DATABASE)
 #include "WebDatabaseManagerProxy.h"
 #endif
+#if ENABLE(BATTERY_STATUS)
+#include "WebBatteryManagerProxy.h"
+#endif
 
 using namespace WebKit;
 
@@ -206,7 +209,7 @@
 WKBatteryManagerRef WKContextGetBatteryManager(WKContextRef contextRef)
 {
 #if ENABLE(BATTERY_STATUS)
-    return toAPI(toImpl(contextRef)->batteryManagerProxy());
+    return toAPI(toImpl(contextRef)->supplement<WebBatteryManagerProxy>());
 #else
     return 0;
 #endif

Modified: trunk/Source/WebKit2/UIProcess/WebBatteryManagerProxy.cpp (149599 => 149600)


--- trunk/Source/WebKit2/UIProcess/WebBatteryManagerProxy.cpp	2013-05-06 15:43:36 UTC (rev 149599)
+++ trunk/Source/WebKit2/UIProcess/WebBatteryManagerProxy.cpp	2013-05-06 16:17:40 UTC (rev 149600)
@@ -34,32 +34,71 @@
 
 namespace WebKit {
 
+const char* WebBatteryManagerProxy::supplementName()
+{
+    return "WebBatteryManagerProxy";
+}
+
 PassRefPtr<WebBatteryManagerProxy> WebBatteryManagerProxy::create(WebContext* context)
 {
     return adoptRef(new WebBatteryManagerProxy(context));
 }
 
 WebBatteryManagerProxy::WebBatteryManagerProxy(WebContext* context)
-    : m_isUpdating(false)
-    , m_context(context)
+    : WebContextSupplement(context)
+    , m_isUpdating(false)
 {
-    m_context->addMessageReceiver(Messages::WebBatteryManagerProxy::messageReceiverName(), this);
+    WebContextSupplement::context()->addMessageReceiver(Messages::WebBatteryManagerProxy::messageReceiverName(), this);
 }
 
 WebBatteryManagerProxy::~WebBatteryManagerProxy()
 {
 }
 
-void WebBatteryManagerProxy::invalidate()
+void WebBatteryManagerProxy::initializeProvider(const WKBatteryProvider* provider)
 {
+    m_provider.initialize(provider);
+}
+
+
+void WebBatteryManagerProxy::providerDidChangeBatteryStatus(const WTF::AtomicString& eventType, WebBatteryStatus* status)
+{
+    if (!context())
+        return;
+
+    context()->sendToAllProcesses(Messages::WebBatteryManager::DidChangeBatteryStatus(eventType, status->data()));
+}
+
+void WebBatteryManagerProxy::providerUpdateBatteryStatus(WebBatteryStatus* status)
+{
+    if (!context())
+        return;
+
+    context()->sendToAllProcesses(Messages::WebBatteryManager::UpdateBatteryStatus(status->data()));
+}
+
+// WebContextSupplement
+
+void WebBatteryManagerProxy::contextDestroyed()
+{
     stopUpdating();
 }
 
-void WebBatteryManagerProxy::initializeProvider(const WKBatteryProvider* provider)
+void WebBatteryManagerProxy::processDidClose(WebProcessProxy*)
 {
-    m_provider.initialize(provider);
+    stopUpdating();
 }
 
+void WebBatteryManagerProxy::refWebContextSupplement()
+{
+    APIObject::ref();
+}
+
+void WebBatteryManagerProxy::derefWebContextSupplement()
+{
+    APIObject::deref();
+}
+
 void WebBatteryManagerProxy::startUpdating()
 {
     if (m_isUpdating)
@@ -78,22 +117,6 @@
     m_isUpdating = false;
 }
 
-void WebBatteryManagerProxy::providerDidChangeBatteryStatus(const WTF::AtomicString& eventType, WebBatteryStatus* status)
-{
-    if (!m_context)
-        return;
-
-    m_context->sendToAllProcesses(Messages::WebBatteryManager::DidChangeBatteryStatus(eventType, status->data()));
-}
-
-void WebBatteryManagerProxy::providerUpdateBatteryStatus(WebBatteryStatus* status)
-{
-    if (!m_context)
-        return;
-
-    m_context->sendToAllProcesses(Messages::WebBatteryManager::UpdateBatteryStatus(status->data()));
-}
-
 } // namespace WebKit
 
 #endif // ENABLE(BATTERY_STATUS)

Modified: trunk/Source/WebKit2/UIProcess/WebBatteryManagerProxy.h (149599 => 149600)


--- trunk/Source/WebKit2/UIProcess/WebBatteryManagerProxy.h	2013-05-06 15:43:36 UTC (rev 149599)
+++ trunk/Source/WebKit2/UIProcess/WebBatteryManagerProxy.h	2013-05-06 16:17:40 UTC (rev 149600)
@@ -31,29 +31,38 @@
 #include "APIObject.h"
 #include "MessageReceiver.h"
 #include "WebBatteryProvider.h"
+#include "WebContextSupplement.h"
 #include <wtf/Forward.h>
 
 namespace WebKit {
 
 class WebContext;
 class WebBatteryStatus;
-class WebBatteryManagerProxy : public TypedAPIObject<APIObject::TypeBatteryManager>, private CoreIPC::MessageReceiver {
 
+class WebBatteryManagerProxy : public TypedAPIObject<APIObject::TypeBatteryManager>, public WebContextSupplement, private CoreIPC::MessageReceiver {
 public:
+    static const char* supplementName();
+
     static PassRefPtr<WebBatteryManagerProxy> create(WebContext*);
     virtual ~WebBatteryManagerProxy();
 
-    void invalidate();
-    void clearContext() { m_context = 0; }
-
     void initializeProvider(const WKBatteryProvider*);
 
     void providerDidChangeBatteryStatus(const WTF::AtomicString&, WebBatteryStatus*);
     void providerUpdateBatteryStatus(WebBatteryStatus*);
 
+    using APIObject::ref;
+    using APIObject::deref;
+
 private:
     explicit WebBatteryManagerProxy(WebContext*);
 
+    // WebContextSupplement
+    virtual void contextDestroyed() OVERRIDE;
+    virtual void processDidClose(WebProcessProxy*) OVERRIDE;
+    virtual void refWebContextSupplement() OVERRIDE;
+    virtual void derefWebContextSupplement() OVERRIDE;
+
     // CoreIPC::MessageReceiver
     virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&) OVERRIDE;
 
@@ -62,7 +71,6 @@
 
     bool m_isUpdating;
 
-    WebContext* m_context;
     WebBatteryProvider m_provider;
 };
 

Modified: trunk/Source/WebKit2/UIProcess/WebContext.cpp (149599 => 149600)


--- trunk/Source/WebKit2/UIProcess/WebContext.cpp	2013-05-06 15:43:36 UTC (rev 149599)
+++ trunk/Source/WebKit2/UIProcess/WebContext.cpp	2013-05-06 16:17:40 UTC (rev 149600)
@@ -155,9 +155,6 @@
     addMessageReceiver(WebContextLegacyMessages::messageReceiverName(), this);
 
     // NOTE: These sub-objects must be initialized after m_messageReceiverMap..
-#if ENABLE(BATTERY_STATUS)
-    m_batteryManagerProxy = WebBatteryManagerProxy::create(this);
-#endif
     m_iconDatabase = WebIconDatabase::create(this);
 #if ENABLE(NETWORK_INFO)
     m_networkInfoManagerProxy = WebNetworkInfoManagerProxy::create(this);
@@ -179,6 +176,9 @@
 #if USE(SOUP)
     addSupplement<WebSoupRequestManagerProxy>();
 #endif
+#if ENABLE(BATTERY_STATUS)
+    addSupplement<WebBatteryManagerProxy>();
+#endif
 
     contexts().append(this);
 
@@ -222,11 +222,6 @@
         it->value->clearContext();
     }
 
-#if ENABLE(BATTERY_STATUS)
-    m_batteryManagerProxy->invalidate();
-    m_batteryManagerProxy->clearContext();
-#endif
-
     m_iconDatabase->invalidate();
     m_iconDatabase->clearContext();
     
@@ -676,9 +671,6 @@
     for (; it != end; ++it)
         it->value->processDidClose(process);
 
-#if ENABLE(BATTERY_STATUS)
-    m_batteryManagerProxy->invalidate();
-#endif
 #if ENABLE(NETWORK_INFO)
     m_networkInfoManagerProxy->invalidate();
 #endif

Modified: trunk/Source/WebKit2/UIProcess/WebContext.h (149599 => 149600)


--- trunk/Source/WebKit2/UIProcess/WebContext.h	2013-05-06 15:43:36 UTC (rev 149599)
+++ trunk/Source/WebKit2/UIProcess/WebContext.h	2013-05-06 16:17:40 UTC (rev 149600)
@@ -75,9 +75,6 @@
     
 typedef GenericCallback<WKDictionaryRef> DictionaryCallback;
 
-#if ENABLE(BATTERY_STATUS)
-class WebBatteryManagerProxy;
-#endif
 #if ENABLE(NETWORK_INFO)
 class WebNetworkInfoManagerProxy;
 #endif
@@ -213,9 +210,6 @@
     WebHistoryClient& historyClient() { return m_historyClient; }
     WebContextClient& client() { return m_client; }
 
-#if ENABLE(BATTERY_STATUS)
-    WebBatteryManagerProxy* batteryManagerProxy() const { return m_batteryManagerProxy.get(); }
-#endif
     WebIconDatabase* iconDatabase() const { return m_iconDatabase.get(); }
 #if ENABLE(NETWORK_INFO)
     WebNetworkInfoManagerProxy* networkInfoManagerProxy() const { return m_networkInfoManagerProxy.get(); }
@@ -434,9 +428,6 @@
     bool m_memorySamplerEnabled;
     double m_memorySamplerInterval;
 
-#if ENABLE(BATTERY_STATUS)
-    RefPtr<WebBatteryManagerProxy> m_batteryManagerProxy;
-#endif
     RefPtr<WebIconDatabase> m_iconDatabase;
 #if ENABLE(NETWORK_INFO)
     RefPtr<WebNetworkInfoManagerProxy> m_networkInfoManagerProxy;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to