aw_javascript_dialog_manager.cc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright (c) 2012 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. #include "android_webview/browser/aw_javascript_dialog_manager.h"
  5. #include <utility>
  6. #include "android_webview/browser/aw_contents_client_bridge.h"
  7. #include "content/public/browser/javascript_dialog_manager.h"
  8. #include "content/public/browser/render_frame_host.h"
  9. #include "content/public/browser/web_contents.h"
  10. namespace android_webview {
  11. AwJavaScriptDialogManager::AwJavaScriptDialogManager() {}
  12. AwJavaScriptDialogManager::~AwJavaScriptDialogManager() {}
  13. void AwJavaScriptDialogManager::RunJavaScriptDialog(
  14. content::WebContents* web_contents,
  15. content::RenderFrameHost* render_frame_host,
  16. content::JavaScriptDialogType dialog_type,
  17. const std::u16string& message_text,
  18. const std::u16string& default_prompt_text,
  19. DialogClosedCallback callback,
  20. bool* did_suppress_message) {
  21. AwContentsClientBridge* bridge =
  22. AwContentsClientBridge::FromWebContents(web_contents);
  23. if (!bridge) {
  24. std::move(callback).Run(false, std::u16string());
  25. return;
  26. }
  27. // Non-WebView versions of Chrome use the frame's last committed origin for
  28. // dialog attribution (crbug.com/1241497). However, WebView exposes JS dialog
  29. // calls to users, which means that a change to using the origin (exposed as
  30. // a URL) would be app-visible and a potential compatibility issue.
  31. //
  32. // In addition, WebView is special in that the "last committed origin" and the
  33. // origin of the "last committed URL" can be different due to a legacy app-
  34. // exposed setting, so such a change might be even more breaking.
  35. //
  36. // TODO(crbug.com/1241925): Figure out if some kind of migration can be done
  37. // here, as this is one of several instances in which moving from URL to
  38. // origin would be desirable.
  39. //
  40. // References:
  41. // https://chromium-review.googlesource.com/c/chromium/src/+/2944834/27..46/android_webview/browser/aw_permission_manager.cc#b599
  42. // https://chromium-review.googlesource.com/c/chromium/src/+/3107569/5/android_webview/browser/aw_javascript_dialog_manager.cc#41
  43. bridge->RunJavaScriptDialog(
  44. dialog_type, render_frame_host->GetLastCommittedURL(), message_text,
  45. default_prompt_text, std::move(callback));
  46. }
  47. void AwJavaScriptDialogManager::RunBeforeUnloadDialog(
  48. content::WebContents* web_contents,
  49. content::RenderFrameHost* render_frame_host,
  50. bool is_reload,
  51. DialogClosedCallback callback) {
  52. AwContentsClientBridge* bridge =
  53. AwContentsClientBridge::FromWebContents(web_contents);
  54. if (!bridge) {
  55. std::move(callback).Run(false, std::u16string());
  56. return;
  57. }
  58. bridge->RunBeforeUnloadDialog(web_contents->GetURL(), std::move(callback));
  59. }
  60. void AwJavaScriptDialogManager::CancelDialogs(
  61. content::WebContents* web_contents,
  62. bool reset_state) {}
  63. } // namespace android_webview