]> khamidou — GitHub mirrors - electron.git/commitdiff
Cleanup wrapper function when app has done quitting
authorCheng Zhao <zcbenz@gmail.com>
Wed, 4 Nov 2015 08:54:36 +0000 (16:54 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 4 Nov 2015 08:54:36 +0000 (16:54 +0800)
The app may still do something when quitting, we need to make sure the
wrapper function is still there at that time.

atom/browser/api/atom_api_download_item.cc
atom/browser/api/atom_api_session.cc
atom/browser/api/atom_api_web_contents.cc
atom/browser/api/lib/app.coffee
atom/browser/api/lib/web-contents.coffee

index ec4dcd84b285aba642f179f25a1becf3bf820acf..691cfbfef594381c2bc3d3050774cd1477b46ffb 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <map>
 
+#include "atom/browser/atom_browser_main_parts.h"
 #include "atom/common/native_mate_converters/callback.h"
 #include "atom/common/native_mate_converters/file_path_converter.h"
 #include "atom/common/native_mate_converters/gurl_converter.h"
@@ -159,14 +160,6 @@ mate::ObjectTemplateBuilder DownloadItem::GetObjectTemplateBuilder(
       .SetMethod("setSavePath", &DownloadItem::SetSavePath);
 }
 
-void SetWrapDownloadItem(const WrapDownloadItemCallback& callback) {
-  g_wrap_download_item = callback;
-}
-
-void ClearWrapDownloadItem() {
-  g_wrap_download_item.Reset();
-}
-
 // static
 mate::Handle<DownloadItem> DownloadItem::Create(
     v8::Isolate* isolate, content::DownloadItem* item) {
@@ -182,6 +175,18 @@ void* DownloadItem::UserDataKey() {
   return &kDownloadItemSavePathKey;
 }
 
+void ClearWrapDownloadItem() {
+  g_wrap_download_item.Reset();
+}
+
+void SetWrapDownloadItem(const WrapDownloadItemCallback& callback) {
+  g_wrap_download_item = callback;
+
+  // Cleanup the wrapper on exit.
+  atom::AtomBrowserMainParts::Get()->RegisterDestructionCallback(
+      base::Bind(ClearWrapDownloadItem));
+}
+
 }  // namespace api
 
 }  // namespace atom
@@ -193,7 +198,6 @@ void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
   v8::Isolate* isolate = context->GetIsolate();
   mate::Dictionary dict(isolate, exports);
   dict.SetMethod("_setWrapDownloadItem", &atom::api::SetWrapDownloadItem);
-  dict.SetMethod("_clearWrapDownloadItem", &atom::api::ClearWrapDownloadItem);
 }
 
 }  // namespace
index 5bb96710f22697b95202a089eb43ac8e972c67c3..0ec9c05ed84ea5f6f3e30bd983c92edd10dc17cf 100644 (file)
@@ -9,9 +9,10 @@
 
 #include "atom/browser/api/atom_api_cookies.h"
 #include "atom/browser/api/atom_api_download_item.h"
-#include "atom/browser/atom_browser_context.h"
 #include "atom/browser/api/atom_api_web_contents.h"
 #include "atom/browser/api/save_page_handler.h"
+#include "atom/browser/atom_browser_context.h"
+#include "atom/browser/atom_browser_main_parts.h"
 #include "atom/common/native_mate_converters/callback.h"
 #include "atom/common/native_mate_converters/gurl_converter.h"
 #include "atom/common/native_mate_converters/file_path_converter.h"
@@ -395,12 +396,16 @@ mate::Handle<Session> Session::FromPartition(
                     static_cast<AtomBrowserContext*>(browser_context.get()));
 }
 
+void ClearWrapSession() {
+  g_wrap_session.Reset();
+}
+
 void SetWrapSession(const WrapSessionCallback& callback) {
   g_wrap_session = callback;
-}
 
-void ClearWrapSession() {
-  g_wrap_session.Reset();
+  // Cleanup the wrapper on exit.
+  atom::AtomBrowserMainParts::Get()->RegisterDestructionCallback(
+      base::Bind(ClearWrapSession));
 }
 
 }  // namespace api
@@ -415,7 +420,6 @@ void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
   mate::Dictionary dict(isolate, exports);
   dict.SetMethod("fromPartition", &atom::api::Session::FromPartition);
   dict.SetMethod("_setWrapSession", &atom::api::SetWrapSession);
-  dict.SetMethod("_clearWrapSession", &atom::api::ClearWrapSession);
 }
 
 }  // namespace
index c329b257a29026e1ed3a806c4d50affcd8767907..5165877d1670d3c62e675ba21c31374a1700bffb 100644 (file)
@@ -1124,12 +1124,16 @@ mate::Handle<WebContents> WebContents::Create(
   return handle;
 }
 
+void ClearWrapWebContents() {
+  g_wrap_web_contents.Reset();
+}
+
 void SetWrapWebContents(const WrapWebContentsCallback& callback) {
   g_wrap_web_contents = callback;
-}
 
-void ClearWrapWebContents() {
-  g_wrap_web_contents.Reset();
+  // Cleanup the wrapper on exit.
+  atom::AtomBrowserMainParts::Get()->RegisterDestructionCallback(
+      base::Bind(ClearWrapWebContents));
 }
 
 }  // namespace api
@@ -1145,7 +1149,6 @@ void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
   mate::Dictionary dict(isolate, exports);
   dict.SetMethod("create", &atom::api::WebContents::Create);
   dict.SetMethod("_setWrapWebContents", &atom::api::SetWrapWebContents);
-  dict.SetMethod("_clearWrapWebContents", &atom::api::ClearWrapWebContents);
 }
 
 }  // namespace
index cc676df0dd5a644bcdcc1453fd0960ec1b90eb50..ba68076177ae7e1270070eeae38c394858f291ff 100644 (file)
@@ -59,10 +59,7 @@ app.on 'activate', (event, hasVisibleWindows) -> @emit 'activate-with-no-open-wi
 
 # Wrappers for native classes.
 sessionBindings._setWrapSession wrapSession
-process.once 'exit', sessionBindings._clearWrapSession
-
 downloadItemBindings._setWrapDownloadItem wrapDownloadItem
-process.once 'exit', downloadItemBindings._clearWrapDownloadItem
 
 # Only one App object pemitted.
 module.exports = app
index eab9f196715886e91f892351d1f95ae1945c3a1d..331a561189d7a4edb774b08822fe38a82e325b79 100644 (file)
@@ -112,7 +112,6 @@ wrapWebContents = (webContents) ->
     @_printToPDF printingSetting, callback
 
 binding._setWrapWebContents wrapWebContents
-process.once 'exit', binding._clearWrapWebContents
 
 module.exports.create = (options={}) ->
   binding.create(options)