Add window closing related methods for window observer.
This commit is contained in:
parent
edd8410c24
commit
9e489cae0c
3 changed files with 19 additions and 4 deletions
|
@ -134,6 +134,13 @@ void NativeWindow::CloseDevTools() {
|
|||
}
|
||||
|
||||
void NativeWindow::CloseWebContents() {
|
||||
bool prevent_default = false;
|
||||
FOR_EACH_OBSERVER(NativeWindowObserver,
|
||||
observers_,
|
||||
WillCloseWindow(&prevent_default));
|
||||
if (prevent_default)
|
||||
return;
|
||||
|
||||
content::WebContents* web_contents(GetWebContents());
|
||||
|
||||
if (web_contents->NeedToFireBeforeUnload())
|
||||
|
@ -174,8 +181,12 @@ content::JavaScriptDialogManager* NativeWindow::GetJavaScriptDialogManager() {
|
|||
void NativeWindow::CloseContents(content::WebContents* source) {
|
||||
// When the web contents is gone, close the window immediately, but the
|
||||
// memory will not be freed until you call delete.
|
||||
// In this way, it would be safe to manage windows via smart pointers.
|
||||
// In this way, it would be safe to manage windows via smart pointers. If you
|
||||
// want to free memory when the window is closed, you can do deleting by
|
||||
// overriding WillCloseWindow method in the observer.
|
||||
CloseImmediately();
|
||||
|
||||
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowClosed());
|
||||
}
|
||||
|
||||
bool NativeWindow::OnMessageReceived(const IPC::Message& message) {
|
||||
|
|
|
@ -99,7 +99,6 @@ NativeWindowMac::NativeWindowMac(content::WebContents* web_contents,
|
|||
[atom_window setShell:this];
|
||||
|
||||
window_ = atom_window;
|
||||
[window() setReleasedWhenClosed:NO];
|
||||
[window() setDelegate:[[AtomNSWindowDelegate alloc] initWithShell:this]];
|
||||
|
||||
// Disable fullscreen button when 'fullscreen' is specified to false.
|
||||
|
@ -115,7 +114,6 @@ NativeWindowMac::NativeWindowMac(content::WebContents* web_contents,
|
|||
}
|
||||
|
||||
NativeWindowMac::~NativeWindowMac() {
|
||||
[window() release];
|
||||
}
|
||||
|
||||
void NativeWindowMac::Close() {
|
||||
|
|
|
@ -15,7 +15,13 @@ class NativeWindowObserver {
|
|||
|
||||
// Called when the web page of the window has updated it's document title.
|
||||
virtual void OnPageTitleUpdated(bool* prevent_default,
|
||||
const std::string& title) = 0;
|
||||
const std::string& title) {}
|
||||
|
||||
// Called when the window is gonna closed.
|
||||
virtual void WillCloseWindow(bool* prevent_default) {}
|
||||
|
||||
// Called when the window is closed.
|
||||
virtual void OnWindowClosed() {}
|
||||
};
|
||||
|
||||
} // namespace atom
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue