Make sure WindowClosed message is sent when window is destroyed.
This commit is contained in:
parent
21df63fc9b
commit
e7aab096e7
2 changed files with 24 additions and 4 deletions
|
@ -38,6 +38,7 @@ std::vector<NativeWindow*> NativeWindow::windows_;
|
||||||
NativeWindow::NativeWindow(content::WebContents* web_contents,
|
NativeWindow::NativeWindow(content::WebContents* web_contents,
|
||||||
base::DictionaryValue* options)
|
base::DictionaryValue* options)
|
||||||
: content::WebContentsObserver(web_contents),
|
: content::WebContentsObserver(web_contents),
|
||||||
|
is_closed_(false),
|
||||||
inspectable_web_contents_(
|
inspectable_web_contents_(
|
||||||
brightray::InspectableWebContents::Create(web_contents)) {
|
brightray::InspectableWebContents::Create(web_contents)) {
|
||||||
web_contents->SetDelegate(this);
|
web_contents->SetDelegate(this);
|
||||||
|
@ -50,8 +51,9 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeWindow::~NativeWindow() {
|
NativeWindow::~NativeWindow() {
|
||||||
windows_.erase(std::remove(windows_.begin(), windows_.end(), this),
|
// It's possible that the windows gets destroyed before it's closed, in that
|
||||||
windows_.end());
|
// case we need to ensure the OnWindowClosed message is still notified.
|
||||||
|
NotifyWindowClosed();
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
|
@ -153,6 +155,17 @@ content::WebContents* NativeWindow::GetWebContents() const {
|
||||||
return inspectable_web_contents_->GetWebContents();
|
return inspectable_web_contents_->GetWebContents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NativeWindow::NotifyWindowClosed() {
|
||||||
|
if (is_closed_)
|
||||||
|
return;
|
||||||
|
|
||||||
|
is_closed_ = true;
|
||||||
|
windows_.erase(std::remove(windows_.begin(), windows_.end(), this),
|
||||||
|
windows_.end());
|
||||||
|
|
||||||
|
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowClosed());
|
||||||
|
}
|
||||||
|
|
||||||
// Window opened by window.open.
|
// Window opened by window.open.
|
||||||
void NativeWindow::WebContentsCreated(
|
void NativeWindow::WebContentsCreated(
|
||||||
content::WebContents* source_contents,
|
content::WebContents* source_contents,
|
||||||
|
@ -186,7 +199,7 @@ void NativeWindow::CloseContents(content::WebContents* source) {
|
||||||
// overriding the WillCloseWindow method in the observer.
|
// overriding the WillCloseWindow method in the observer.
|
||||||
CloseImmediately();
|
CloseImmediately();
|
||||||
|
|
||||||
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowClosed());
|
NotifyWindowClosed();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NativeWindow::OnMessageReceived(const IPC::Message& message) {
|
bool NativeWindow::OnMessageReceived(const IPC::Message& message) {
|
||||||
|
|
|
@ -59,6 +59,9 @@ class NativeWindow : public content::WebContentsDelegate,
|
||||||
static NativeWindow* FromProcessIDAndRoutingID(int process_id,
|
static NativeWindow* FromProcessIDAndRoutingID(int process_id,
|
||||||
int routing_id);
|
int routing_id);
|
||||||
|
|
||||||
|
// Return all opened windows.
|
||||||
|
static std::vector<NativeWindow*> windows() { return windows_; }
|
||||||
|
|
||||||
void InitFromOptions(base::DictionaryValue* options);
|
void InitFromOptions(base::DictionaryValue* options);
|
||||||
|
|
||||||
virtual void Close() = 0;
|
virtual void Close() = 0;
|
||||||
|
@ -92,6 +95,7 @@ class NativeWindow : public content::WebContentsDelegate,
|
||||||
virtual void SetKiosk(bool kiosk) = 0;
|
virtual void SetKiosk(bool kiosk) = 0;
|
||||||
virtual bool IsKiosk() = 0;
|
virtual bool IsKiosk() = 0;
|
||||||
|
|
||||||
|
virtual bool IsClosed() const { return is_closed_; }
|
||||||
virtual void ShowDevTools();
|
virtual void ShowDevTools();
|
||||||
virtual void CloseDevTools();
|
virtual void CloseDevTools();
|
||||||
|
|
||||||
|
@ -118,6 +122,8 @@ class NativeWindow : public content::WebContentsDelegate,
|
||||||
return inspectable_web_contents_.get();
|
return inspectable_web_contents_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NotifyWindowClosed();
|
||||||
|
|
||||||
// Implementations of content::WebContentsDelegate.
|
// Implementations of content::WebContentsDelegate.
|
||||||
virtual void WebContentsCreated(content::WebContents* source_contents,
|
virtual void WebContentsCreated(content::WebContents* source_contents,
|
||||||
int64 source_frame_id,
|
int64 source_frame_id,
|
||||||
|
@ -153,8 +159,9 @@ class NativeWindow : public content::WebContentsDelegate,
|
||||||
// Stores all windows.
|
// Stores all windows.
|
||||||
static std::vector<NativeWindow*> windows_;
|
static std::vector<NativeWindow*> windows_;
|
||||||
|
|
||||||
scoped_ptr<AtomJavaScriptDialogManager> dialog_manager_;
|
bool is_closed_;
|
||||||
|
|
||||||
|
scoped_ptr<AtomJavaScriptDialogManager> dialog_manager_;
|
||||||
scoped_ptr<brightray::InspectableWebContents> inspectable_web_contents_;
|
scoped_ptr<brightray::InspectableWebContents> inspectable_web_contents_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(NativeWindow);
|
DISALLOW_COPY_AND_ASSIGN(NativeWindow);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue