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

Side by Side 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: Fixes based on review from Charlie. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/browser_plugin/browser_plugin.h" 5 #include "content/renderer/browser_plugin/browser_plugin.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h"
9 #include "content/common/browser_plugin_messages.h" 10 #include "content/common/browser_plugin_messages.h"
10 #include "content/public/common/content_client.h" 11 #include "content/public/common/content_client.h"
11 #include "content/public/renderer/content_renderer_client.h" 12 #include "content/public/renderer/content_renderer_client.h"
12 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" 13 #include "content/renderer/browser_plugin/browser_plugin_bindings.h"
13 #include "content/renderer/browser_plugin/browser_plugin_manager.h" 14 #include "content/renderer/browser_plugin/browser_plugin_manager.h"
14 #include "content/renderer/render_process_impl.h" 15 #include "content/renderer/render_process_impl.h"
15 #include "content/renderer/render_thread_impl.h" 16 #include "content/renderer/render_thread_impl.h"
16 #include "skia/ext/platform_canvas.h" 17 #include "skia/ext/platform_canvas.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
(...skipping 14 matching lines...) Expand all
33 using WebKit::WebRect; 34 using WebKit::WebRect;
34 using WebKit::WebURL; 35 using WebKit::WebURL;
35 using WebKit::WebVector; 36 using WebKit::WebVector;
36 37
37 namespace content { 38 namespace content {
38 39
39 namespace { 40 namespace {
40 const char kCrashEventName[] = "crash"; 41 const char kCrashEventName[] = "crash";
41 const char kNavigationEventName[] = "navigation"; 42 const char kNavigationEventName[] = "navigation";
42 const char* kSrcAttribute = "src"; 43 const char* kSrcAttribute = "src";
44 const char* kPartitionAttribute = "partition";
45 const char* kPersistPrefix = "persist:";
46
43 } 47 }
44 48
45 BrowserPlugin::BrowserPlugin( 49 BrowserPlugin::BrowserPlugin(
46 int instance_id, 50 int instance_id,
47 RenderViewImpl* render_view, 51 RenderViewImpl* render_view,
48 WebKit::WebFrame* frame, 52 WebKit::WebFrame* frame,
49 const WebPluginParams& params) 53 const WebPluginParams& params)
50 : instance_id_(instance_id), 54 : instance_id_(instance_id),
51 render_view_(render_view), 55 render_view_(render_view),
52 container_(NULL), 56 container_(NULL),
53 damage_buffer_(NULL), 57 damage_buffer_(NULL),
54 sad_guest_(NULL), 58 sad_guest_(NULL),
55 guest_crashed_(false), 59 guest_crashed_(false),
56 resize_pending_(false), 60 resize_pending_(false),
57 parent_frame_(frame->identifier()) { 61 parent_frame_(frame->identifier()),
62 has_navigated_(false),
63 persist_storage_(false) {
58 BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this); 64 BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this);
59 bindings_.reset(new BrowserPluginBindings(this)); 65 bindings_.reset(new BrowserPluginBindings(this));
60 66
61 std::string src; 67 ParseAttributes(params);
62 if (ParseSrcAttribute(params, &src))
63 SetSrcAttribute(src);
64 } 68 }
65 69
66 BrowserPlugin::~BrowserPlugin() { 70 BrowserPlugin::~BrowserPlugin() {
67 if (damage_buffer_) { 71 if (damage_buffer_) {
68 RenderProcess::current()->FreeTransportDIB(damage_buffer_); 72 RenderProcess::current()->FreeTransportDIB(damage_buffer_);
69 damage_buffer_ = NULL; 73 damage_buffer_ = NULL;
70 } 74 }
71 RemoveEventListeners(); 75 RemoveEventListeners();
72 BrowserPluginManager::Get()->RemoveBrowserPlugin(instance_id_); 76 BrowserPluginManager::Get()->RemoveBrowserPlugin(instance_id_);
73 BrowserPluginManager::Get()->Send( 77 BrowserPluginManager::Get()->Send(
(...skipping 16 matching lines...) Expand all
90 void BrowserPlugin::SetSrcAttribute(const std::string& src) { 94 void BrowserPlugin::SetSrcAttribute(const std::string& src) {
91 if (src == src_ && !guest_crashed_) 95 if (src == src_ && !guest_crashed_)
92 return; 96 return;
93 if (!src.empty()) { 97 if (!src.empty()) {
94 BrowserPluginManager::Get()->Send( 98 BrowserPluginManager::Get()->Send(
95 new BrowserPluginHostMsg_NavigateOrCreateGuest( 99 new BrowserPluginHostMsg_NavigateOrCreateGuest(
96 render_view_->GetRoutingID(), 100 render_view_->GetRoutingID(),
97 instance_id_, 101 instance_id_,
98 parent_frame_, 102 parent_frame_,
99 src)); 103 src));
104 has_navigated_ = true;
100 } 105 }
101 src_ = src; 106 src_ = src;
102 guest_crashed_ = false; 107 guest_crashed_ = false;
103 } 108 }
104 109
105 bool BrowserPlugin::ParseSrcAttribute( 110 std::string BrowserPlugin::GetPartitionAttribute() const {
106 const WebKit::WebPluginParams& params, 111 std::string value;
107 std::string* src) { 112 if (persist_storage_)
113 value.append(kPersistPrefix);
114
115 value.append(storage_partition_id_);
116 return value;
117 }
118
119 bool BrowserPlugin::SetPartitionAttribute(const std::string& partition_id,
120 std::string& error_message) {
121 if (has_navigated_) {
122 error_message =
123 "The object has already navigated, so its partition cannot be changed.";
124 return false;
125 }
126 if (!storage_partition_id_.empty()) {
127 error_message = "The partition attribute has already been set.";
128 return false;
129 }
130
131 std::string input = partition_id;
132
133 // Since the "persist:" prefix is in ASCII, StartsWith will work fine on
134 // UTF-8 encoded |partition_id|. If the prefix is a match, we can safely
135 // remove the prefix without splicing in the middle of a multi-byte codepoint.
136 // We can use the rest of the string as UTF-8 encoded one.
137 if (StartsWithASCII(input, kPersistPrefix, true)) {
138 size_t index = input.find(":");
139 CHECK(index != std::string::npos);
140 // It is safe to do index + 1, since we tested for the full prefix above.
141 input = input.substr(index + 1);
142 if (input.empty()) {
143 error_message = "Invalid empty partition attribute.";
144 return false;
145 }
146 persist_storage_ = true;
147 } else {
148 persist_storage_ = false;
149 }
150
151 storage_partition_id_ = input;
152 return true;
153 }
154
155 void BrowserPlugin::ParseAttributes(const WebKit::WebPluginParams& params) {
156 std::string src;
157
108 // Get the src attribute from the attributes vector 158 // Get the src attribute from the attributes vector
109 for (unsigned i = 0; i < params.attributeNames.size(); ++i) { 159 for (unsigned i = 0; i < params.attributeNames.size(); ++i) {
110 std::string attributeName = params.attributeNames[i].utf8(); 160 std::string attributeName = params.attributeNames[i].utf8();
111 if (LowerCaseEqualsASCII(attributeName, kSrcAttribute)) { 161 if (LowerCaseEqualsASCII(attributeName, kSrcAttribute)) {
112 *src = params.attributeValues[i].utf8(); 162 src = params.attributeValues[i].utf8();
113 return true; 163 } else if (LowerCaseEqualsASCII(attributeName, kPartitionAttribute)) {
164 std::string error;
165 SetPartitionAttribute(params.attributeValues[i].utf8(), error);
114 } 166 }
115 } 167 }
116 return false; 168
169 // Set the 'src' attribute last, as it will set the has_navigated_ flag to
170 // true, which prevents changing the 'partition' attribute.
171 if (!src.empty())
172 SetSrcAttribute(src);
117 } 173 }
118 174
119 float BrowserPlugin::GetDeviceScaleFactor() const { 175 float BrowserPlugin::GetDeviceScaleFactor() const {
120 if (!render_view_) 176 if (!render_view_)
121 return 1.0f; 177 return 1.0f;
122 return render_view_->GetWebView()->deviceScaleFactor(); 178 return render_view_->GetWebView()->deviceScaleFactor();
123 } 179 }
124 180
125 void BrowserPlugin::RemoveEventListeners() { 181 void BrowserPlugin::RemoveEventListeners() {
126 EventListenerMap::iterator event_listener_map_iter = 182 EventListenerMap::iterator event_listener_map_iter =
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 void* notify_data) { 468 void* notify_data) {
413 } 469 }
414 470
415 void BrowserPlugin::didFailLoadingFrameRequest( 471 void BrowserPlugin::didFailLoadingFrameRequest(
416 const WebKit::WebURL& url, 472 const WebKit::WebURL& url,
417 void* notify_data, 473 void* notify_data,
418 const WebKit::WebURLError& error) { 474 const WebKit::WebURLError& error) {
419 } 475 }
420 476
421 } // namespace content 477 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698