forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add WebLocalFrameObserver to replace RenderFrameObserver methods
This allows us to reduce the size of RenderFrameImpl so that it is not just a springboard for events to be rebroadcast on RenderFrameObserver. Move WillSendSubmitEvent over to this new interface. BUG=1349894 Change-Id: I309992ab8d50d55f4c4dcadb8a37561766e8701e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3864268 Reviewed-by: Arthur Sonzogni <arthursonzogni@chromium.org> Reviewed-by: Kentaro Hara <haraken@chromium.org> Reviewed-by: Dominic Battré <battre@chromium.org> Commit-Queue: Dave Tapuska <dtapuska@chromium.org> Cr-Commit-Position: refs/heads/main@{#1042084}
- Loading branch information
Showing
14 changed files
with
145 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2022 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_LOCAL_FRAME_OBSERVER_H_ | ||
#define THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_LOCAL_FRAME_OBSERVER_H_ | ||
|
||
#include "base/observer_list_types.h" | ||
#include "third_party/blink/public/platform/web_common.h" | ||
#include "third_party/blink/public/platform/web_private_ptr.h" | ||
|
||
namespace blink { | ||
class WebFormElement; | ||
class WebLocalFrame; | ||
class WebLocalFrameImpl; | ||
|
||
// Base class for objects that want to get notified of changes to the local | ||
// frame. | ||
class BLINK_EXPORT WebLocalFrameObserver : public base::CheckedObserver { | ||
public: | ||
// A subclass can use this to delete itself. | ||
virtual void OnFrameDetached() = 0; | ||
|
||
// A form submission has been requested, but the page's submit event handler | ||
// hasn't yet had a chance to run (and possibly alter/interrupt the submit.) | ||
virtual void WillSendSubmitEvent(const WebFormElement&) {} | ||
|
||
// Retrieves the WebLocalFrame that is being observed. Can be null. | ||
WebLocalFrame* GetWebLocalFrame() const; | ||
|
||
protected: | ||
friend class WebLocalFrameImpl; | ||
explicit WebLocalFrameObserver(WebLocalFrame* web_local_frame); | ||
~WebLocalFrameObserver() override; | ||
|
||
private: | ||
// Called when `web_local_frame_` was detached. | ||
void WebLocalFrameDetached(); | ||
|
||
// Sets `WebLocalFrame` to track. | ||
// Removes itself of previous (if any) `web_local_frame_` observer list and | ||
// adds to the new `web_local_frame`. | ||
void Observe(WebLocalFrameImpl* web_local_frame); | ||
|
||
WebPrivatePtr<WebLocalFrameImpl, | ||
kWebPrivatePtrDestructionSameThread, | ||
WebPrivatePtrStrength::kWeak> | ||
web_local_frame_; | ||
}; | ||
|
||
} // namespace blink | ||
|
||
#endif // THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_VIEW_OBSERVER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
third_party/blink/renderer/core/frame/web_local_frame_observer.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2022 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "third_party/blink/public/web/web_local_frame_observer.h" | ||
|
||
#include "third_party/blink/renderer/core/frame/web_local_frame_impl.h" | ||
#include "third_party/blink/renderer/platform/wtf/casting.h" | ||
|
||
namespace blink { | ||
|
||
WebLocalFrameObserver::WebLocalFrameObserver(WebLocalFrame* web_local_frame) | ||
: web_local_frame_(To<WebLocalFrameImpl>(web_local_frame)) { | ||
// |web_local_frame_| can be null on unit testing or if Observe() is used. | ||
if (web_local_frame_) { | ||
web_local_frame_->AddObserver(this); | ||
} | ||
} | ||
|
||
WebLocalFrameObserver::~WebLocalFrameObserver() { | ||
Observe(nullptr); | ||
} | ||
|
||
WebLocalFrame* WebLocalFrameObserver::GetWebLocalFrame() const { | ||
return web_local_frame_.Get(); | ||
} | ||
|
||
void WebLocalFrameObserver::Observe(WebLocalFrameImpl* web_local_frame) { | ||
if (web_local_frame_) { | ||
web_local_frame_->RemoveObserver(this); | ||
} | ||
|
||
web_local_frame_ = web_local_frame; | ||
if (web_local_frame) { | ||
web_local_frame->AddObserver(this); | ||
} | ||
} | ||
|
||
void WebLocalFrameObserver::WebLocalFrameDetached() { | ||
Observe(nullptr); | ||
OnFrameDetached(); | ||
} | ||
|
||
} // namespace blink |