Commit a868c6c1 authored by fsamuel@chromium.org's avatar fsamuel@chromium.org

Prevent derived classes of GuestViewBase from overriding key methods

This change removes the obligation for the derived class to call the base class' implementation at the end. This makes it easier to write GuestViewBase derived classes.

BUG=364141 330264

Review URL: https://codereview.chromium.org/318433002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274801 0039d316-1c4b-4281-b951-d872f2087c98
parent 74213487
...@@ -211,6 +211,7 @@ void GuestViewBase::Attach(content::WebContents* embedder_web_contents, ...@@ -211,6 +211,7 @@ void GuestViewBase::Attach(content::WebContents* embedder_web_contents,
} }
void GuestViewBase::Destroy() { void GuestViewBase::Destroy() {
WillDestroy();
if (!destruction_callback_.is_null()) if (!destruction_callback_.is_null())
destruction_callback_.Run(); destruction_callback_.Run();
delete guest_web_contents(); delete guest_web_contents();
...@@ -242,6 +243,7 @@ void GuestViewBase::DidStopLoading(content::RenderViewHost* render_view_host) { ...@@ -242,6 +243,7 @@ void GuestViewBase::DidStopLoading(content::RenderViewHost* render_view_host) {
} }
void GuestViewBase::WebContentsDestroyed() { void GuestViewBase::WebContentsDestroyed() {
GuestDestroyed();
delete this; delete this;
} }
......
...@@ -76,15 +76,30 @@ class GuestViewBase : public content::BrowserPluginGuestDelegate, ...@@ -76,15 +76,30 @@ class GuestViewBase : public content::BrowserPluginGuestDelegate,
virtual const char* GetViewType() const = 0; virtual const char* GetViewType() const = 0;
// This method can be overriden by subclasses. This method is called when // This method can be overridden by subclasses. This method is called when
// the initial set of frames within the page have completed loading. // the initial set of frames within the page have completed loading.
virtual void DidStopLoading() {} virtual void DidStopLoading() {}
// This method can be overridden by subclasses. It indicates that this guest's // This method is called when the guest WebContents is about to be destroyed.
// embedder has been destroyed and the guest will be destroyed shortly. This //
// method gives derived classes the opportunity to perform some cleanup. // This method can be overridden by subclasses. This gives the derived class
// an opportunity to perform some cleanup prior to destruction.
virtual void WillDestroy() {}
// This method is called when the guest's embedder WebContents has been
// destroyed and the guest will be destroyed shortly.
//
// This method can be overridden by subclasses. This gives the derived class
// an opportunity to perform some cleanup prior to destruction.
virtual void EmbedderDestroyed() {} virtual void EmbedderDestroyed() {}
// This method is called when the guest WebContents has been destroyed. This
// object will be destroyed after this call returns.
//
// This method can be overridden by subclasses. This gives the derived class
// opportunity to perform some cleanup.
virtual void GuestDestroyed() {}
// This method queries whether drag-and-drop is enabled for this particular // This method queries whether drag-and-drop is enabled for this particular
// view. By default, drag-and-drop is disabled. Derived classes can override // view. By default, drag-and-drop is disabled. Derived classes can override
// this behavior to enable drag-and-drop. // this behavior to enable drag-and-drop.
...@@ -143,21 +158,11 @@ class GuestViewBase : public content::BrowserPluginGuestDelegate, ...@@ -143,21 +158,11 @@ class GuestViewBase : public content::BrowserPluginGuestDelegate,
void SetOpener(GuestViewBase* opener); void SetOpener(GuestViewBase* opener);
// WebContentsObserver implementation.
virtual void DidStopLoading(
content::RenderViewHost* render_view_host) OVERRIDE FINAL;
virtual void WebContentsDestroyed() OVERRIDE;
// WebContentsDelegate implementation.
virtual bool ShouldFocusPageAfterCrash() OVERRIDE;
virtual bool PreHandleGestureEvent(
content::WebContents* source,
const blink::WebGestureEvent& event) OVERRIDE;
// BrowserPluginGuestDelegate implementation. // BrowserPluginGuestDelegate implementation.
virtual void Destroy() OVERRIDE; virtual void Destroy() OVERRIDE FINAL;
virtual void RegisterDestructionCallback( virtual void RegisterDestructionCallback(
const DestructionCallback& callback) OVERRIDE; const DestructionCallback& callback) OVERRIDE FINAL;
protected: protected:
GuestViewBase(int guest_instance_id, GuestViewBase(int guest_instance_id,
content::WebContents* guest_web_contents, content::WebContents* guest_web_contents,
...@@ -172,6 +177,17 @@ class GuestViewBase : public content::BrowserPluginGuestDelegate, ...@@ -172,6 +177,17 @@ class GuestViewBase : public content::BrowserPluginGuestDelegate,
void SendQueuedEvents(); void SendQueuedEvents();
// WebContentsObserver implementation.
virtual void DidStopLoading(
content::RenderViewHost* render_view_host) OVERRIDE FINAL;
virtual void WebContentsDestroyed() OVERRIDE FINAL;
// WebContentsDelegate implementation.
virtual bool ShouldFocusPageAfterCrash() OVERRIDE FINAL;
virtual bool PreHandleGestureEvent(
content::WebContents* source,
const blink::WebGestureEvent& event) OVERRIDE FINAL;
content::WebContents* embedder_web_contents_; content::WebContents* embedder_web_contents_;
const std::string embedder_extension_id_; const std::string embedder_extension_id_;
int embedder_render_process_id_; int embedder_render_process_id_;
......
...@@ -359,10 +359,26 @@ void WebViewGuest::EmbedderDestroyed() { ...@@ -359,10 +359,26 @@ void WebViewGuest::EmbedderDestroyed() {
view_instance_id())); view_instance_id()));
} }
void WebViewGuest::GuestDestroyed() {
// Clean up custom context menu items for this guest.
extensions::MenuManager* menu_manager = extensions::MenuManager::Get(
Profile::FromBrowserContext(browser_context()));
menu_manager->RemoveAllContextItems(extensions::MenuItem::ExtensionKey(
embedder_extension_id(), view_instance_id()));
RemoveWebViewFromExtensionRendererState(web_contents());
}
bool WebViewGuest::IsDragAndDropEnabled() const { bool WebViewGuest::IsDragAndDropEnabled() const {
return true; return true;
} }
void WebViewGuest::WillDestroy() {
if (!attached() && GetOpener())
GetOpener()->pending_new_windows_.erase(this);
DestroyUnattachedWindows();
}
bool WebViewGuest::AddMessageToConsole(WebContents* source, bool WebViewGuest::AddMessageToConsole(WebContents* source,
int32 level, int32 level,
const base::string16& message, const base::string16& message,
...@@ -865,17 +881,6 @@ void WebViewGuest::RenderProcessGone(base::TerminationStatus status) { ...@@ -865,17 +881,6 @@ void WebViewGuest::RenderProcessGone(base::TerminationStatus status) {
DispatchEvent(new GuestViewBase::Event(webview::kEventExit, args.Pass())); DispatchEvent(new GuestViewBase::Event(webview::kEventExit, args.Pass()));
} }
void WebViewGuest::WebContentsDestroyed() {
// Clean up custom context menu items for this guest.
extensions::MenuManager* menu_manager = extensions::MenuManager::Get(
Profile::FromBrowserContext(browser_context()));
menu_manager->RemoveAllContextItems(extensions::MenuItem::ExtensionKey(
embedder_extension_id(), view_instance_id()));
RemoveWebViewFromExtensionRendererState(web_contents());
GuestViewBase::WebContentsDestroyed();
}
void WebViewGuest::UserAgentOverrideSet(const std::string& user_agent) { void WebViewGuest::UserAgentOverrideSet(const std::string& user_agent) {
content::NavigationController& controller = content::NavigationController& controller =
guest_web_contents()->GetController(); guest_web_contents()->GetController();
...@@ -1269,13 +1274,6 @@ void WebViewGuest::SetZoom(double zoom_factor) { ...@@ -1269,13 +1274,6 @@ void WebViewGuest::SetZoom(double zoom_factor) {
current_zoom_factor_ = zoom_factor; current_zoom_factor_ = zoom_factor;
} }
void WebViewGuest::Destroy() {
if (!attached() && GetOpener())
GetOpener()->pending_new_windows_.erase(this);
DestroyUnattachedWindows();
GuestViewBase::Destroy();
}
void WebViewGuest::AddNewContents(content::WebContents* source, void WebViewGuest::AddNewContents(content::WebContents* source,
content::WebContents* new_contents, content::WebContents* new_contents,
WindowOpenDisposition disposition, WindowOpenDisposition disposition,
......
...@@ -71,7 +71,9 @@ class WebViewGuest : public GuestView<WebViewGuest>, ...@@ -71,7 +71,9 @@ class WebViewGuest : public GuestView<WebViewGuest>,
const base::DictionaryValue& args) OVERRIDE; const base::DictionaryValue& args) OVERRIDE;
virtual void DidStopLoading() OVERRIDE; virtual void DidStopLoading() OVERRIDE;
virtual void EmbedderDestroyed() OVERRIDE; virtual void EmbedderDestroyed() OVERRIDE;
virtual void GuestDestroyed() OVERRIDE;
virtual bool IsDragAndDropEnabled() const OVERRIDE; virtual bool IsDragAndDropEnabled() const OVERRIDE;
virtual void WillDestroy() OVERRIDE;
// WebContentsDelegate implementation. // WebContentsDelegate implementation.
virtual bool AddMessageToConsole(content::WebContents* source, virtual bool AddMessageToConsole(content::WebContents* source,
...@@ -136,7 +138,6 @@ class WebViewGuest : public GuestView<WebViewGuest>, ...@@ -136,7 +138,6 @@ class WebViewGuest : public GuestView<WebViewGuest>,
bool last_unlocked_by_target, bool last_unlocked_by_target,
const base::Callback<void(bool)>& callback) OVERRIDE; const base::Callback<void(bool)>& callback) OVERRIDE;
virtual void NavigateGuest(const std::string& src) OVERRIDE; virtual void NavigateGuest(const std::string& src) OVERRIDE;
virtual void Destroy() OVERRIDE;
// NotificationObserver implementation. // NotificationObserver implementation.
virtual void Observe(int type, virtual void Observe(int type,
...@@ -299,7 +300,6 @@ class WebViewGuest : public GuestView<WebViewGuest>, ...@@ -299,7 +300,6 @@ class WebViewGuest : public GuestView<WebViewGuest>,
const IPC::Message& message, const IPC::Message& message,
content::RenderFrameHost* render_frame_host) OVERRIDE; content::RenderFrameHost* render_frame_host) OVERRIDE;
virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE; virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
virtual void WebContentsDestroyed() OVERRIDE;
virtual void UserAgentOverrideSet(const std::string& user_agent) OVERRIDE; virtual void UserAgentOverrideSet(const std::string& user_agent) OVERRIDE;
virtual void RenderViewReady() OVERRIDE; virtual void RenderViewReady() OVERRIDE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment