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

Side by Side Diff: content/renderer/browser_plugin/browser_plugin_bindings.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: Testing 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_bindings.h" 5 #include "content/renderer/browser_plugin/browser_plugin_bindings.h"
6 6
7 #include <cstdlib> 7 #include <cstdlib>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 22 matching lines...) Expand all
33 using WebKit::WebPluginContainer; 33 using WebKit::WebPluginContainer;
34 using WebKit::WebSerializedScriptValue; 34 using WebKit::WebSerializedScriptValue;
35 using WebKit::WebString; 35 using WebKit::WebString;
36 36
37 namespace content { 37 namespace content {
38 38
39 namespace { 39 namespace {
40 40
41 const char kAddEventListener[] = "addEventListener"; 41 const char kAddEventListener[] = "addEventListener";
42 const char kGetProcessId[] = "getProcessId"; 42 const char kGetProcessId[] = "getProcessId";
43 const char kPartitionAttribute[] = "partition";
43 const char kReloadMethod[] = "reload"; 44 const char kReloadMethod[] = "reload";
44 const char kRemoveEventListener[] = "removeEventListener"; 45 const char kRemoveEventListener[] = "removeEventListener";
45 const char kSrcAttribute[] = "src"; 46 const char kSrcAttribute[] = "src";
46 const char kStopMethod[] = "stop"; 47 const char kStopMethod[] = "stop";
47 48
48 BrowserPluginBindings* GetBindings(NPObject* object) { 49 BrowserPluginBindings* GetBindings(NPObject* object) {
49 return static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(object)-> 50 return static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(object)->
50 message_channel; 51 message_channel;
51 } 52 }
52 53
(...skipping 14 matching lines...) Expand all
67 } 68 }
68 69
69 bool IdentifierIsGetProcessID(NPIdentifier identifier) { 70 bool IdentifierIsGetProcessID(NPIdentifier identifier) {
70 return WebBindings::getStringIdentifier(kGetProcessId) == identifier; 71 return WebBindings::getStringIdentifier(kGetProcessId) == identifier;
71 } 72 }
72 73
73 bool IdentifierIsSrcAttribute(NPIdentifier identifier) { 74 bool IdentifierIsSrcAttribute(NPIdentifier identifier) {
74 return WebBindings::getStringIdentifier(kSrcAttribute) == identifier; 75 return WebBindings::getStringIdentifier(kSrcAttribute) == identifier;
75 } 76 }
76 77
78 bool IdentifierIsPartitionAttribute(NPIdentifier identifier) {
79 return WebBindings::getStringIdentifier(kPartitionAttribute) == identifier;
80 }
81
77 std::string StringFromNPVariant(const NPVariant& variant) { 82 std::string StringFromNPVariant(const NPVariant& variant) {
78 if (!NPVARIANT_IS_STRING(variant)) 83 if (!NPVARIANT_IS_STRING(variant))
79 return std::string(); 84 return std::string();
80 const NPString& np_string = NPVARIANT_TO_STRING(variant); 85 const NPString& np_string = NPVARIANT_TO_STRING(variant);
81 return std::string(np_string.UTF8Characters, np_string.UTF8Length); 86 return std::string(np_string.UTF8Characters, np_string.UTF8Length);
82 } 87 }
83 88
84 string16 String16FromNPVariant(const NPVariant& variant) { 89 string16 String16FromNPVariant(const NPVariant& variant) {
85 if (!NPVARIANT_IS_STRING(variant)) 90 if (!NPVARIANT_IS_STRING(variant))
86 return string16(); 91 return string16();
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 205
201 bool BrowserPluginBindingsInvokeDefault(NPObject* np_obj, 206 bool BrowserPluginBindingsInvokeDefault(NPObject* np_obj,
202 const NPVariant* args, 207 const NPVariant* args,
203 uint32 arg_count, 208 uint32 arg_count,
204 NPVariant* result) { 209 NPVariant* result) {
205 NOTIMPLEMENTED(); 210 NOTIMPLEMENTED();
206 return false; 211 return false;
207 } 212 }
208 213
209 bool BrowserPluginBindingsHasProperty(NPObject* np_obj, NPIdentifier name) { 214 bool BrowserPluginBindingsHasProperty(NPObject* np_obj, NPIdentifier name) {
210 return IdentifierIsSrcAttribute(name); 215 return IdentifierIsSrcAttribute(name) ||
216 IdentifierIsPartitionAttribute(name);
211 } 217 }
212 218
213 bool BrowserPluginBindingsGetProperty(NPObject* np_obj, NPIdentifier name, 219 bool BrowserPluginBindingsGetProperty(NPObject* np_obj, NPIdentifier name,
214 NPVariant* result) { 220 NPVariant* result) {
215 if (!np_obj) 221 if (!np_obj)
216 return false; 222 return false;
217 223
224 if (!result)
225 return false;
226
218 if (IdentifierIsAddEventListener(name) || 227 if (IdentifierIsAddEventListener(name) ||
219 IdentifierIsRemoveEventListener(name)) 228 IdentifierIsRemoveEventListener(name))
220 return false; 229 return false;
221 230
231 // All attributes from here on rely on the bindings, so retrieve it once and
232 // return on failure.
233 BrowserPluginBindings* bindings = GetBindings(np_obj);
234 if (!bindings)
235 return false;
236
222 if (IdentifierIsSrcAttribute(name)) { 237 if (IdentifierIsSrcAttribute(name)) {
223 BrowserPluginBindings* bindings = GetBindings(np_obj);
224 if (!bindings)
225 return false;
226 std::string src = bindings->instance()->GetSrcAttribute(); 238 std::string src = bindings->instance()->GetSrcAttribute();
227 return StringToNPVariant(src, result); 239 return StringToNPVariant(src, result);
228 } 240 }
229 241
242 if (IdentifierIsPartitionAttribute(name)) {
243 std::string partition_id = bindings->instance()->GetPartitionAttribute();
244 return StringToNPVariant(partition_id, result);
245 }
246
230 return false; 247 return false;
231 } 248 }
232 249
233 bool BrowserPluginBindingsSetProperty(NPObject* np_obj, NPIdentifier name, 250 bool BrowserPluginBindingsSetProperty(NPObject* np_obj, NPIdentifier name,
234 const NPVariant* variant) { 251 const NPVariant* variant) {
235 if (!np_obj) 252 if (!np_obj)
236 return false; 253 return false;
254 if (!variant)
255 return false;
256
257 // All attributes from here on rely on the bindings, so retrieve it once and
258 // return on failure.
259 BrowserPluginBindings* bindings = GetBindings(np_obj);
260 if (!bindings)
261 return false;
237 262
238 if (IdentifierIsSrcAttribute(name)) { 263 if (IdentifierIsSrcAttribute(name)) {
239 std::string src = StringFromNPVariant(*variant); 264 std::string src = StringFromNPVariant(*variant);
240 BrowserPluginBindings* bindings = GetBindings(np_obj);
241 if (!bindings)
242 return false;
243 bindings->instance()->SetSrcAttribute(src); 265 bindings->instance()->SetSrcAttribute(src);
244 return true; 266 return true;
245 } 267 }
268
269 if (IdentifierIsPartitionAttribute(name)) {
270 std::string partition_id = StringFromNPVariant(*variant);
271 std::string error_message;
272 if (!bindings->instance()->SetPartitionAttribute(partition_id,
273 error_message)) {
274 WebBindings::setException(
275 np_obj, static_cast<const NPUTF8 *>(error_message.c_str()));
276 return false;
277 }
278 return true;
279 }
280
246 return false; 281 return false;
247 } 282 }
248 283
249 bool BrowserPluginBindingsEnumerate(NPObject *np_obj, NPIdentifier **value, 284 bool BrowserPluginBindingsEnumerate(NPObject *np_obj, NPIdentifier **value,
250 uint32_t *count) { 285 uint32_t *count) {
251 NOTIMPLEMENTED(); 286 NOTIMPLEMENTED();
252 return true; 287 return true;
253 } 288 }
254 289
255 NPClass browser_plugin_message_class = { 290 NPClass browser_plugin_message_class = {
(...skipping 29 matching lines...) Expand all
285 WebBindings::createObject(NULL, &browser_plugin_message_class); 320 WebBindings::createObject(NULL, &browser_plugin_message_class);
286 np_object_ = static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(obj); 321 np_object_ = static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(obj);
287 np_object_->message_channel = weak_ptr_factory_.GetWeakPtr(); 322 np_object_->message_channel = weak_ptr_factory_.GetWeakPtr();
288 } 323 }
289 324
290 BrowserPluginBindings::~BrowserPluginBindings() { 325 BrowserPluginBindings::~BrowserPluginBindings() {
291 WebBindings::releaseObject(np_object_); 326 WebBindings::releaseObject(np_object_);
292 } 327 }
293 328
294 } // namespace content 329 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/browser_plugin/browser_plugin.cc ('k') | content/renderer/browser_plugin/browser_plugin_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698