Fix a crash when destroying window.

This commit is contained in:
Cheng Zhao 2014-04-11 18:43:01 +08:00
parent 84d458687a
commit 5c5cf3c66e
3 changed files with 16 additions and 6 deletions

View file

@ -57,12 +57,12 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
base::DictionaryValue* options) base::DictionaryValue* options)
: content::WebContentsObserver(web_contents), : content::WebContentsObserver(web_contents),
has_frame_(true), has_frame_(true),
inspectable_web_contents_(
brightray::InspectableWebContents::Create(web_contents)),
is_closed_(false), is_closed_(false),
node_integration_("except-iframe"), node_integration_("except-iframe"),
has_dialog_attached_(false), has_dialog_attached_(false),
weak_factory_(this) { weak_factory_(this),
inspectable_web_contents_(
brightray::InspectableWebContents::Create(web_contents)) {
options->GetBoolean(switches::kFrame, &has_frame_); options->GetBoolean(switches::kFrame, &has_frame_);
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
@ -365,6 +365,10 @@ void NativeWindow::NotifyWindowBlur() {
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowBlur()); FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowBlur());
} }
void NativeWindow::DestroyWebContents() {
inspectable_web_contents_.reset();
}
// In atom-shell all reloads and navigations started by renderer process would // In atom-shell all reloads and navigations started by renderer process would
// be redirected to this method, so we can have precise control of how we // be redirected to this method, so we can have precise control of how we
// would open the url (in our case, is to restart the renderer process). See // would open the url (in our case, is to restart the renderer process). See

View file

@ -196,6 +196,9 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
void NotifyWindowClosed(); void NotifyWindowClosed();
void NotifyWindowBlur(); void NotifyWindowBlur();
// Destroy the inspectable_web_contents.
void DestroyWebContents();
// Called when the window needs to update its draggable region. // Called when the window needs to update its draggable region.
virtual void UpdateDraggableRegions( virtual void UpdateDraggableRegions(
const std::vector<DraggableRegion>& regions) = 0; const std::vector<DraggableRegion>& regions) = 0;
@ -251,8 +254,6 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
// Window icon. // Window icon.
gfx::Image icon_; gfx::Image icon_;
scoped_ptr<brightray::InspectableWebContents> inspectable_web_contents_;
private: private:
// Schedule a notification unresponsive event. // Schedule a notification unresponsive event.
void ScheduleUnresponsiveEvent(int ms); void ScheduleUnresponsiveEvent(int ms);
@ -307,6 +308,11 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
scoped_ptr<AtomJavaScriptDialogManager> dialog_manager_; scoped_ptr<AtomJavaScriptDialogManager> dialog_manager_;
// Notice that inspectable_web_contents_ must be placed after dialog_manager_,
// so we can make sure inspectable_web_contents_ is destroyed before
// dialog_manager_, otherwise a crash would happen.
scoped_ptr<brightray::InspectableWebContents> inspectable_web_contents_;
// Maps url to file path, used by the file requests sent from devtools. // Maps url to file path, used by the file requests sent from devtools.
typedef std::map<std::string, base::FilePath> PathsMap; typedef std::map<std::string, base::FilePath> PathsMap;
PathsMap saved_files_; PathsMap saved_files_;

View file

@ -201,7 +201,7 @@ NativeWindowMac::NativeWindowMac(content::WebContents* web_contents,
NativeWindowMac::~NativeWindowMac() { NativeWindowMac::~NativeWindowMac() {
// Force InspectableWebContents to be destroyed before we destroy window, // Force InspectableWebContents to be destroyed before we destroy window,
// because it may still be observing the window at this time. // because it may still be observing the window at this time.
inspectable_web_contents_.reset(); DestroyWebContents();
} }
void NativeWindowMac::Close() { void NativeWindowMac::Close() {