blink_local_frame.patch 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Cheng Zhao <[email protected]>
  3. Date: Thu, 20 Sep 2018 17:45:03 -0700
  4. Subject: blink_local_frame.patch
  5. According to electron/electron#3699, it is unreliable to use |unload|
  6. event for process.exit('exit'), so we have to do that in
  7. willReleaseScriptContext.
  8. Refs changes in:
  9. * https://codereview.chromium.org/1657583002
  10. * https://chromium-review.googlesource.com/c/chromium/src/+/2596880
  11. * https://chromium-review.googlesource.com/c/chromium/src/+/2597169
  12. This patch reverts the changes to fix associated crashes in Electron.
  13. diff --git a/third_party/blink/renderer/core/frame/frame.cc b/third_party/blink/renderer/core/frame/frame.cc
  14. index 22c4d4e9718a503d9c7ca26a40c97149b0f8986a..6bdc2757c96a28022fda9e6f5e3b74a08332a4ce 100644
  15. --- a/third_party/blink/renderer/core/frame/frame.cc
  16. +++ b/third_party/blink/renderer/core/frame/frame.cc
  17. @@ -125,14 +125,6 @@ bool Frame::Detach(FrameDetachType type) {
  18. DCHECK(!IsDetached());
  19. - // TODO(dcheng): FocusController::FrameDetached() *should* fire JS events,
  20. - // hence the above check for `client_` being null. However, when this was
  21. - // previously placed before the `FrameDetached()` call, nothing crashes, which
  22. - // is suspicious. Investigate if we really don't need to fire JS events--and
  23. - // if we don't, move `forbid_scripts` up to be instantiated sooner and
  24. - // simplify this code.
  25. - ScriptForbiddenScope forbid_scripts;
  26. -
  27. if (type == FrameDetachType::kRemove) {
  28. if (provisional_frame_) {
  29. provisional_frame_->Detach(FrameDetachType::kRemove);
  30. @@ -156,6 +148,14 @@ bool Frame::Detach(FrameDetachType type) {
  31. GetWindowProxyManager()->ClearForSwap();
  32. }
  33. + // TODO(dcheng): FocusController::FrameDetached() *should* fire JS events,
  34. + // hence the above check for `client_` being null. However, when this was
  35. + // previously placed before the `FrameDetached()` call, nothing crashes, which
  36. + // is suspicious. Investigate if we really don't need to fire JS events--and
  37. + // if we don't, move `forbid_scripts` up to be instantiated sooner and
  38. + // simplify this code.
  39. + ScriptForbiddenScope forbid_scripts;
  40. +
  41. // After this, we must no longer talk to the client since this clears
  42. // its owning reference back to our owning LocalFrame.
  43. client_->Detached(type);
  44. diff --git a/third_party/blink/renderer/core/frame/local_frame.cc b/third_party/blink/renderer/core/frame/local_frame.cc
  45. index 6e278ba2097021dcdf0ac9cd4d39b108929c79c6..59ed3c0fcc335ce418484f537886a5ded7835418 100644
  46. --- a/third_party/blink/renderer/core/frame/local_frame.cc
  47. +++ b/third_party/blink/renderer/core/frame/local_frame.cc
  48. @@ -665,10 +665,6 @@ bool LocalFrame::DetachImpl(FrameDetachType type) {
  49. }
  50. DCHECK(!view_ || !view_->IsAttached());
  51. - // This is the earliest that scripting can be disabled:
  52. - // - FrameLoader::Detach() can fire XHR abort events
  53. - // - Document::Shutdown() can dispose plugins which can run script.
  54. - ScriptForbiddenScope forbid_script;
  55. if (!Client())
  56. return false;
  57. @@ -716,6 +712,11 @@ bool LocalFrame::DetachImpl(FrameDetachType type) {
  58. DCHECK(!view_->IsAttached());
  59. Client()->WillBeDetached();
  60. + // This is the earliest that scripting can be disabled:
  61. + // - FrameLoader::Detach() can fire XHR abort events
  62. + // - Document::Shutdown() can dispose plugins which can run script.
  63. + ScriptForbiddenScope forbid_script;
  64. +
  65. // TODO(crbug.com/729196): Trace why LocalFrameView::DetachFromLayout crashes.
  66. CHECK(!view_->IsAttached());
  67. SetView(nullptr);