2006-12-18 Ada Chan <adachan@apple.com>
authoradachan <adachan@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Dec 2006 06:15:09 +0000 (06:15 +0000)
committeradachan <adachan@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Dec 2006 06:15:09 +0000 (06:15 +0000)
        Reviewed by Adam.

        Moved canRunBeforeUnloadConfirmPanel, runBeforeUnloadConfirmPanel, and closeWindowSoon
        from WebCoreFrameBridge to Chrome.
        Moved implementation of Frame::scheduleClose to Frame.cpp.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@18302 268f45cc-cd09-0410-ab3c-d52691b4dbfc

22 files changed:
WebCore/ChangeLog
WebCore/WebCore.exp
WebCore/bridge/win/FrameWin.h
WebCore/page/Chrome.cpp
WebCore/page/Chrome.h
WebCore/page/ChromeClient.h
WebCore/page/Frame.cpp
WebCore/page/Frame.h
WebCore/page/mac/FrameMac.h
WebCore/page/mac/FrameMac.mm
WebCore/page/mac/WebCoreFrameBridge.h
WebCore/platform/gdk/FrameGdk.h
WebCore/platform/gdk/TemporaryLinkStubs.cpp
WebCore/platform/qt/FrameQt.cpp
WebCore/platform/qt/FrameQt.h
WebCore/platform/win/TemporaryLinkStubs.cpp
WebKit/COM/ChromeClientWin.cpp
WebKit/COM/ChromeClientWin.h
WebKit/ChangeLog
WebKit/WebCoreSupport/WebChromeClient.h
WebKit/WebCoreSupport/WebChromeClient.mm
WebKit/WebCoreSupport/WebFrameBridge.mm

index 63fea78..0ea6bd8 100644 (file)
@@ -1,3 +1,34 @@
+2006-12-18  Ada Chan  <adachan@apple.com>
+
+        Reviewed by Adam.
+
+        Moved implementation of Frame::scheduleClose to Frame.cpp.
+        Added canRunBeforeUnloadConfirmPanel, runBeforeUnloadConfirmPanel, and closeWindowSoon
+        in Chrome and ChromeClient.
+
+        * WebCore.exp:
+        * bridge/win/FrameWin.h:
+        * page/Chrome.cpp:
+        (WebCore::Chrome::canRunBeforeUnloadConfirmPanel):
+        (WebCore::Chrome::runBeforeUnloadConfirmPanel):
+        (WebCore::Chrome::closeWindowSoon):
+        * page/Chrome.h:
+        * page/ChromeClient.h:
+        * page/Frame.cpp:
+        (WebCore::Frame::shouldClose):
+        (WebCore::Frame::scheduleClose):
+        * page/Frame.h:
+        * page/mac/FrameMac.h:
+        * page/mac/FrameMac.mm:
+        * page/mac/WebCoreFrameBridge.h:
+        * platform/gdk/FrameGdk.h:
+        * platform/gdk/TemporaryLinkStubs.cpp:
+        (FrameGdk::issuePasteCommand):
+        * platform/qt/FrameQt.cpp:
+        * platform/qt/FrameQt.h:
+        * platform/win/TemporaryLinkStubs.cpp:
+        (WebCore::FrameWin::issuePasteCommand):
+
 2006-12-18  Alice Liu  <alice.liu@apple.com>
 
         Reviewed by Adam.
index 607dcb8..4851e53 100644 (file)
@@ -239,6 +239,7 @@ __ZN7WebCore5Cache11setDisabledEb
 __ZN7WebCore5Cache13getStatisticsEv
 __ZN7WebCore5Cache14setMaximumSizeEj
 __ZN7WebCore5Frame11setSettingsEPNS_8SettingsE
+__ZN7WebCore5Frame11shouldCloseEv
 __ZN7WebCore5Frame17setWindowHasFocusEb
 __ZN7WebCore5Frame20setSelectionFromNoneEv
 __ZN7WebCore5Frame21setProhibitsScrollingEb
@@ -280,7 +281,6 @@ __ZN7WebCore8Document11completeURLERKNS_16DeprecatedStringE
 __ZN7WebCore8Document13removeMarkersENS_14DocumentMarker10MarkerTypeE
 __ZN7WebCore8Document14setFocusedNodeEN3WTF10PassRefPtrINS_4NodeEEE
 __ZN7WebCore8Document4bodyEv
