Commit a56e0932 authored by yoshiki's avatar yoshiki Committed by Commit bot

Fix window.close() in Athena

This patch makes AthenaWebView handle content::WebContentsDelegate::CloseContents().

BUG=412188
TEST=manual test

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

Cr-Commit-Position: refs/heads/master@{#300125}
parent a6edc5a7
...@@ -47,8 +47,11 @@ class WebActivityController : public AcceleratorHandler { ...@@ -47,8 +47,11 @@ class WebActivityController : public AcceleratorHandler {
CMD_STOP, CMD_STOP,
}; };
explicit WebActivityController(views::WebView* web_view) explicit WebActivityController(WebActivity* owner_activity,
: web_view_(web_view), reserved_accelerator_enabled_(true) {} views::WebView* web_view)
: owner_activity_(owner_activity),
web_view_(web_view),
reserved_accelerator_enabled_(true) {}
virtual ~WebActivityController() {} virtual ~WebActivityController() {}
// Installs accelerators for web activity. // Installs accelerators for web activity.
...@@ -136,7 +139,7 @@ class WebActivityController : public AcceleratorHandler { ...@@ -136,7 +139,7 @@ class WebActivityController : public AcceleratorHandler {
web_view_->GetWebContents()->GetController().GoForward(); web_view_->GetWebContents()->GetController().GoForward();
return true; return true;
case CMD_CLOSE: case CMD_CLOSE:
web_view_->GetWidget()->Close(); Activity::Delete(owner_activity_);
return true; return true;
case CMD_STOP: case CMD_STOP:
web_view_->GetWebContents()->Stop(); web_view_->GetWebContents()->Stop();
...@@ -145,6 +148,7 @@ class WebActivityController : public AcceleratorHandler { ...@@ -145,6 +148,7 @@ class WebActivityController : public AcceleratorHandler {
return false; return false;
} }
Activity* const owner_activity_;
views::WebView* web_view_; views::WebView* web_view_;
bool reserved_accelerator_enabled_; bool reserved_accelerator_enabled_;
scoped_ptr<AcceleratorManager> accelerator_manager_; scoped_ptr<AcceleratorManager> accelerator_manager_;
...@@ -164,9 +168,11 @@ const float kDistanceReload = 150; ...@@ -164,9 +168,11 @@ const float kDistanceReload = 150;
// own content so that it can eject and reload it. // own content so that it can eject and reload it.
class AthenaWebView : public views::WebView { class AthenaWebView : public views::WebView {
public: public:
explicit AthenaWebView(content::BrowserContext* context) explicit AthenaWebView(content::BrowserContext* context,
WebActivity* owner_activity)
: views::WebView(context), : views::WebView(context),
controller_(new WebActivityController(this)), controller_(new WebActivityController(owner_activity, this)),
owner_activity_(owner_activity),
fullscreen_(false), fullscreen_(false),
overscroll_y_(0) { overscroll_y_(0) {
SetEmbedFullscreenWidgetMode(true); SetEmbedFullscreenWidgetMode(true);
...@@ -174,9 +180,11 @@ class AthenaWebView : public views::WebView { ...@@ -174,9 +180,11 @@ class AthenaWebView : public views::WebView {
// content status to unloaded if that happens. // content status to unloaded if that happens.
} }
AthenaWebView(content::WebContents* web_contents) AthenaWebView(content::WebContents* web_contents,
WebActivity* owner_activity)
: views::WebView(web_contents->GetBrowserContext()), : views::WebView(web_contents->GetBrowserContext()),
controller_(new WebActivityController(this)) { controller_(new WebActivityController(owner_activity, this)),
owner_activity_(owner_activity) {
scoped_ptr<content::WebContents> old_contents( scoped_ptr<content::WebContents> old_contents(
SwapWebContents(scoped_ptr<content::WebContents>(web_contents))); SwapWebContents(scoped_ptr<content::WebContents>(web_contents)));
} }
...@@ -376,6 +384,10 @@ class AthenaWebView : public views::WebView { ...@@ -376,6 +384,10 @@ class AthenaWebView : public views::WebView {
return athena::OpenFileChooser(web_contents, params); return athena::OpenFileChooser(web_contents, params);
} }
virtual void CloseContents(content::WebContents* contents) override {
Activity::Delete(owner_activity_);
}
private: private:
void CreateProgressBar() { void CreateProgressBar() {
CHECK(!progress_bar_); CHECK(!progress_bar_);
...@@ -404,6 +416,8 @@ class AthenaWebView : public views::WebView { ...@@ -404,6 +416,8 @@ class AthenaWebView : public views::WebView {
scoped_ptr<WebActivityController> controller_; scoped_ptr<WebActivityController> controller_;
Activity* const owner_activity_;
// If the activity got evicted, this is the web content which holds the known // If the activity got evicted, this is the web content which holds the known
// state of the content before eviction. // state of the content before eviction.
scoped_ptr<content::WebContents> evicted_web_contents_; scoped_ptr<content::WebContents> evicted_web_contents_;
...@@ -426,7 +440,7 @@ WebActivity::WebActivity(content::BrowserContext* browser_context, ...@@ -426,7 +440,7 @@ WebActivity::WebActivity(content::BrowserContext* browser_context,
const base::string16& title, const base::string16& title,
const GURL& url) const GURL& url)
: browser_context_(browser_context), : browser_context_(browser_context),
web_view_(new AthenaWebView(browser_context)), web_view_(new AthenaWebView(browser_context, this)),
title_(title), title_(title),
title_color_(kDefaultTitleColor), title_color_(kDefaultTitleColor),
current_state_(ACTIVITY_UNLOADED), current_state_(ACTIVITY_UNLOADED),
...@@ -439,7 +453,7 @@ WebActivity::WebActivity(content::BrowserContext* browser_context, ...@@ -439,7 +453,7 @@ WebActivity::WebActivity(content::BrowserContext* browser_context,
WebActivity::WebActivity(content::WebContents* contents) WebActivity::WebActivity(content::WebContents* contents)
: browser_context_(contents->GetBrowserContext()), : browser_context_(contents->GetBrowserContext()),
web_view_(new AthenaWebView(contents)), web_view_(new AthenaWebView(contents, this)),
title_color_(kDefaultTitleColor), title_color_(kDefaultTitleColor),
current_state_(ACTIVITY_UNLOADED), current_state_(ACTIVITY_UNLOADED),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
......
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