Reduce duplicated code in WebPageProxy
https://bugs.webkit.org/show_bug.cgi?id=122230

Patch by Gustavo Noronha Silva <gustavo.noronha@collabora.co.uk> on 2013-10-07
Reviewed by Darin Adler.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::close): move duplicate code to resetState and call it.
(WebKit::WebPageProxy::resetState): new private method for code that is shared between
close and resetStateAfterProcessExited.
(WebKit::WebPageProxy::resetStateAfterProcessExited): move duplicate code to resetState
and call it.
* UIProcess/WebPageProxy.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@157064 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebKit2/ChangeLog b/Source/WebKit2/ChangeLog
index 5f56a27..ba11df0 100644
--- a/Source/WebKit2/ChangeLog
+++ b/Source/WebKit2/ChangeLog
@@ -1,3 +1,18 @@
+2013-10-07  Gustavo Noronha Silva  <gustavo.noronha@collabora.co.uk>
+
+        Reduce duplicated code in WebPageProxy
+        https://bugs.webkit.org/show_bug.cgi?id=122230
+
+        Reviewed by Darin Adler.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::close): move duplicate code to resetState and call it.
+        (WebKit::WebPageProxy::resetState): new private method for code that is shared between
+        close and resetStateAfterProcessExited.
+        (WebKit::WebPageProxy::resetStateAfterProcessExited): move duplicate code to resetState
+        and call it.
+        * UIProcess/WebPageProxy.h:
+
 2013-10-07  Sam Weinig  <sam@webkit.org>
 
         CTTE: Use references in and around DragController
diff --git a/Source/WebKit2/UIProcess/WebPageProxy.cpp b/Source/WebKit2/UIProcess/WebPageProxy.cpp
index 75f1037..d480434 100644
--- a/Source/WebKit2/UIProcess/WebPageProxy.cpp
+++ b/Source/WebKit2/UIProcess/WebPageProxy.cpp
@@ -546,77 +546,8 @@
     m_pageClient->pageClosed();
 
     m_process->disconnectFramesFromPage(this);
-    m_mainFrame = 0;
 
-#if ENABLE(INSPECTOR)
-    if (m_inspector) {
-        m_inspector->invalidate();
-        m_inspector = 0;
-    }
-#endif
-
-#if ENABLE(FULLSCREEN_API)
-    if (m_fullScreenManager) {
-        m_fullScreenManager->invalidate();
-        m_fullScreenManager = 0;
-    }
-#endif
-
-#if ENABLE(VIBRATION)
-    m_vibration->invalidate();
-#endif
-
-    if (m_openPanelResultListener) {
-        m_openPanelResultListener->invalidate();
-        m_openPanelResultListener = 0;
-    }
-
-#if ENABLE(INPUT_TYPE_COLOR)
-    if (m_colorPicker) {
-        m_colorPicker->invalidate();
-        m_colorPicker = nullptr;
-    }
-#endif
-
-#if ENABLE(GEOLOCATION)
-    m_geolocationPermissionRequestManager.invalidateRequests();
-#endif
-
-    m_notificationPermissionRequestManager.invalidateRequests();
-    m_process->context()->supplement<WebNotificationManagerProxy>()->clearNotifications(this);
-
-    m_toolTip = String();
-
-    m_mainFrameHasHorizontalScrollbar = false;
-    m_mainFrameHasVerticalScrollbar = false;
-
-    m_mainFrameIsPinnedToLeftSide = false;
-    m_mainFrameIsPinnedToRightSide = false;
-    m_mainFrameIsPinnedToTopSide = false;
-    m_mainFrameIsPinnedToBottomSide = false;
-
-    m_visibleScrollerThumbRect = IntRect();
-
-    invalidateCallbackMap(m_voidCallbacks);
-    invalidateCallbackMap(m_dataCallbacks);
-    invalidateCallbackMap(m_imageCallbacks);
-    invalidateCallbackMap(m_stringCallbacks);
-    m_loadDependentStringCallbackIDs.clear();
-    invalidateCallbackMap(m_scriptValueCallbacks);
-    invalidateCallbackMap(m_computedPagesCallbacks);
-#if PLATFORM(GTK)
-    invalidateCallbackMap(m_printFinishedCallbacks);
-#endif
-
-    Vector<WebEditCommandProxy*> editCommandVector;
-    copyToVector(m_editCommandSet, editCommandVector);
-    m_editCommandSet.clear();
-    for (size_t i = 0, size = editCommandVector.size(); i < size; ++i)
-        editCommandVector[i]->invalidate();
-
-    m_activePopupMenu = 0;
-
-    m_estimatedProgress = 0.0;
+    resetState();
 
     m_loaderClient.initialize(0);
     m_policyClient.initialize(0);
@@ -631,8 +562,6 @@
     m_contextMenuClient.initialize(0);
 #endif
 
-    m_drawingArea = nullptr;
-
 #if PLATFORM(MAC)
     m_exposedRectChangedTimer.stop();
 #endif
@@ -641,6 +570,7 @@
     m_process->removeWebPage(m_pageID);
     m_process->removeMessageReceiver(Messages::WebPageProxy::messageReceiverName(), m_pageID);
     m_process->context()->storageManager().destroySessionStorageNamespace(m_pageID);
+    m_process->context()->supplement<WebNotificationManagerProxy>()->clearNotifications(this);
 }
 
 bool WebPageProxy::tryClose()
@@ -3797,34 +3727,23 @@
     m_loaderClient.processDidCrash(this);
 }
 
-void WebPageProxy::resetStateAfterProcessExited()
+void WebPageProxy::resetState()
 {
-    if (!isValid())
-        return;
-
-    ASSERT(m_pageClient);
-    m_process->removeMessageReceiver(Messages::WebPageProxy::messageReceiverName(), m_pageID);
-
-    m_isValid = false;
-    m_isPageSuspended = false;
-    m_waitingForDidUpdateInWindowState = false;
-
-    if (m_mainFrame) {
-        m_urlAtProcessExit = m_mainFrame->url();
-        m_loadStateAtProcessExit = m_mainFrame->loadState();
-    }
-
     m_mainFrame = nullptr;
     m_drawingArea = nullptr;
 
 #if ENABLE(INSPECTOR)
-    m_inspector->invalidate();
-    m_inspector = nullptr;
+    if (m_inspector) {
+        m_inspector->invalidate();
+        m_inspector = nullptr;
+    }
 #endif
 
 #if ENABLE(FULLSCREEN_API)
-    m_fullScreenManager->invalidate();
-    m_fullScreenManager = nullptr;
+    if (m_fullScreenManager) {
+        m_fullScreenManager->invalidate();
+        m_fullScreenManager = nullptr;
+    }
 #endif
 
 #if ENABLE(VIBRATION)
@@ -3863,6 +3782,7 @@
 
     invalidateCallbackMap(m_voidCallbacks);
     invalidateCallbackMap(m_dataCallbacks);
+    invalidateCallbackMap(m_imageCallbacks);
     invalidateCallbackMap(m_stringCallbacks);
     m_loadDependentStringCallbackIDs.clear();
     invalidateCallbackMap(m_scriptValueCallbacks);
@@ -3877,12 +3797,32 @@
     m_editCommandSet.clear();
     for (size_t i = 0, size = editCommandVector.size(); i < size; ++i)
         editCommandVector[i]->invalidate();
-    m_pageClient->clearAllEditCommands();
 
     m_activePopupMenu = 0;
 
     m_estimatedProgress = 0.0;
+}
 
+void WebPageProxy::resetStateAfterProcessExited()
+{
+    if (!isValid())
+        return;
+
+    ASSERT(m_pageClient);
+    m_process->removeMessageReceiver(Messages::WebPageProxy::messageReceiverName(), m_pageID);
+
+    m_isValid = false;
+    m_isPageSuspended = false;
+    m_waitingForDidUpdateInWindowState = false;
+
+    if (m_mainFrame) {
+        m_urlAtProcessExit = m_mainFrame->url();
+        m_loadStateAtProcessExit = m_mainFrame->loadState();
+    }
+
+    resetState();
+
+    m_pageClient->clearAllEditCommands();
     m_pendingLearnOrIgnoreWordMessageCount = 0;
 
     // If the call out to the loader client didn't cause the web process to be relaunched,
diff --git a/Source/WebKit2/UIProcess/WebPageProxy.h b/Source/WebKit2/UIProcess/WebPageProxy.h
index 70c98e3..17a2ee3 100644
--- a/Source/WebKit2/UIProcess/WebPageProxy.h
+++ b/Source/WebKit2/UIProcess/WebPageProxy.h
@@ -767,6 +767,7 @@
     WebPageProxy(PageClient*, PassRefPtr<WebProcessProxy>, WebPageGroup*, uint64_t pageID);
     void platformInitialize();
 
+    void resetState();
     void resetStateAfterProcessExited();
 
     // CoreIPC::MessageReceiver