-__ZN7WebCore8FrameMac11shouldCloseEv
 __ZN7WebCore8FrameMac18windowScriptObjectEv
 __ZN7WebCore8FrameMac20windowScriptNPObjectEv
 __ZN7WebCore8FrameMac26dashboardRegionsDictionaryEv
index f4a3f82..d7728b5 100644 (file)
@@ -59,7 +59,6 @@ namespace WebCore {
         virtual bool runJavaScriptConfirm(const String& message);
         virtual bool runJavaScriptPrompt(const String& message, const String& defaultValue, String& result);
         virtual bool shouldInterruptJavaScript();
-        virtual void scheduleClose();
         virtual void focusWindow();
         virtual void unfocusWindow();
         virtual void print();
index f2b64e6..f668025 100644 (file)
@@ -180,5 +180,20 @@ void Chrome::addMessageToConsole(const String &message, unsigned lineNumber, con
     m_client->addMessageToConsole(message, lineNumber, sourceURL);
 }
 
+bool Chrome::canRunBeforeUnloadConfirmPanel()
+{
+    return m_client->canRunBeforeUnloadConfirmPanel();
+}
+
+bool Chrome::runBeforeUnloadConfirmPanel(const String& message, Frame* frame)
+{
+    return m_client->runBeforeUnloadConfirmPanel(message, frame);
+}
+
+void Chrome::closeWindowSoon()
+{
+    m_client->closeWindowSoon();
+}
+
 } // namespace WebCore
 
index 0827b41..5813650 100644 (file)
@@ -29,6 +29,7 @@ namespace WebCore {
     class ChromeClient;
     class ContextMenu;
     class FloatRect;
+    class Frame;
     class Page;
     class String;
     struct FrameLoadRequest;
@@ -73,7 +74,12 @@ namespace WebCore {
         void setResizable(bool) const;
 
         void addMessageToConsole(const String& message, unsigned int lineNumber, const String& sourceID);
-        
+
+        bool canRunBeforeUnloadConfirmPanel();
+        bool runBeforeUnloadConfirmPanel(const String& message, Frame* frame);
+
+        void closeWindowSoon();
+
     private:
         Page* m_page;
         ChromeClient* m_client;
index b72c51e..83b24cc 100644 (file)
@@ -24,6 +24,7 @@
 namespace WebCore {
 
     class FloatRect;
+    class Frame;
     class Page;
     class String;
     
@@ -66,6 +67,11 @@ namespace WebCore {
         virtual void setResizable(bool) = 0;
         
         virtual void addMessageToConsole(const String& message, unsigned int lineNumber, const String& sourceID) = 0;
+
+        virtual bool canRunBeforeUnloadConfirmPanel() = 0;
+        virtual bool runBeforeUnloadConfirmPanel(const String& message, Frame* frame) = 0;
+
+        virtual void closeWindowSoon() = 0;
 };
 
 }
index afbe5dd..743734b 100644 (file)
@@ -30,6 +30,8 @@
 #include "FramePrivate.h"
 
 #include "ApplyStyleCommand.h"
+#include "BeforeUnloadEvent.h"
+#include "Chrome.h"
 #include "CSSComputedStyleDeclaration.h"
 #include "CSSProperty.h"
 #include "CSSPropertyNames.h"
@@ -1503,6 +1505,44 @@ void Frame::setProhibitsScrolling(bool prohibit)
     d->m_prohibitsScrolling = prohibit;
 }
 
+bool Frame::shouldClose()
+{
+    Chrome* chrome = page() ? page()->chrome() : 0;
+    if (!chrome || !chrome->canRunBeforeUnloadConfirmPanel())
+        return true;
+
+    RefPtr<Document> doc = document();
+    if (!doc)
+        return true;
+    HTMLElement* body = doc->body();
+    if (!body)
+        return true;
+
+    RefPtr<BeforeUnloadEvent> beforeUnloadEvent = new BeforeUnloadEvent;
+    beforeUnloadEvent->setTarget(doc);
+    doc->handleWindowEvent(beforeUnloadEvent.get(), false);
+
+    if (!beforeUnloadEvent->defaultPrevented() && doc)
+        doc->defaultEventHandler(beforeUnloadEvent.get());
+    if (beforeUnloadEvent->result().isNull())
+        return true;
+
+    String text = beforeUnloadEvent->result();
+    text.replace('\\', backslashAsCurrencySymbol());
+
+    return chrome->runBeforeUnloadConfirmPanel(text, this);
+}
+
+void Frame::scheduleClose()
+{
+    if (!shouldClose())
+        return;
+
+    Chrome* chrome = page() ? page()->chrome() : 0;
+    if (chrome)
+        chrome->closeWindowSoon();
+}
+
 FramePrivate::FramePrivate(Page* page, Frame* parent, Frame* thisFrame, HTMLFrameOwnerElement* ownerElement, FrameLoaderClient* frameLoaderClient)
     : m_page(page)
     , m_treeNode(thisFrame, parent)
index 9649b88..cdc02d8 100644 (file)
@@ -225,10 +225,11 @@ public:
     virtual bool runJavaScriptConfirm(const String& message) = 0;
     virtual bool runJavaScriptPrompt(const String& message, const String& defaultValue, String& result) = 0;  
     virtual bool shouldInterruptJavaScript() = 0;
-    virtual void scheduleClose() = 0;
     virtual void focusWindow() = 0;
     virtual void unfocusWindow() = 0;
     virtual void print() = 0;
+    bool shouldClose();
+    void scheduleClose();
 
 private:
     virtual void setStatusBarText(const String&);
index 2a7d3ce..b6cdd3b 100644 (file)
@@ -115,7 +115,6 @@ public:
     void willPopupMenu(NSMenu *);
 
     void cleanupPluginObjects();
-    bool shouldClose();
 
     NSImage* selectionImage(bool forceWhiteText = false) const;
     NSImage* snapshotDragImage(Node*, NSRect* imageRect, NSRect* elementRect) const;
@@ -146,8 +145,6 @@ public:
 
     virtual void print();
 
-    virtual void scheduleClose();
-
 // === to be moved into Editor
 
 public:
index 3af5d21..f8ca0fa 100644 (file)
@@ -367,15 +367,6 @@ void FrameMac::setStatusBarText(const String& status)
     [localPool release];
 }
 
-void FrameMac::scheduleClose()
-{
-    if (!shouldClose())
-        return;
-    BEGIN_BLOCK_OBJC_EXCEPTIONS;
-    [_bridge closeWindowSoon];
-    END_BLOCK_OBJC_EXCEPTIONS;
-}
-
 void FrameMac::focusWindow()
 {
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
@@ -1065,39 +1056,6 @@ bool FrameMac::isCharacterSmartReplaceExempt(UChar c, bool isPreviousChar)
     return [_bridge isCharacterSmartReplaceExempt:c isPreviousCharacter:isPreviousChar];
 }
 
-bool FrameMac::shouldClose()
-{
-    BEGIN_BLOCK_OBJC_EXCEPTIONS;
-
-    if (![_bridge canRunBeforeUnloadConfirmPanel])
-        return true;
-
-    RefPtr<Document> doc = document();
-    if (!doc)
-        return true;
-    HTMLElement* body = doc->body();
-    if (!body)
-        return true;
-
-    RefPtr<BeforeUnloadEvent> event = new BeforeUnloadEvent;
-    event->setTarget(doc);
-    doc->handleWindowEvent(event.get(), false);
-
-    if (!event->defaultPrevented() && doc)
-        doc->defaultEventHandler(event.get());
-    if (event->result().isNull())
-        return true;
-
-    String text = event->result();
-    text.replace('\\', backslashAsCurrencySymbol());
-
-    return [_bridge runBeforeUnloadConfirmPanelWithMessage:text];
-
-    END_BLOCK_OBJC_EXCEPTIONS;
-
-    return true;
-}
-
 void Frame::setNeedsReapplyStyles()
 {
     [Mac(this)->_bridge setNeedsReapplyStyles];
index d15cfab..d942f7e 100644 (file)
@@ -289,14 +289,10 @@ typedef enum ObjectElementType {
 
 - (BOOL)textViewWasFirstResponderAtMouseDownTime:(NSTextView *)textView;
 
-- (void)closeWindowSoon;
-
 - (void)runJavaScriptAlertPanelWithMessage:(NSString *)message;
 - (BOOL)runJavaScriptConfirmPanelWithMessage:(NSString *)message;
 - (BOOL)runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)defaultText returningText:(NSString **)result;
 - (BOOL)shouldInterruptJavaScript;
-- (BOOL)canRunBeforeUnloadConfirmPanel;
-- (BOOL)runBeforeUnloadConfirmPanelWithMessage:(NSString *)message;
 - (void)runOpenPanelForFileButtonWithResultListener:(id <WebCoreOpenPanelResultListener>)resultListener;
 
 - (void)formControlIsBecomingFirstResponder:(NSView *)formControl;
index c4c6abf..abb51d5 100644 (file)
@@ -85,8 +85,6 @@ public:
 
     virtual void setTitle(const String&);
 
-    virtual void scheduleClose();
-
     virtual void unfocusWindow();
 
     virtual void focusWindow();
index ae628ee..ccd688e 100644 (file)
@@ -153,7 +153,6 @@ void FrameGdk::issueCopyCommand() { notImplemented(); }
 void FrameGdk::issueUndoCommand() { notImplemented(); }
 String FrameGdk::mimeTypeForFileName(String const&) const { notImplemented(); return String(); }
 void FrameGdk::issuePasteCommand() { notImplemented(); }
-void FrameGdk::scheduleClose() { notImplemented(); }
 void FrameGdk::markMisspellings(WebCore::Selection const&) { notImplemented(); }
 bool FrameGdk::menubarVisible() { notImplemented(); return 0; }
 bool FrameGdk::personalbarVisible() { notImplemented(); return 0; }
index 5ee3dae..a254ada 100644 (file)
@@ -154,11 +154,6 @@ String FrameQt::mimeTypeForFileName(const String&) const
     return String();
 }
 
-void FrameQt::scheduleClose()
-{
-    // no-op
-}
-
 void FrameQt::unfocusWindow()
 {
     if (!view())
index 94ffb23..5666acf 100644 (file)
@@ -60,7 +60,6 @@ public:
     virtual bool runJavaScriptPrompt(const String& message, const String& defaultValue,
                                      String& result);
     virtual bool shouldInterruptJavaScript();
-    virtual void scheduleClose();
     virtual void focusWindow();
     virtual void unfocusWindow();
     virtual void print();
index a3df794..9de1b1d 100644 (file)
@@ -219,7 +219,6 @@ void FrameWin::issueCutCommand() { notImplemented(); }
 void FrameWin::issueCopyCommand() { notImplemented(); }
 String FrameWin::mimeTypeForFileName(String const&) const { notImplemented(); return String(); }
 void FrameWin::issuePasteCommand() { notImplemented(); }
-void FrameWin::scheduleClose() { notImplemented(); }
 void FrameWin::issueTransposeCommand() { notImplemented(); }
 void FrameWin::issuePasteAndMatchStyleCommand() { notImplemented(); }
 bool FrameWin::isLoadTypeReload() { notImplemented(); return false; }
index 4836043..b1cd90f 100644 (file)
@@ -157,3 +157,20 @@ void ChromeClientWin::addMessageToConsole(const WebCore::String&,
 {
     notImplemented();
 }
+
+bool ChromeClientWin::canRunBeforeUnloadConfirmPanel()
+{
+    notImplemented();
+    return false;
+}
+
+bool ChromeClientWin::runBeforeUnloadConfirmPanel(const String&, Frame*)
+{
+    notImplemented();
+    return false;
+}
+
+void ChromeClientWin::closeWindowSoon()
+{
+    notImplemented();
+}
index a3f310c..8eda40c 100644 (file)
@@ -69,6 +69,11 @@ public:
     virtual void addMessageToConsole(const WebCore::String& message,
                                      unsigned int lineNumber,
                                      const WebCore::String& sourceID);
+
+    virtual bool canRunBeforeUnloadConfirmPanel();
+    virtual bool runBeforeUnloadConfirmPanel(const String& message, Frame* frame);
+
+    virtual void closeWindowSoon();
 };
 
 #endif // ChromeClientWin_H
index 371baf2..7b36b89 100644 (file)
@@ -1,3 +1,22 @@
+2006-12-18  Ada Chan  <adachan@apple.com>
+
+        Reviewed by Adam.
+        
+        Moved canRunBeforeUnloadConfirmPanel, runBeforeUnloadConfirmPanel, and closeWindowSoon
+        from WebCoreFrameBridge to Chrome.
+
+        * COM/ChromeClientWin.cpp:
+        (ChromeClientWin::canRunBeforeUnloadConfirmPanel):
+        (ChromeClientWin::runBeforeUnloadConfirmPanel):
+        (ChromeClientWin::closeWindowSoon):
+        * COM/ChromeClientWin.h:
+        * WebCoreSupport/WebChromeClient.h:
+        * WebCoreSupport/WebChromeClient.mm:
+        (WebChromeClient::canRunBeforeUnloadConfirmPanel):
+        (WebChromeClient::runBeforeUnloadConfirmPanel):
+        (WebChromeClient::closeWindowSoon):
+        * WebCoreSupport/WebFrameBridge.mm:
+
 2006-12-18  Alice Liu  <alice.liu@apple.com>
 
         Reviewed by Adam.
index ccfdcd1..7f8f3fb 100644 (file)
@@ -71,6 +71,11 @@ public:
     
     virtual void addMessageToConsole(const WebCore::String& message, unsigned int lineNumber, const WebCore::String& sourceID);
 
+    virtual bool canRunBeforeUnloadConfirmPanel();
+    virtual bool runBeforeUnloadConfirmPanel(const WebCore::String& message, WebCore::Frame* frame);
+
+    virtual void closeWindowSoon();
+
 private:
     WebView *m_webView;
 };
index e40d9d0..5635ba0 100644 (file)
@@ -208,4 +208,37 @@ void WebChromeClient::addMessageToConsole(const String& message, unsigned int li
     }    
 }
 
+bool WebChromeClient::canRunBeforeUnloadConfirmPanel()
+{
+    id wd = [m_webView UIDelegate];
+    return [wd respondsToSelector:@selector(webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:)];
+}
+
+bool WebChromeClient::runBeforeUnloadConfirmPanel(const String& message, Frame* frame)
+{
+    id wd = [m_webView UIDelegate];
+    if ([wd respondsToSelector:@selector(webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:)])
+        return [wd webView:m_webView runBeforeUnloadConfirmPanelWithMessage:message initiatedByFrame:kit(frame)];
+    return true;
+}
+
+void WebChromeClient::closeWindowSoon()
+{
+    // We need to remove the parent WebView from WebViewSets here, before it actually
+    // closes, to make sure that JavaScript code that executes before it closes
+    // can't find it. Otherwise, window.open will select a closed WebView instead of 
+    // opening a new one <rdar://problem/3572585>.
+
+    // We also need to stop the load to prevent further parsing or JavaScript execution
+    // after the window has torn down <rdar://problem/4161660>.
+  
+    // FIXME: This code assumes that the UI delegate will respond to a webViewClose
+    // message by actually closing the WebView. Safari guarantees this behavior, but other apps might not.
+    // This approach is an inherent limitation of not making a close execute immediately
+    // after a call to window.close.
+
+    [m_webView setGroupName:nil];
+    [m_webView stopLoading:nil];
+    [m_webView performSelector:@selector(_closeWindow) withObject:nil afterDelay:0.0];
+}
 
index c69420f..d8d18da 100644 (file)
@@ -278,28 +278,6 @@ NSString *WebPluginContainerKey =   @"WebPluginContainer";
     return [webHTMLView _textViewWasFirstResponderAtMouseDownTime:textView];
 }
 
-- (void)closeWindowSoon
-{
-    WebView *parentWebView = [self webView];
-
-    // We need to remove the parent WebView from WebViewSets here, before it actually
-    // closes, to make sure that JavaScript code that executes before it closes
-    // can't find it. Otherwise, window.open will select a closed WebView instead of 
-    // opening a new one <rdar://problem/3572585>.
-
-    // We also need to stop the load to prevent further parsing or JavaScript execution
-    // after the window has torn down <rdar://problem/4161660>.
-  
-    // FIXME: This code assumes that the UI delegate will respond to a webViewClose
-    // message by actually closing the WebView. Safari guarantees this behavior, but other apps might not.
-    // This approach is an inherent limitation of not making a close execute immediately
-    // after a call to window.close.
-    
-    [parentWebView setGroupName:nil];
-    [parentWebView stopLoading:self];
-    [parentWebView performSelector:@selector(_closeWindow) withObject:nil afterDelay:0.0];
-}
-
 - (NSWindow *)window
 {
     ASSERT(_frame != nil);
@@ -342,22 +320,6 @@ NSString *WebPluginContainerKey =   @"WebPluginContainer";
     return NO;
 }
 
-- (BOOL)canRunBeforeUnloadConfirmPanel
-{
-    WebView *wv = [self webView];
-    id wd = [wv UIDelegate];
-    return [wd respondsToSelector:@selector(webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:)];
-}
-
-- (BOOL)runBeforeUnloadConfirmPanelWithMessage:(NSString *)message
-{
-    WebView *wv = [self webView];
-    id wd = [wv UIDelegate];
-    if ([wd respondsToSelector:@selector(webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:)])
-        return [wd webView:wv runBeforeUnloadConfirmPanelWithMessage:message initiatedByFrame:_frame];
-    return YES;
-}
-
 - (BOOL)runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)defaultText returningText:(NSString **)result
 {
     WebView *wv = [self webView];