Commit 3ae15dd6 authored by ericzeng@chromium.org's avatar ericzeng@chromium.org

Handle closing web contents in ExtensionOptionsGuest

Implement CloseContents for ExtensionOptionsGuest. CloseContents
propagates a 'close' event up to the <extensionoptions> node.
In WebUI, when the extension options overlay receives this event,
it will close the overlay.

Extension options pages that used window.close() to close their
tab in the old options page UI will now close their embedder
overlay.

BUG=386842, 386838

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

Cr-Commit-Position: refs/heads/master@{#291554}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@291554 0039d316-1c4b-4281-b951-d872f2087c98
parent 5a2284cf
...@@ -223,6 +223,24 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, CanEmbedExtensionOptions) { ...@@ -223,6 +223,24 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, CanEmbedExtensionOptions) {
ASSERT_TRUE(listener->WaitUntilSatisfied()); ASSERT_TRUE(listener->WaitUntilSatisfied());
} }
IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, ReceivesExtensionOptionsOnClose) {
scoped_ptr<ExtensionTestMessageListener> listener(
new ExtensionTestMessageListener("ready", true));
const Extension* extension =
InstallExtension(test_data_dir_.AppendASCII("extension_options")
.AppendASCII("close_self"), 1);
ASSERT_TRUE(extension);
ASSERT_TRUE(
RunTestOnExtensionsFrame("receives_extension_options_on_close.js"));
ASSERT_TRUE(listener->WaitUntilSatisfied());
listener->Reply(extension->id());
listener.reset(new ExtensionTestMessageListener("onclose received", false));
ASSERT_TRUE(listener->WaitUntilSatisfied());
}
} // namespace } // namespace
} // namespace extensions } // namespace extensions
...@@ -185,6 +185,12 @@ void ExtensionOptionsGuest::SetUpAutoSize() { ...@@ -185,6 +185,12 @@ void ExtensionOptionsGuest::SetUpAutoSize() {
true, gfx::Size(min_width, min_height), gfx::Size(max_width, max_height)); true, gfx::Size(min_width, min_height), gfx::Size(max_width, max_height));
} }
void ExtensionOptionsGuest::CloseContents(content::WebContents* source) {
DispatchEventToEmbedder(new extensions::GuestViewBase::Event(
extension_options_internal::OnClose::kEventName,
make_scoped_ptr(new base::DictionaryValue())));
}
bool ExtensionOptionsGuest::ShouldCreateWebContents( bool ExtensionOptionsGuest::ShouldCreateWebContents(
content::WebContents* web_contents, content::WebContents* web_contents,
int route_id, int route_id,
......
...@@ -41,6 +41,7 @@ class ExtensionOptionsGuest ...@@ -41,6 +41,7 @@ class ExtensionOptionsGuest
virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE; virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE;
// content::WebContentsDelegate implementation. // content::WebContentsDelegate implementation.
virtual void CloseContents(content::WebContents* source) OVERRIDE;
virtual bool ShouldCreateWebContents( virtual bool ShouldCreateWebContents(
content::WebContents* web_contents, content::WebContents* web_contents,
int route_id, int route_id,
......
...@@ -6,5 +6,5 @@ in the LICENSE file. ...@@ -6,5 +6,5 @@ in the LICENSE file.
<div id="extension-options-overlay" class="page"> <div id="extension-options-overlay" class="page">
<div class="close-button"></div> <div class="close-button"></div>
<h1 id="extension-options-overlay-title"></h1> <h1 id="extension-options-overlay-title"></h1>
<div class="extension-options-overlay-guest"></div> <div id="extension-options-overlay-guest"></div>
</div> </div>
...@@ -47,9 +47,12 @@ cr.define('extensions', function() { ...@@ -47,9 +47,12 @@ cr.define('extensions', function() {
*/ */
handleDismiss_: function(event) { handleDismiss_: function(event) {
this.setVisible_(false); this.setVisible_(false);
var extensionoptions = document.querySelector('extensionoptions'); var extensionoptions =
$('extension-options-overlay-guest')
.querySelector('extensionoptions');
if (extensionoptions) if (extensionoptions)
$('extension-options-overlay').removeChild(extensionoptions); $('extension-options-overlay-guest').removeChild(extensionoptions);
}, },
/** /**
...@@ -64,13 +67,17 @@ cr.define('extensions', function() { ...@@ -64,13 +67,17 @@ cr.define('extensions', function() {
extensionoptions.extension = extensionId; extensionoptions.extension = extensionId;
extensionoptions.autosize = 'on'; extensionoptions.autosize = 'on';
extensionoptions.onclose = function() {
this.handleDismiss_();
}.bind(this);
// TODO(ericzeng): Resize in a non-jarring way. // TODO(ericzeng): Resize in a non-jarring way.
extensionoptions.onsizechanged = function(evt) { extensionoptions.onsizechanged = function(evt) {
$('extension-options-overlay').style.width = evt.width; $('extension-options-overlay').style.width = evt.width;
$('extension-options-overlay').style.height = evt.height; $('extension-options-overlay').style.height = evt.height;
}.bind(this); }.bind(this);
$('extension-options-overlay').appendChild(extensionoptions); $('extension-options-overlay-guest').appendChild(extensionoptions);
$('extension-options-overlay-title').textContent = extensionName; $('extension-options-overlay-title').textContent = extensionName;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
// Internal API for the &lt;extensiontoptions&gt; tag // Internal API for the &lt;extensiontoptions&gt; tag
namespace extensionOptionsInternal { namespace extensionOptionsInternal {
interface Events { interface Events {
static void onClose();
static void onLoad(); static void onLoad();
static void onSizeChanged(long width, long height); static void onSizeChanged(long width, long height);
}; };
......
...@@ -10,6 +10,10 @@ var CreateEvent = function(name) { ...@@ -10,6 +10,10 @@ var CreateEvent = function(name) {
}; };
var EXTENSION_OPTIONS_EVENTS = { var EXTENSION_OPTIONS_EVENTS = {
'close': {
evt: CreateEvent('extensionOptionsInternal.onClose'),
fields: []
},
'load': { 'load': {
evt: CreateEvent('extensionOptionsInternal.onLoad'), evt: CreateEvent('extensionOptionsInternal.onLoad'),
fields: [] fields: []
......
{
"name": "close_self_test",
"version": "0.1",
"manifest_version": 2,
"options_page": "options.html",
"description": "Tests if close event is propagated to the embedder",
"permissions": [
"embeddedExtensionOptions"
]
}
<!--
* Copyright 2014 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.
-->
<html>
<body>
<script src="options.js"></script>
</body>
</html>
// Copyright 2014 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.
window.close();
// Copyright 2014 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.
// out/Debug/browser_tests
// --gtest_filter=ExtensionWebUITest.ReceivesExtensionOptionsOnClose
if (!chrome || !chrome.test || !chrome.test.sendMessage) {
console.error('chrome.test.sendMessage is unavailable on ' +
document.location.href);
domAutomationController.send(false);
return;
}
chrome.test.sendMessage('ready', function(reply) {
var extensionoptions = document.createElement('extensionoptions');
extensionoptions.onclose = function() {
chrome.test.sendMessage('onclose received');
};
extensionoptions.setAttribute('extension', reply);
document.body.appendChild(extensionoptions);
});
domAutomationController.send(true);
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