15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef CONTENT_PUBLIC_BROWSER_JAVASCRIPT_DIALOG_MANAGER_H_
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define CONTENT_PUBLIC_BROWSER_JAVASCRIPT_DIALOG_MANAGER_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/callback.h"
117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/strings/string16.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/common/content_export.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/common/javascript_message_type.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/native_widget_types.h"
157dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "url/gurl.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content {
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebContents;
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// An interface consisting of methods that can be called to produce and manage
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// JavaScript dialogs.
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class CONTENT_EXPORT JavaScriptDialogManager {
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef base::Callback<void(bool /* success */,
26a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                              const base::string16& /* user_input */)>
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                  DialogClosedCallback;
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Displays a JavaScript dialog. |did_suppress_message| will not be nil; if
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |true| is returned in it, the caller will handle faking the reply.
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void RunJavaScriptDialog(
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      WebContents* web_contents,
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const GURL& origin_url,
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const std::string& accept_lang,
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      JavaScriptMessageType javascript_message_type,
36a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      const base::string16& message_text,
37a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      const base::string16& default_prompt_text,
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const DialogClosedCallback& callback,
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      bool* did_suppress_message) = 0;
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Displays a dialog asking the user if they want to leave a page.
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void RunBeforeUnloadDialog(WebContents* web_contents,
43a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                     const base::string16& message_text,
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                     bool is_reload,
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                     const DialogClosedCallback& callback) = 0;
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Accepts or dismisses the active JavaScript dialog, which must be owned
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // by the given |web_contents|. If |prompt_override| is not null, the prompt
492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // text of the dialog should be set before accepting. Returns true if the
502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // dialog was handled.
512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool HandleJavaScriptDialog(WebContents* web_contents,
522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                      bool accept,
53a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                      const base::string16* prompt_override);
542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
55a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // Cancels all active and pending dialogs for the given WebContents.
56a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  virtual void CancelActiveAndPendingDialogs(WebContents* web_contents) = 0;
57a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
58a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // The given WebContents is being destroyed; discards any saved state tied
59a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // to it.
60a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  virtual void WebContentsDestroyed(WebContents* web_contents) = 0;
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~JavaScriptDialogManager() {}
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace content
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif  // CONTENT_PUBLIC_BROWSER_JAVASCRIPT_DIALOG_MANAGER_H_
68