Make beforeunload work in webview

This commit is contained in:
Cheng Zhao 2015-05-01 13:48:39 +08:00
parent 36d2512ff8
commit bfac7f7a17
3 changed files with 13 additions and 1 deletions

View 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_)

View 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_;

View 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);