NativeWindow::NativeWindow(content::WebContents* web_contents,
base::DictionaryValue* options)
: content::WebContentsObserver(web_contents),
+ is_closed_(false),
inspectable_web_contents_(
brightray::InspectableWebContents::Create(web_contents)) {
web_contents->SetDelegate(this);
}
NativeWindow::~NativeWindow() {
- windows_.erase(std::remove(windows_.begin(), windows_.end(), this),
- windows_.end());
+ // It's possible that the windows gets destroyed before it's closed, in that
+ // case we need to ensure the OnWindowClosed message is still notified.
+ NotifyWindowClosed();
}
// static
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.
void NativeWindow::WebContentsCreated(
content::WebContents* source_contents,
// overriding the WillCloseWindow method in the observer.
CloseImmediately();
- FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowClosed());
+ NotifyWindowClosed();
}
bool NativeWindow::OnMessageReceived(const IPC::Message& message) {
static NativeWindow* FromProcessIDAndRoutingID(int process_id,
int routing_id);
+ // Return all opened windows.
+ static std::vector<NativeWindow*> windows() { return windows_; }
+
void InitFromOptions(base::DictionaryValue* options);
virtual void Close() = 0;
virtual void SetKiosk(bool kiosk) = 0;
virtual bool IsKiosk() = 0;
+ virtual bool IsClosed() const { return is_closed_; }
virtual void ShowDevTools();
virtual void CloseDevTools();
return inspectable_web_contents_.get();
}
+ void NotifyWindowClosed();
+
// Implementations of content::WebContentsDelegate.
virtual void WebContentsCreated(content::WebContents* source_contents,
int64 source_frame_id,
// Stores all 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_;
DISALLOW_COPY_AND_ASSIGN(NativeWindow);