Commit 3649edb8 authored by adachan's avatar adachan

2006-12-18 Ada Chan <adachan@apple.com>

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



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@18302 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent b36f3b84
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.
......@@ -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
......
......@@ -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();
......
......@@ -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
......@@ -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;
......
......@@ -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;
};
}
......
......@@ -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)
......
......@@ -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&);
......
......@@ -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:
......
......@@ -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];
......
......@@ -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;
......
......@@ -85,8 +85,6 @@ public:
virtual void setTitle(const String&);
virtual void scheduleClose();
virtual void unfocusWindow();
virtual void focusWindow();
......
......@@ -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; }
......
......@@ -154,11 +154,6 @@ String FrameQt::mimeTypeForFileName(const String&) const
return String();
}
void FrameQt::scheduleClose()
{
// no-op
}
void FrameQt::unfocusWindow()
{
if (!view())
......
......@@ -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();
......
......@@ -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; }
......
......@@ -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();
}
......@@ -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
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.
......
......@@ -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;
};
......@@ -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];
}
......@@ -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];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment