web_view_java_script_dialog_presenter.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef IOS_WEB_VIEW_INTERNAL_WEB_VIEW_JAVA_SCRIPT_DIALOG_PRESENTER_H_
  5. #define IOS_WEB_VIEW_INTERNAL_WEB_VIEW_JAVA_SCRIPT_DIALOG_PRESENTER_H_
  6. #import "ios/web/public/ui/java_script_dialog_presenter.h"
  7. @class CWVWebView;
  8. @protocol CWVUIDelegate;
  9. namespace ios_web_view {
  10. // WebView implementation of JavaScriptDialogPresenter. Passes JavaScript alert
  11. // handling to |ui_delegate_|.
  12. class WebViewJavaScriptDialogPresenter final
  13. : public web::JavaScriptDialogPresenter {
  14. public:
  15. WebViewJavaScriptDialogPresenter(CWVWebView* web_view,
  16. id<CWVUIDelegate> ui_delegate);
  17. WebViewJavaScriptDialogPresenter(const WebViewJavaScriptDialogPresenter&) =
  18. delete;
  19. WebViewJavaScriptDialogPresenter& operator=(
  20. const WebViewJavaScriptDialogPresenter&) = delete;
  21. ~WebViewJavaScriptDialogPresenter() override;
  22. void SetUIDelegate(id<CWVUIDelegate> ui_delegate);
  23. // web::JavaScriptDialogPresenter overrides:
  24. void RunJavaScriptDialog(web::WebState* web_state,
  25. const GURL& origin_url,
  26. web::JavaScriptDialogType dialog_type,
  27. NSString* message_text,
  28. NSString* default_prompt_text,
  29. web::DialogClosedCallback callback) override;
  30. void CancelDialogs(web::WebState* web_state) override;
  31. private:
  32. // Displays JavaScript alert.
  33. void HandleJavaScriptAlert(const GURL& origin_url,
  34. NSString* message_text,
  35. web::DialogClosedCallback callback);
  36. // Displays JavaScript confirm dialog.
  37. void HandleJavaScriptConfirmDialog(const GURL& origin_url,
  38. NSString* message_text,
  39. web::DialogClosedCallback callback);
  40. // Displays JavaScript text prompt.
  41. void HandleJavaScriptTextPrompt(const GURL& origin_url,
  42. NSString* message_text,
  43. NSString* default_prompt_text,
  44. web::DialogClosedCallback callback);
  45. // The underlying delegate handling the dialog UI.
  46. __weak id<CWVUIDelegate> ui_delegate_ = nil;
  47. // The web view which originated the dialogs.
  48. __weak CWVWebView* web_view_ = nil;
  49. };
  50. } // namespace ios_web_view
  51. #endif // IOS_WEB_VIEW_INTERNAL_WEB_VIEW_JAVA_SCRIPT_DIALOG_PRESENTER_H_