Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1104)

Unified Diff: content/renderer/browser_plugin/browser_plugin.cc

Issue 10928237: Add support for parsing a 'partition' attribute on the <browser> tag. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moving to UTF-8 encoded strings and added test for multibyte characters. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/renderer/browser_plugin/browser_plugin.cc
diff --git a/content/renderer/browser_plugin/browser_plugin.cc b/content/renderer/browser_plugin/browser_plugin.cc
index 8ba5421f33aa700fe63e733024d9a5185ed74684..e144b3d3e7f3bbf979f4b1a9ecb5b6eaae0b9f16 100644
--- a/content/renderer/browser_plugin/browser_plugin.cc
+++ b/content/renderer/browser_plugin/browser_plugin.cc
@@ -6,6 +6,7 @@
#include "base/message_loop.h"
#include "base/string_util.h"
+#include "base/utf_string_conversions.h"
#include "content/common/browser_plugin_messages.h"
#include "content/public/common/content_client.h"
#include "content/public/renderer/content_renderer_client.h"
@@ -40,6 +41,7 @@ namespace {
const char kCrashEventName[] = "crash";
const char kNavigationEventName[] = "navigation";
const char* kSrcAttribute = "src";
+const char* kPartitionAttribute = "partition";
}
BrowserPlugin::BrowserPlugin(
@@ -54,13 +56,13 @@ BrowserPlugin::BrowserPlugin(
sad_guest_(NULL),
guest_crashed_(false),
resize_pending_(false),
- parent_frame_(frame->identifier()) {
+ parent_frame_(frame->identifier()),
+ has_navigated_(false),
+ persist_storage_(false) {
BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this);
bindings_.reset(new BrowserPluginBindings(this));
- std::string src;
- if (ParseSrcAttribute(params, &src))
- SetSrcAttribute(src);
+ ParseAttributes(params);
}
BrowserPlugin::~BrowserPlugin() {
@@ -97,23 +99,75 @@ void BrowserPlugin::SetSrcAttribute(const std::string& src) {
instance_id_,
parent_frame_,
src));
+ has_navigated_ = true;
}
src_ = src;
guest_crashed_ = false;
}
-bool BrowserPlugin::ParseSrcAttribute(
- const WebKit::WebPluginParams& params,
- std::string* src) {
+std::string BrowserPlugin::GetPartitionAttribute() const {
+ std::string value;
+ if (persist_storage_)
+ value.append("persist:");
Charlie Reis 2012/09/18 22:09:33 This should be a constant at the top of the file.
nasko 2012/09/18 22:56:20 Done.
+
+ value.append(storage_partition_id_);
+ return value;
+}
+
+bool BrowserPlugin::SetPartitionAttribute(const std::string& partition_id,
+ std::string& error_message) {
+ if (has_navigated_) {
+ error_message = "The object has already navigated.";
Charlie Reis 2012/09/18 22:09:33 Can we provide a little more to help the developer
nasko 2012/09/18 22:56:20 Done.
+ return false;
+ }
+ if (!storage_partition_id_.empty()) {
+ error_message = "The partition attribute has already been set.";
Charlie Reis 2012/09/18 22:09:33 Why is this an error? Couldn't you safely set it
nasko 2012/09/18 22:56:20 I would like to disallow setting it multiple times
Charlie Reis 2012/09/19 00:06:31 That seems like an unnecessary restriction to me,
nasko 2012/09/19 17:03:23 Done.
+ return false;
+ }
+
+ std::string input = partition_id;
+ std::string persist_prefix("persist:");
+
+ // Since the "persist:" prefix is in ASCII, StartsWith will work fine on
+ // UTF-8 encoded |partition_id|. If the prefix is a match, we can safely
+ // remove the prefix without splicing in the middle of a multi-byte codepoint.
+ // We can use the rest of the string as UTF-8 encoded one.
Charlie Reis 2012/09/18 22:09:33 Awesome comment.
nasko 2012/09/18 22:56:20 Credit goes to the master of awesomeness - ajwong!
+ if (StartsWithASCII(input, persist_prefix, true)) {
+ size_t index = input.find(":");
+ CHECK(index != std::string::npos);
+ // It is safe to do index + 1, since we tested for the full prefix above.
+ input = input.substr(index + 1);
+ if (input.empty()) {
+ error_message = "Invalid partition attribute.";
Charlie Reis 2012/09/18 22:09:33 Maybe "Invalid empty partition attribute"? This i
nasko 2012/09/18 22:56:20 Done.
+ return false;
+ }
+ persist_storage_ = true;
+ } else {
+ persist_storage_ = false;
+ }
+
+ storage_partition_id_ = input;
+ return true;
+}
+
+void BrowserPlugin::ParseAttributes(const WebKit::WebPluginParams& params) {
+ std::string src;
+
// Get the src attribute from the attributes vector
for (unsigned i = 0; i < params.attributeNames.size(); ++i) {
std::string attributeName = params.attributeNames[i].utf8();
if (LowerCaseEqualsASCII(attributeName, kSrcAttribute)) {
- *src = params.attributeValues[i].utf8();
- return true;
+ src = params.attributeValues[i].utf8();
+ } else if (LowerCaseEqualsASCII(attributeName, kPartitionAttribute)) {
+ std::string error;
+ SetPartitionAttribute(params.attributeValues[i].utf8(), error);
}
}
- return false;
+
+ // Set the 'src' attribute last, as it will set the has_navigated_ flag to
+ // true, which prevents changing the 'partition' attribute.
Charlie Reis 2012/09/18 22:09:33 Ah, good point.
nasko 2012/09/18 22:56:20 Done.
+ if (!src.empty())
+ SetSrcAttribute(src);
}
float BrowserPlugin::GetDeviceScaleFactor() const {

Powered by Google App Engine
This is Rietveld 408576698