summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormthiesse@chromium.org <mthiesse@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-05 01:42:19 +0000
committermthiesse@chromium.org <mthiesse@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-05 01:42:19 +0000
commita4197adc1699df5628e726c73c5a3b9dd67c9db2 (patch)
treed5665f23db95a9b0de43f365c57350b77e444061
parentac8bd041b81e46e4e4fcd5021aaa5499703952e6 (diff)
downloadchromium_src-a4197adc1699df5628e726c73c5a3b9dd67c9db2.zip
chromium_src-a4197adc1699df5628e726c73c5a3b9dd67c9db2.tar.gz
chromium_src-a4197adc1699df5628e726c73c5a3b9dd67c9db2.tar.bz2
BrowserPlugin - Change the setting of AutoSize attribute to follow HTML spec
Code is completed, new tests still need to be written. Existing tests ran (and passed): content_browsertests --gtest_filter="BrowserPlugin*" browser_tests --gtest_filter="WebViewTest*" BUG= Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=180442 Review URL: https://chromiumcodereview.appspot.com/12049018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@180602 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/renderer/resources/extensions/web_view.js4
-rw-r--r--content/browser/browser_plugin/browser_plugin_host_browsertest.cc117
-rw-r--r--content/renderer/browser_plugin/browser_plugin.cc56
-rw-r--r--content/renderer/browser_plugin/browser_plugin.h7
-rw-r--r--content/renderer/browser_plugin/browser_plugin_bindings.cc106
-rw-r--r--content/renderer/browser_plugin/browser_plugin_bindings.h1
-rw-r--r--content/renderer/browser_plugin/browser_plugin_browsertest.cc26
-rw-r--r--content/renderer/browser_plugin/browser_plugin_constants.cc12
-rw-r--r--content/renderer/browser_plugin/browser_plugin_constants.h1
9 files changed, 267 insertions, 63 deletions
diff --git a/chrome/renderer/resources/extensions/web_view.js b/chrome/renderer/resources/extensions/web_view.js
index 68bd3da..73f4f1a 100644
--- a/chrome/renderer/resources/extensions/web_view.js
+++ b/chrome/renderer/resources/extensions/web_view.js
@@ -9,8 +9,8 @@
var watchForTag = require("tagWatcher").watchForTag;
-var WEB_VIEW_ATTRIBUTES = ['name', 'src', 'partition', 'autoSize', 'minHeight',
- 'minWidth', 'maxHeight', 'maxWidth'];
+var WEB_VIEW_ATTRIBUTES = ['name', 'src', 'partition', 'autosize', 'minheight',
+ 'minwidth', 'maxheight', 'maxwidth'];
// All exposed api methods for <webview>, these are forwarded to the browser
// plugin.
diff --git a/content/browser/browser_plugin/browser_plugin_host_browsertest.cc b/content/browser/browser_plugin/browser_plugin_host_browsertest.cc
index b99188f..3824c35 100644
--- a/content/browser/browser_plugin/browser_plugin_host_browsertest.cc
+++ b/content/browser/browser_plugin/browser_plugin_host_browsertest.cc
@@ -5,6 +5,7 @@
#include "base/command_line.h"
#include "base/memory/singleton.h"
#include "base/run_loop.h"
+#include "base/string_split.h"
#include "base/test/test_timeouts.h"
#include "base/utf_string_conversions.h"
#include "content/browser/browser_plugin/browser_plugin_guest.h"
@@ -279,6 +280,23 @@ class BrowserPluginHostTest : public ContentBrowserTest {
content::ExecuteScriptAndGetValue(rvh, jscript);
}
+ bool IsAttributeNull(RenderViewHost* rvh, const std::string& attribute) {
+ scoped_ptr<base::Value> value = content::ExecuteScriptAndGetValue(rvh,
+ "document.getElementById('plugin').getAttribute('" + attribute + "');");
+ return value->GetType() == Value::TYPE_NULL;
+ }
+
+ // Removes all attributes in the comma-delimited string |attributes|.
+ void RemoveAttributes(RenderViewHost* rvh, const std::string& attributes) {
+ std::vector<std::string> attributes_list;
+ base::SplitString(attributes, ',', &attributes_list);
+ std::vector<std::string>::const_iterator itr;
+ for (itr = attributes_list.begin(); itr != attributes_list.end(); ++itr) {
+ ExecuteSyncJSFunction(rvh, "document.getElementById('plugin')"
+ "." + *itr + " = null;");
+ }
+ }
+
// This helper method does the following:
// 1. Start the test server and navigate the shell to |embedder_url|.
// 2. Execute custom pre-navigation |embedder_code| if provided.
@@ -1168,11 +1186,11 @@ IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, FocusTracksEmbedder) {
IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AutoSizeBeforeNavigation) {
const char* kEmbedderURL = "files/browser_plugin_embedder.html";
const std::string embedder_code =
- "document.getElementById('plugin').minWidth = 300;"
- "document.getElementById('plugin').minHeight = 200;"
- "document.getElementById('plugin').maxWidth = 600;"
- "document.getElementById('plugin').maxHeight = 400;"
- "document.getElementById('plugin').autoSize = true;";
+ "document.getElementById('plugin').minwidth = 300;"
+ "document.getElementById('plugin').minheight = 200;"
+ "document.getElementById('plugin').maxwidth = 600;"
+ "document.getElementById('plugin').maxheight = 400;"
+ "document.getElementById('plugin').autosize = true;";
StartBrowserPluginTest(
kEmbedderURL, kHTMLForGuestWithSize, true, embedder_code);
// Verify that the guest has been auto-sized.
@@ -1194,28 +1212,28 @@ IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AutoSizeAfterNavigation) {
expected_title);
ExecuteSyncJSFunction(
rvh,
- "document.getElementById('plugin').minWidth = 300;"
- "document.getElementById('plugin').minHeight = 200;"
- "document.getElementById('plugin').maxWidth = 600;"
- "document.getElementById('plugin').maxHeight = 400;"
- "document.getElementById('plugin').autoSize = true;");
+ "document.getElementById('plugin').minwidth = 300;"
+ "document.getElementById('plugin').minheight = 200;"
+ "document.getElementById('plugin').maxwidth = 600;"
+ "document.getElementById('plugin').maxheight = 400;"
+ "document.getElementById('plugin').autosize = true;");
string16 actual_title = title_watcher.WaitAndGetTitle();
EXPECT_EQ(expected_title, actual_title);
}
{
- // Change the minWidth and verify that it causes relayout.
+ // Change the minwidth and verify that it causes relayout.
const string16 expected_title = ASCIIToUTF16("AutoSize(350, 400)");
content::TitleWatcher title_watcher(test_embedder()->web_contents(),
expected_title);
ExecuteSyncJSFunction(
- rvh, "document.getElementById('plugin').minWidth = 350;");
+ rvh, "document.getElementById('plugin').minwidth = 350;");
string16 actual_title = title_watcher.WaitAndGetTitle();
EXPECT_EQ(expected_title, actual_title);
}
{
// Turn off autoSize and verify that the guest resizes to fit the container.
ExecuteSyncJSFunction(
- rvh, "document.getElementById('plugin').autoSize = false;");
+ rvh, "document.getElementById('plugin').autosize = null;");
test_guest()->WaitForViewSize(gfx::Size(640, 480));
}
}
@@ -1279,4 +1297,77 @@ IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, ChangeWindowName) {
}
}
+// This test verifies that all autosize attributes can be removed
+// without crashing the plugin, or throwing errors.
+IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, RemoveAutosizeAttributes) {
+ const char* kEmbedderURL = "files/browser_plugin_embedder.html";
+ const std::string embedder_code =
+ "document.getElementById('plugin').minwidth = 300;"
+ "document.getElementById('plugin').minheight = 200;"
+ "document.getElementById('plugin').maxwidth = 600;"
+ "document.getElementById('plugin').maxheight = 400;"
+ "document.getElementById('plugin').name = 'name';"
+ "document.getElementById('plugin').src = 'foo';"
+ "document.getElementById('plugin').autosize = '';";
+ StartBrowserPluginTest(
+ kEmbedderURL, kHTMLForGuestWithSize, true, embedder_code);
+ RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
+ test_embedder()->web_contents()->GetRenderViewHost());
+ RemoveAttributes(rvh, "maxheight, maxwidth, minheight, minwidth, autosize");
+
+ // Verify that the guest resizes to fit the container (and hasn't crashed).
+ test_guest()->WaitForViewSize(gfx::Size(640, 480));
+ EXPECT_TRUE(IsAttributeNull(rvh, "maxheight"));
+ EXPECT_TRUE(IsAttributeNull(rvh, "maxwidth"));
+ EXPECT_TRUE(IsAttributeNull(rvh, "minheight"));
+ EXPECT_TRUE(IsAttributeNull(rvh, "minwidth"));
+ EXPECT_TRUE(IsAttributeNull(rvh, "autosize"));
+}
+
+// This test verifies that autosize works when some of the parameters are unset.
+IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, PartialAutosizeAttributes) {
+ const char* kEmbedderURL = "files/browser_plugin_embedder.html";
+ const std::string embedder_code =
+ "document.getElementById('plugin').minwidth = 300;"
+ "document.getElementById('plugin').minheight = 200;"
+ "document.getElementById('plugin').maxwidth = 700;"
+ "document.getElementById('plugin').maxheight = 600;"
+ "document.getElementById('plugin').autosize = '';";
+ StartBrowserPluginTest(
+ kEmbedderURL, kHTMLForGuestWithSize, true, embedder_code);
+ RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
+ test_embedder()->web_contents()->GetRenderViewHost());
+ {
+ // Remove an autosize attribute and verify that it causes relayout.
+ const string16 expected_title = ASCIIToUTF16("AutoSize(640, 400)");
+ content::TitleWatcher title_watcher(test_embedder()->web_contents(),
+ expected_title);
+ RemoveAttributes(rvh, "minwidth");
+ string16 actual_title = title_watcher.WaitAndGetTitle();
+ EXPECT_EQ(expected_title, actual_title);
+ }
+ {
+ // Remove an autosize attribute and verify that it causes relayout.
+ // Also tests that when minwidth > maxwidth, minwidth = maxwidth.
+ const string16 expected_title = ASCIIToUTF16("AutoSize(700, 480)");
+ content::TitleWatcher title_watcher(test_embedder()->web_contents(),
+ expected_title);
+ RemoveAttributes(rvh, "maxheight");
+ ExecuteSyncJSFunction(
+ rvh, "document.getElementById('plugin').minwidth = 800;"
+ "document.getElementById('plugin').minheight = 800;");
+ string16 actual_title = title_watcher.WaitAndGetTitle();
+ EXPECT_EQ(expected_title, actual_title);
+ }
+ {
+ // Remove maxwidth and make sure the size returns to plugin size.
+ const string16 expected_title = ASCIIToUTF16("AutoSize(640, 480)");
+ content::TitleWatcher title_watcher(test_embedder()->web_contents(),
+ expected_title);
+ RemoveAttributes(rvh, "maxwidth");
+ string16 actual_title = title_watcher.WaitAndGetTitle();
+ EXPECT_EQ(expected_title, actual_title);
+ }
+}
+
} // namespace content
diff --git a/content/renderer/browser_plugin/browser_plugin.cc b/content/renderer/browser_plugin/browser_plugin.cc
index 6798d96..0dbc53f 100644
--- a/content/renderer/browser_plugin/browser_plugin.cc
+++ b/content/renderer/browser_plugin/browser_plugin.cc
@@ -147,27 +147,37 @@ void BrowserPlugin::UpdateDOMAttribute(const std::string& attribute_name,
WebKit::WebElement element = container()->element();
WebKit::WebString web_attribute_name =
WebKit::WebString::fromUTF8(attribute_name);
- std::string current_value(element.getAttribute(web_attribute_name).utf8());
- if (current_value == attribute_value)
- return;
-
- if (attribute_value.empty()) {
- element.removeAttribute(web_attribute_name);
- } else {
+ if (!HasDOMAttribute(attribute_name) ||
+ (std::string(element.getAttribute(web_attribute_name).utf8()) !=
+ attribute_value)) {
element.setAttribute(web_attribute_name,
WebKit::WebString::fromUTF8(attribute_value));
}
}
+void BrowserPlugin::RemoveDOMAttribute(const std::string& attribute_name) {
+ if (!container())
+ return;
+
+ container()->element().removeAttribute(
+ WebKit::WebString::fromUTF8(attribute_name));
+}
+
std::string BrowserPlugin::GetDOMAttributeValue(
const std::string& attribute_name) const {
if (!container())
return "";
- WebKit::WebElement element = container()->element();
- WebKit::WebString web_attribute_name =
- WebKit::WebString::fromUTF8(attribute_name);
- return element.getAttribute(web_attribute_name).utf8();
+ return container()->element().getAttribute(
+ WebKit::WebString::fromUTF8(attribute_name)).utf8();
+}
+
+bool BrowserPlugin::HasDOMAttribute(const std::string& attribute_name) const {
+ if (!container())
+ return false;
+
+ return container()->element().hasAttribute(
+ WebKit::WebString::fromUTF8(attribute_name));
}
std::string BrowserPlugin::GetNameAttribute() const {
@@ -179,7 +189,7 @@ std::string BrowserPlugin::GetSrcAttribute() const {
}
bool BrowserPlugin::GetAutoSizeAttribute() const {
- return GetDOMAttributeValue(browser_plugin::kAttributeAutoSize) == "true";
+ return HasDOMAttribute(browser_plugin::kAttributeAutoSize);
}
int BrowserPlugin::GetMaxHeightAttribute() const {
@@ -221,13 +231,21 @@ int BrowserPlugin::GetAdjustedMaxWidth() const {
}
int BrowserPlugin::GetAdjustedMinHeight() const {
- // For autosize, minheight should not be bigger than maxheight.
- return std::min(GetMinHeightAttribute(), GetAdjustedMaxHeight());
+ int min_height = GetMinHeightAttribute();
+ // FrameView.cpp does not allow this value to be <= 0, so when the value is
+ // unset (or set to 0), we set it to the container size.
+ min_height = min_height ? min_height : height();
+ // For autosize, minHeight should not be bigger than maxHeight.
+ return std::min(min_height, GetAdjustedMaxHeight());
}
int BrowserPlugin::GetAdjustedMinWidth() const {
- // For autosize, minwidth should not be bigger than maxwidth.
- return std::min(GetMinWidthAttribute(), GetAdjustedMaxWidth());
+ int min_width = GetMinWidthAttribute();
+ // FrameView.cpp does not allow this value to be <= 0, so when the value is
+ // unset (or set to 0), we set it to the container size.
+ min_width = min_width ? min_width : width();
+ // For autosize, minWidth should not be bigger than maxWidth.
+ return std::min(min_width, GetAdjustedMaxWidth());
}
std::string BrowserPlugin::GetPartitionAttribute() const {
@@ -708,6 +726,12 @@ bool BrowserPlugin::ParsePartitionAttribute(std::string* error_message) {
return true;
}
+bool BrowserPlugin::CanRemovePartitionAttribute(std::string* error_message) {
+ if (navigate_src_sent_)
+ *error_message = browser_plugin::kErrorCannotRemovePartition;
+ return !navigate_src_sent_;
+}
+
void BrowserPlugin::ParseAttributes() {
// TODO(mthiesse): Handle errors here?
std::string error;
diff --git a/content/renderer/browser_plugin/browser_plugin.h b/content/renderer/browser_plugin/browser_plugin.h
index 571804f..17dcdcf 100644
--- a/content/renderer/browser_plugin/browser_plugin.h
+++ b/content/renderer/browser_plugin/browser_plugin.h
@@ -42,9 +42,12 @@ class CONTENT_EXPORT BrowserPlugin :
// |attribute_value|.
void UpdateDOMAttribute(const std::string& attribute_name,
const std::string& attribute_value);
-
+ // Remove the DOM Node attribute with the name |attribute_name|.
+ void RemoveDOMAttribute(const std::string& attribute_name);
// Get Browser Plugin's DOM Node attribute |attribute_name|'s value.
std::string GetDOMAttributeValue(const std::string& attribute_name) const;
+ // Checks if the attribute |attribute_name| exists in the DOM.
+ bool HasDOMAttribute(const std::string& attribute_name) const;
// Get the name attribute value.
std::string GetNameAttribute() const;
@@ -74,6 +77,8 @@ class CONTENT_EXPORT BrowserPlugin :
// this instance of BrowserPlugin. If an error occurs, the |error_message| is
// set appropriately to indicate the failure reason.
bool ParsePartitionAttribute(std::string* error_message);
+ // True if the partition attribute can be removed.
+ bool CanRemovePartitionAttribute(std::string* error_message);
bool InAutoSizeBounds(const gfx::Size& size) const;
diff --git a/content/renderer/browser_plugin/browser_plugin_bindings.cc b/content/renderer/browser_plugin/browser_plugin_bindings.cc
index 2ac280b..142adc9 100644
--- a/content/renderer/browser_plugin/browser_plugin_bindings.cc
+++ b/content/renderer/browser_plugin/browser_plugin_bindings.cc
@@ -158,6 +158,9 @@ bool BrowserPluginBindingsSetProperty(NPObject* np_obj, NPIdentifier name,
if (!bindings)
return false;
+ if (variant->type == NPVariantType_Null)
+ return bindings->RemoveProperty(np_obj, name);
+
return bindings->SetProperty(np_obj, name, variant);
}
@@ -401,11 +404,33 @@ class BrowserPluginPropertyBinding {
virtual bool SetProperty(BrowserPluginBindings* bindings,
NPObject* np_obj,
const NPVariant* variant) = 0;
+ virtual void RemoveProperty(BrowserPluginBindings* bindings,
+ NPObject* np_obj) = 0;
// Updates the DOM Attribute value with the current property value.
void UpdateDOMAttribute(BrowserPluginBindings* bindings,
std::string new_value) {
bindings->instance()->UpdateDOMAttribute(name(), new_value);
}
+ protected:
+ // Depending on where the attribute comes from it could be a string, int32,
+ // or a double. Javascript tends to produce an Int32 or a String, but setting
+ // the value from the developer tools console may also produce a Double...
+ int IntFromNPVariant(const NPVariant* variant) {
+ int value;
+ switch (variant->type) {
+ case NPVariantType_Double:
+ case NPVariantType_Int32:
+ value = Int32FromNPVariant(*variant);
+ break;
+ case NPVariantType_String:
+ base::StringToInt(StringFromNPVariant(*variant), &value);
+ break;
+ default:
+ value = 0;
+ break;
+ }
+ return value;
+ }
private:
std::string name_;
@@ -427,19 +452,20 @@ class BrowserPluginPropertyBindingAutoSize
virtual bool SetProperty(BrowserPluginBindings* bindings,
NPObject* np_obj,
const NPVariant* variant) OVERRIDE {
- bool new_value;
- if (variant->type == NPVariantType_Bool) {
- new_value = NPVARIANT_TO_BOOLEAN(*variant);
- } else {
- new_value = LowerCaseEqualsASCII(std::string(
- NPVARIANT_TO_STRING(*variant).UTF8Characters), "true");
- }
- if (bindings->instance()->GetAutoSizeAttribute() != new_value) {
- UpdateDOMAttribute(bindings, new_value ? "true" : "false");
+ std::string value = StringFromNPVariant(*variant);
+ if (!bindings->instance()->HasDOMAttribute(name())) {
+ UpdateDOMAttribute(bindings, value);
bindings->instance()->ParseAutoSizeAttribute();
+ } else {
+ UpdateDOMAttribute(bindings, value);
}
return true;
}
+ virtual void RemoveProperty(BrowserPluginBindings* bindings,
+ NPObject* np_obj) OVERRIDE {
+ bindings->instance()->RemoveDOMAttribute(name());
+ bindings->instance()->ParseAutoSizeAttribute();
+ }
private:
DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingAutoSize);
};
@@ -464,6 +490,8 @@ class BrowserPluginPropertyBindingContentWindow
const NPVariant* variant) OVERRIDE {
return false;
}
+ virtual void RemoveProperty(BrowserPluginBindings* bindings,
+ NPObject* np_obj) OVERRIDE {}
private:
DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingContentWindow);
};
@@ -483,13 +511,18 @@ class BrowserPluginPropertyBindingMaxHeight
virtual bool SetProperty(BrowserPluginBindings* bindings,
NPObject* np_obj,
const NPVariant* variant) OVERRIDE {
- int new_value = Int32FromNPVariant(*variant);
+ int new_value = IntFromNPVariant(variant);
if (bindings->instance()->GetMaxHeightAttribute() != new_value) {
UpdateDOMAttribute(bindings, base::IntToString(new_value));
bindings->instance()->ParseSizeContraintsChanged();
}
return true;
}
+ virtual void RemoveProperty(BrowserPluginBindings* bindings,
+ NPObject* np_obj) OVERRIDE {
+ bindings->instance()->RemoveDOMAttribute(name());
+ bindings->instance()->ParseSizeContraintsChanged();
+ }
private:
DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMaxHeight);
};
@@ -509,13 +542,18 @@ class BrowserPluginPropertyBindingMaxWidth
virtual bool SetProperty(BrowserPluginBindings* bindings,
NPObject* np_obj,
const NPVariant* variant) OVERRIDE {
- int new_value = Int32FromNPVariant(*variant);
+ int new_value = IntFromNPVariant(variant);
if (bindings->instance()->GetMaxWidthAttribute() != new_value) {
UpdateDOMAttribute(bindings, base::IntToString(new_value));
bindings->instance()->ParseSizeContraintsChanged();
}
return true;
}
+ virtual void RemoveProperty(BrowserPluginBindings* bindings,
+ NPObject* np_obj) OVERRIDE {
+ bindings->instance()->RemoveDOMAttribute(name());
+ bindings->instance()->ParseSizeContraintsChanged();
+ }
private:
DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMaxWidth);
};
@@ -535,13 +573,18 @@ class BrowserPluginPropertyBindingMinHeight
virtual bool SetProperty(BrowserPluginBindings* bindings,
NPObject* np_obj,
const NPVariant* variant) OVERRIDE {
- int new_value = Int32FromNPVariant(*variant);
+ int new_value = IntFromNPVariant(variant);
if (bindings->instance()->GetMinHeightAttribute() != new_value) {
UpdateDOMAttribute(bindings, base::IntToString(new_value));
bindings->instance()->ParseSizeContraintsChanged();
}
return true;
}
+ virtual void RemoveProperty(BrowserPluginBindings* bindings,
+ NPObject* np_obj) OVERRIDE {
+ bindings->instance()->RemoveDOMAttribute(name());
+ bindings->instance()->ParseSizeContraintsChanged();
+ }
private:
DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinHeight);
};
@@ -561,13 +604,18 @@ class BrowserPluginPropertyBindingMinWidth
virtual bool SetProperty(BrowserPluginBindings* bindings,
NPObject* np_obj,
const NPVariant* variant) OVERRIDE {
- int new_value = Int32FromNPVariant(*variant);
+ int new_value = IntFromNPVariant(variant);
if (bindings->instance()->GetMinWidthAttribute() != new_value) {
UpdateDOMAttribute(bindings, base::IntToString(new_value));
bindings->instance()->ParseSizeContraintsChanged();
}
return true;
}
+ virtual void RemoveProperty(BrowserPluginBindings* bindings,
+ NPObject* np_obj) OVERRIDE {
+ bindings->instance()->RemoveDOMAttribute(name());
+ bindings->instance()->ParseSizeContraintsChanged();
+ }
private:
DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinWidth);
};
@@ -594,6 +642,11 @@ class BrowserPluginPropertyBindingName
}
return true;
}
+ virtual void RemoveProperty(BrowserPluginBindings* bindings,
+ NPObject* np_obj) OVERRIDE {
+ bindings->instance()->RemoveDOMAttribute(name());
+ bindings->instance()->ParseNameAttribute();
+ }
private:
DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingName);
};
@@ -627,6 +680,16 @@ class BrowserPluginPropertyBindingPartition
}
return true;
}
+ virtual void RemoveProperty(BrowserPluginBindings* bindings,
+ NPObject* np_obj) OVERRIDE {
+ std::string error_message;
+ if (bindings->instance()->CanRemovePartitionAttribute(&error_message)) {
+ bindings->instance()->RemoveDOMAttribute(name());
+ } else {
+ WebBindings::setException(
+ np_obj, static_cast<const NPUTF8 *>(error_message.c_str()));
+ }
+ }
private:
DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingPartition);
};
@@ -659,6 +722,10 @@ class BrowserPluginPropertyBindingSrc : public BrowserPluginPropertyBinding {
}
return true;
}
+ virtual void RemoveProperty(BrowserPluginBindings* bindings,
+ NPObject* np_obj) OVERRIDE {
+ bindings->instance()->RemoveDOMAttribute(name());
+ }
private:
DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingSrc);
};
@@ -756,6 +823,19 @@ bool BrowserPluginBindings::SetProperty(NPObject* np_obj,
return false;
}
+bool BrowserPluginBindings::RemoveProperty(NPObject* np_obj,
+ NPIdentifier name) {
+ for (PropertyBindingList::iterator iter = property_bindings_.begin();
+ iter != property_bindings_.end();
+ ++iter) {
+ if ((*iter)->MatchesName(name)) {
+ (*iter)->RemoveProperty(this, np_obj);
+ return true;
+ }
+ }
+ return false;
+}
+
bool BrowserPluginBindings::GetProperty(NPIdentifier name, NPVariant* result) {
for (PropertyBindingList::iterator iter = property_bindings_.begin();
iter != property_bindings_.end();
diff --git a/content/renderer/browser_plugin/browser_plugin_bindings.h b/content/renderer/browser_plugin/browser_plugin_bindings.h
index 43bd4c2..91e8ced 100644
--- a/content/renderer/browser_plugin/browser_plugin_bindings.h
+++ b/content/renderer/browser_plugin/browser_plugin_bindings.h
@@ -48,6 +48,7 @@ class BrowserPluginBindings {
NPIdentifier name,
const NPVariant* variant);
bool GetProperty(NPIdentifier name, NPVariant* result);
+ bool RemoveProperty(NPObject *np_obj, NPIdentifier name);
private:
BrowserPlugin* instance_;
// The NPObject we use to expose postMessage to JavaScript.
diff --git a/content/renderer/browser_plugin/browser_plugin_browsertest.cc b/content/renderer/browser_plugin/browser_plugin_browsertest.cc
index 3e1898a..35b4a36 100644
--- a/content/renderer/browser_plugin/browser_plugin_browsertest.cc
+++ b/content/renderer/browser_plugin/browser_plugin_browsertest.cc
@@ -28,8 +28,8 @@ const char kHTMLForBrowserPluginObject[] =
const char kHTMLForBrowserPluginWithAllAttributes[] =
"<object id='browserplugin' width='640' height='480' type='%s'"
- " autoSize='true' maxHeight='600' maxWidth='800' minHeight='240'"
- " minWidth='320' name='Jim' partition='someid' src='foo'>";
+ " autosize maxheight='600' maxwidth='800' minheight='240'"
+ " minwidth='320' name='Jim' partition='someid' src='foo'>";
const char kHTMLForSourcelessPluginObject[] =
"<object id='browserplugin' width='640px' height='480px' type='%s'>";
@@ -185,20 +185,20 @@ TEST_F(BrowserPluginTest, ParseAllAttributes) {
LoadHTML(html.c_str());
bool result;
bool has_value = ExecuteScriptAndReturnBool(
- "document.getElementById('browserplugin').autoSize", &result);
+ "document.getElementById('browserplugin').autosize", &result);
EXPECT_TRUE(has_value);
EXPECT_TRUE(result);
int maxHeight = ExecuteScriptAndReturnInt(
- "document.getElementById('browserplugin').maxHeight");
+ "document.getElementById('browserplugin').maxheight");
EXPECT_EQ(600, maxHeight);
int maxWidth = ExecuteScriptAndReturnInt(
- "document.getElementById('browserplugin').maxWidth");
+ "document.getElementById('browserplugin').maxwidth");
EXPECT_EQ(800, maxWidth);
int minHeight = ExecuteScriptAndReturnInt(
- "document.getElementById('browserplugin').minHeight");
+ "document.getElementById('browserplugin').minheight");
EXPECT_EQ(240, minHeight);
int minWidth = ExecuteScriptAndReturnInt(
- "document.getElementById('browserplugin').minWidth");
+ "document.getElementById('browserplugin').minwidth");
EXPECT_EQ(320, minWidth);
std::string name = ExecuteScriptAndReturnString(
"document.getElementById('browserplugin').name");
@@ -815,14 +815,14 @@ TEST_F(BrowserPluginTest, AutoSizeAttributes) {
LoadHTML(html.c_str());
const char* kSetAutoSizeParametersAndNavigate =
"var browserplugin = document.getElementById('browserplugin');"
- "browserplugin.autoSize = true;"
- "browserplugin.minWidth = 42;"
- "browserplugin.minHeight = 43;"
- "browserplugin.maxWidth = 1337;"
- "browserplugin.maxHeight = 1338;"
+ "browserplugin.autosize = true;"
+ "browserplugin.minwidth = 42;"
+ "browserplugin.minheight = 43;"
+ "browserplugin.maxwidth = 1337;"
+ "browserplugin.maxheight = 1338;"
"browserplugin.src = 'foobar';";
const char* kDisableAutoSize =
- "document.getElementById('browserplugin').autoSize = false;";
+ "document.getElementById('browserplugin').removeAttribute('autosize');";
int instance_id = 0;
// Set some autosize parameters before navigating then navigate.
diff --git a/content/renderer/browser_plugin/browser_plugin_constants.cc b/content/renderer/browser_plugin/browser_plugin_constants.cc
index 8b3551b..92ed335 100644
--- a/content/renderer/browser_plugin/browser_plugin_constants.cc
+++ b/content/renderer/browser_plugin/browser_plugin_constants.cc
@@ -21,12 +21,12 @@ const char kMethodStop[] = "stop";
const char kMethodTerminate[] = "terminate";
// Attributes.
-const char kAttributeAutoSize[] = "autoSize";
+const char kAttributeAutoSize[] = "autosize";
const char kAttributeContentWindow[] = "contentWindow";
-const char kAttributeMaxHeight[] = "maxHeight";
-const char kAttributeMaxWidth[] = "maxWidth";
-const char kAttributeMinHeight[] = "minHeight";
-const char kAttributeMinWidth[] = "minWidth";
+const char kAttributeMaxHeight[] = "maxheight";
+const char kAttributeMaxWidth[] = "maxwidth";
+const char kAttributeMinHeight[] = "minheight";
+const char kAttributeMinWidth[] = "minwidth";
const char kAttributeName[] = "name";
const char kAttributePartition[] = "partition";
const char kAttributeSrc[] = "src";
@@ -60,6 +60,8 @@ const char kErrorAlreadyNavigated[] =
"The object has already navigated, so its partition cannot be changed.";
const char kErrorInvalidPartition[] =
"Invalid partition attribute.";
+const char kErrorCannotRemovePartition[] =
+ "Cannot remove partition attribute after navigating.";
// Other.
const int kInstanceIDNone = 0;
diff --git a/content/renderer/browser_plugin/browser_plugin_constants.h b/content/renderer/browser_plugin/browser_plugin_constants.h
index b50a0b2..6219151 100644
--- a/content/renderer/browser_plugin/browser_plugin_constants.h
+++ b/content/renderer/browser_plugin/browser_plugin_constants.h
@@ -59,6 +59,7 @@ extern const char kURL[];
// Error messages.
extern const char kErrorAlreadyNavigated[];
extern const char kErrorInvalidPartition[];
+extern const char kErrorCannotRemovePartition[];
// Other.
extern const int kInstanceIDNone;