Commit c4a81629 authored by dcheng@chromium.org's avatar dcheng@chromium.org

Snapshot a pointer to the main frame when creating WebViewFrameWidget.

Otherwise, invoking WebViewFrameWidget::close() from frame swap will
result in trying to clear the frame widget on the wrong main frame.

Other miscellaneous fixes:
- WebViewFrameWidget now uses smart pointers where appropriate for its
  members.
- WebViewFrameWidget's ctor also takes a WebWidgetClient* pointer.
  This is future-proofing to help merge the widget implementations in
  WebFrameWidget and WebView.

BUG=419087

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

git-svn-id: svn://svn.chromium.org/blink/trunk@201048 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent f2719fda
...@@ -65,9 +65,9 @@ WebFrameWidget* WebFrameWidget::create(WebWidgetClient* client, WebLocalFrame* l ...@@ -65,9 +65,9 @@ WebFrameWidget* WebFrameWidget::create(WebWidgetClient* client, WebLocalFrame* l
return WebFrameWidgetImpl::create(client, localRoot); return WebFrameWidgetImpl::create(client, localRoot);
} }
WebFrameWidget* WebFrameWidget::create(WebView* webView) WebFrameWidget* WebFrameWidget::create(WebWidgetClient* client, WebView* webView, WebLocalFrame* mainFrame)
{ {
return new WebViewFrameWidget(*toWebViewImpl(webView)); return new WebViewFrameWidget(client, toWebViewImpl(*webView), toWebLocalFrameImpl(*mainFrame));
} }
WebFrameWidgetImpl* WebFrameWidgetImpl::create(WebWidgetClient* client, WebLocalFrame* localRoot) WebFrameWidgetImpl* WebFrameWidgetImpl::create(WebWidgetClient* client, WebLocalFrame* localRoot)
......
...@@ -10,9 +10,10 @@ ...@@ -10,9 +10,10 @@
namespace blink { namespace blink {
WebViewFrameWidget::WebViewFrameWidget(WebViewImpl& webView) : m_webView(&webView) WebViewFrameWidget::WebViewFrameWidget(WebWidgetClient* client, WebViewImpl& webView, WebLocalFrameImpl& mainFrame)
: m_client(client), m_webView(&webView), m_mainFrame(&mainFrame)
{ {
m_webView->mainFrameImpl()->setFrameWidget(this); m_mainFrame->setFrameWidget(this);
} }
WebViewFrameWidget::~WebViewFrameWidget() WebViewFrameWidget::~WebViewFrameWidget()
...@@ -21,8 +22,14 @@ WebViewFrameWidget::~WebViewFrameWidget() ...@@ -21,8 +22,14 @@ WebViewFrameWidget::~WebViewFrameWidget()
void WebViewFrameWidget::close() void WebViewFrameWidget::close()
{ {
m_webView->mainFrameImpl()->setFrameWidget(nullptr); // Note: it's important to use the captured main frame pointer here. During
// a frame swap, the swapped frame is detached *after* the frame tree is
// updated. If the main frame is being swapped, then
// m_webView()->mainFrameImpl() will no longer point to the original frame.
m_mainFrame->setFrameWidget(nullptr);
m_mainFrame = nullptr;
m_webView = nullptr; m_webView = nullptr;
m_client = nullptr;
// Note: this intentionally does not forward to WebView::close(), to make it // Note: this intentionally does not forward to WebView::close(), to make it
// easier to untangle the cleanup logic later. // easier to untangle the cleanup logic later.
......
...@@ -5,12 +5,16 @@ ...@@ -5,12 +5,16 @@
#ifndef WebViewFrameWidget_h #ifndef WebViewFrameWidget_h
#define WebViewFrameWidget_h #define WebViewFrameWidget_h
#include "platform/heap/Handle.h"
#include "public/web/WebFrameWidget.h" #include "public/web/WebFrameWidget.h"
#include "wtf/Noncopyable.h" #include "wtf/Noncopyable.h"
#include "wtf/RefPtr.h"
namespace blink { namespace blink {
class WebLocalFrameImpl;
class WebViewImpl; class WebViewImpl;
class WebWidgetClient;
// Shim class to help normalize the widget interfaces in the Blink public API. // Shim class to help normalize the widget interfaces in the Blink public API.
// For OOPI, subframes have WebFrameWidgets for input and rendering. // For OOPI, subframes have WebFrameWidgets for input and rendering.
...@@ -30,7 +34,7 @@ class WebViewImpl; ...@@ -30,7 +34,7 @@ class WebViewImpl;
class WebViewFrameWidget : public WebFrameWidget { class WebViewFrameWidget : public WebFrameWidget {
WTF_MAKE_NONCOPYABLE(WebViewFrameWidget); WTF_MAKE_NONCOPYABLE(WebViewFrameWidget);
public: public:
explicit WebViewFrameWidget(WebViewImpl&); explicit WebViewFrameWidget(WebWidgetClient*, WebViewImpl&, WebLocalFrameImpl&);
virtual ~WebViewFrameWidget(); virtual ~WebViewFrameWidget();
// WebFrameWidget overrides: // WebFrameWidget overrides:
...@@ -92,7 +96,9 @@ public: ...@@ -92,7 +96,9 @@ public:
bool forSubframe() const { return false; } bool forSubframe() const { return false; }
private: private:
WebViewImpl* m_webView; WebWidgetClient* m_client;
RefPtr<WebViewImpl> m_webView;
RefPtrWillBePersistent<WebLocalFrameImpl> m_mainFrame;
}; };
} // namespace blink } // namespace blink
......
...@@ -46,7 +46,8 @@ public: ...@@ -46,7 +46,8 @@ public:
BLINK_EXPORT static WebFrameWidget* create(WebWidgetClient*, WebLocalFrame*); BLINK_EXPORT static WebFrameWidget* create(WebWidgetClient*, WebLocalFrame*);
// Creates a frame widget for a WebView. Temporary helper to help transition // Creates a frame widget for a WebView. Temporary helper to help transition
// away from WebView inheriting WebWidget. // away from WebView inheriting WebWidget.
BLINK_EXPORT static WebFrameWidget* create(WebView*); // TODO(dcheng): Remove once transition is complete.
BLINK_EXPORT static WebFrameWidget* create(WebWidgetClient*, WebView*, WebLocalFrame* mainFrame);
// Sets the visibility of the WebFrameWidget. // Sets the visibility of the WebFrameWidget.
// We still track page-level visibility, but additionally we need to notify a WebFrameWidget // We still track page-level visibility, but additionally we need to notify a WebFrameWidget
......
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