]> khamidou — GitHub mirrors - electron.git/commitdiff
Make beforeunload work in webview
authorCheng Zhao <zcbenz@gmail.com>
Fri, 1 May 2015 05:48:39 +0000 (13:48 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 1 May 2015 05:48:39 +0000 (13:48 +0800)
atom/browser/api/atom_api_web_contents.cc
atom/browser/api/atom_api_web_contents.h
atom/browser/atom_javascript_dialog_manager.cc

index a6b10acd1e9050b307753e53b50ea3e56c54215e..e6aa2f898679193c91e9639c383703782593fbe3 100644 (file)
@@ -7,6 +7,7 @@
 #include <set>
 
 #include "atom/browser/atom_browser_context.h"
+#include "atom/browser/atom_javascript_dialog_manager.h"
 #include "atom/browser/native_window.h"
 #include "atom/browser/web_dialog_helper.h"
 #include "atom/browser/web_view_manager.h"
@@ -146,6 +147,14 @@ content::WebContents* WebContents::OpenURLFromTab(
   return web_contents();
 }
 
+content::JavaScriptDialogManager* WebContents::GetJavaScriptDialogManager(
+    content::WebContents* source) {
+  if (!dialog_manager_)
+    dialog_manager_.reset(new AtomJavaScriptDialogManager);
+
+  return dialog_manager_.get();
+}
+
 void WebContents::RunFileChooser(content::WebContents* guest,
                                  const content::FileChooserParams& params) {
   if (!web_dialog_helper_)
index 0d146a694679f583365390b18838c3ef08e55a54..e8010d560015f99b27b3fe7e8a7bc0812b5026f0 100644 (file)
@@ -27,6 +27,7 @@ class Dictionary;
 
 namespace atom {
 
+class AtomJavaScriptDialogManager;
 class WebDialogHelper;
 
 namespace api {
@@ -126,6 +127,8 @@ class WebContents : public mate::EventEmitter,
   content::WebContents* OpenURLFromTab(
       content::WebContents* source,
       const content::OpenURLParams& params) override;
+  content::JavaScriptDialogManager* GetJavaScriptDialogManager(
+      content::WebContents* source) override;
   void RunFileChooser(content::WebContents* web_contents,
                       const content::FileChooserParams& params) override;
   void EnumerateDirectory(content::WebContents* web_contents,
@@ -201,6 +204,7 @@ class WebContents : public mate::EventEmitter,
                                      const gfx::Size& new_size);
 
   scoped_ptr<WebDialogHelper> web_dialog_helper_;
+  scoped_ptr<AtomJavaScriptDialogManager> dialog_manager_;
 
   // Unique ID for a guest WebContents.
   int guest_instance_id_;
index 8d4e10853495d27846262018ed29de445ac3df38..c21d1fb1181622c999e0072ef990465a35072aea 100644 (file)
@@ -27,7 +27,6 @@ void AtomJavaScriptDialogManager::RunBeforeUnloadDialog(
     const base::string16& message_text,
     bool is_reload,
     const DialogClosedCallback& callback) {
-
   bool prevent_reload = message_text.empty() ||
                         message_text == base::ASCIIToUTF16("false");
   callback.Run(!prevent_reload, message_text);