Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 18 matching lines...) Expand all Loading... | |
| 29 using WebKit::WebDOMEvent; | 29 using WebKit::WebDOMEvent; |
| 30 using WebKit::WebDOMMessageEvent; | 30 using WebKit::WebDOMMessageEvent; |
| 31 using WebKit::WebPluginContainer; | 31 using WebKit::WebPluginContainer; |
| 32 using WebKit::WebString; | 32 using WebKit::WebString; |
| 33 | 33 |
| 34 namespace content { | 34 namespace content { |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 const char kAddEventListener[] = "addEventListener"; | 38 const char kAddEventListener[] = "addEventListener"; |
| 39 const char kAutoSizeAttribute[] = "autoSize"; | |
| 39 const char kBackMethod[] = "back"; | 40 const char kBackMethod[] = "back"; |
| 40 const char kCanGoBack[] = "canGoBack"; | 41 const char kCanGoBack[] = "canGoBack"; |
| 41 const char kCanGoForward[] = "canGoForward"; | 42 const char kCanGoForward[] = "canGoForward"; |
| 42 const char kContentWindow[] = "contentWindow"; | 43 const char kContentWindow[] = "contentWindow"; |
| 43 const char kForwardMethod[] = "forward"; | 44 const char kForwardMethod[] = "forward"; |
| 44 const char kGetProcessId[] = "getProcessId"; | 45 const char kGetProcessId[] = "getProcessId"; |
| 45 const char kGoMethod[] = "go"; | 46 const char kGoMethod[] = "go"; |
| 47 const char kMaxHeightAttribute[] = "maxHeight"; | |
| 48 const char kMaxWidthAttribute[] = "maxWidth"; | |
| 49 const char kMinHeightAttribute[] = "minHeight"; | |
| 50 const char kMinWidthAttribute[] = "minWidth"; | |
| 46 const char kPartitionAttribute[] = "partition"; | 51 const char kPartitionAttribute[] = "partition"; |
| 47 const char kReloadMethod[] = "reload"; | 52 const char kReloadMethod[] = "reload"; |
| 48 const char kRemoveEventListener[] = "removeEventListener"; | 53 const char kRemoveEventListener[] = "removeEventListener"; |
| 49 const char kSrcAttribute[] = "src"; | 54 const char kSrcAttribute[] = "src"; |
| 50 const char kStopMethod[] = "stop"; | 55 const char kStopMethod[] = "stop"; |
| 51 const char kTerminateMethod[] = "terminate"; | 56 const char kTerminateMethod[] = "terminate"; |
| 52 | 57 |
| 53 BrowserPluginBindings* GetBindings(NPObject* object) { | 58 BrowserPluginBindings* GetBindings(NPObject* object) { |
| 54 return static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(object)-> | 59 return static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(object)-> |
| 55 message_channel; | 60 message_channel; |
| 56 } | 61 } |
| 57 | 62 |
| 58 bool IdentifierIsContentWindow(NPIdentifier identifier) { | 63 bool IdentifierIsContentWindow(NPIdentifier identifier) { |
| 59 return WebBindings::getStringIdentifier(kContentWindow) == identifier; | 64 return WebBindings::getStringIdentifier(kContentWindow) == identifier; |
| 60 } | 65 } |
| 61 | 66 |
| 62 bool IdentifierIsPartitionAttribute(NPIdentifier identifier) { | 67 bool IdentifierIsPartitionAttribute(NPIdentifier identifier) { |
| 63 return WebBindings::getStringIdentifier(kPartitionAttribute) == identifier; | 68 return WebBindings::getStringIdentifier(kPartitionAttribute) == identifier; |
| 64 } | 69 } |
| 65 | 70 |
| 66 bool IdentifierIsSrcAttribute(NPIdentifier identifier) { | 71 bool IdentifierIsSrcAttribute(NPIdentifier identifier) { |
| 67 return WebBindings::getStringIdentifier(kSrcAttribute) == identifier; | 72 return WebBindings::getStringIdentifier(kSrcAttribute) == identifier; |
| 68 } | 73 } |
| 69 | 74 |
| 75 bool IdentifierIsMaxHeightAttribute(NPIdentifier identifier) { | |
| 76 return WebBindings::getStringIdentifier(kMaxHeightAttribute) == identifier; | |
| 77 } | |
| 78 | |
| 79 bool IdentifierIsMaxWidthAttribute(NPIdentifier identifier) { | |
| 80 return WebBindings::getStringIdentifier(kMaxWidthAttribute) == identifier; | |
| 81 } | |
| 82 | |
| 83 bool IdentifierIsMinHeightAttribute(NPIdentifier identifier) { | |
| 84 return WebBindings::getStringIdentifier(kMinHeightAttribute) == identifier; | |
| 85 } | |
| 86 | |
| 87 bool IdentifierIsMinWidthAttribute(NPIdentifier identifier) { | |
| 88 return WebBindings::getStringIdentifier(kMinWidthAttribute) == identifier; | |
| 89 } | |
| 90 | |
| 91 bool IdentifierIsAutoSizeAttribute(NPIdentifier identifier) { | |
| 92 return WebBindings::getStringIdentifier(kAutoSizeAttribute) == identifier; | |
| 93 } | |
| 94 | |
| 70 int Int32FromNPVariant(const NPVariant& variant) { | 95 int Int32FromNPVariant(const NPVariant& variant) { |
| 71 if (NPVARIANT_IS_INT32(variant)) | 96 if (NPVARIANT_IS_INT32(variant)) |
| 72 return NPVARIANT_TO_INT32(variant); | 97 return NPVARIANT_TO_INT32(variant); |
| 73 | 98 |
| 74 if (NPVARIANT_IS_DOUBLE(variant)) | 99 if (NPVARIANT_IS_DOUBLE(variant)) |
| 75 return NPVARIANT_TO_DOUBLE(variant); | 100 return NPVARIANT_TO_DOUBLE(variant); |
| 76 | 101 |
| 77 return 0; | 102 return 0; |
| 78 } | 103 } |
| 79 | 104 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 const NPVariant* args, | 163 const NPVariant* args, |
| 139 uint32 arg_count, | 164 uint32 arg_count, |
| 140 NPVariant* result) { | 165 NPVariant* result) { |
| 141 NOTIMPLEMENTED(); | 166 NOTIMPLEMENTED(); |
| 142 return false; | 167 return false; |
| 143 } | 168 } |
| 144 | 169 |
| 145 bool BrowserPluginBindingsHasProperty(NPObject* np_obj, NPIdentifier name) { | 170 bool BrowserPluginBindingsHasProperty(NPObject* np_obj, NPIdentifier name) { |
| 146 return IdentifierIsSrcAttribute(name) || | 171 return IdentifierIsSrcAttribute(name) || |
| 147 IdentifierIsContentWindow(name) || | 172 IdentifierIsContentWindow(name) || |
| 148 IdentifierIsPartitionAttribute(name); | 173 IdentifierIsPartitionAttribute(name) || |
| 174 IdentifierIsAutoSizeAttribute(name) || | |
| 175 IdentifierIsMaxHeightAttribute(name) || | |
| 176 IdentifierIsMaxWidthAttribute(name) || | |
| 177 IdentifierIsMinHeightAttribute(name) || | |
| 178 IdentifierIsMinWidthAttribute(name); | |
| 149 } | 179 } |
| 150 | 180 |
| 151 bool BrowserPluginBindingsGetProperty(NPObject* np_obj, NPIdentifier name, | 181 bool BrowserPluginBindingsGetProperty(NPObject* np_obj, NPIdentifier name, |
| 152 NPVariant* result) { | 182 NPVariant* result) { |
| 153 if (!np_obj) | 183 if (!np_obj) |
| 154 return false; | 184 return false; |
| 155 | 185 |
| 156 if (!result) | 186 if (!result) |
| 157 return false; | 187 return false; |
| 158 | 188 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 169 | 199 |
| 170 if (IdentifierIsContentWindow(name)) { | 200 if (IdentifierIsContentWindow(name)) { |
| 171 NPObject* obj = bindings->instance()->GetContentWindow(); | 201 NPObject* obj = bindings->instance()->GetContentWindow(); |
| 172 if (obj) { | 202 if (obj) { |
| 173 result->type = NPVariantType_Object; | 203 result->type = NPVariantType_Object; |
| 174 result->value.objectValue = WebBindings::retainObject(obj); | 204 result->value.objectValue = WebBindings::retainObject(obj); |
| 175 } | 205 } |
| 176 return true; | 206 return true; |
| 177 } | 207 } |
| 178 | 208 |
| 209 if (IdentifierIsAutoSizeAttribute(name)) { | |
| 210 bool autosize = bindings->instance()->GetAutoSizeAttribute(); | |
| 211 BOOLEAN_TO_NPVARIANT(autosize, *result); | |
| 212 return true; | |
| 213 } | |
| 214 | |
| 215 if (IdentifierIsMaxHeightAttribute(name)) { | |
| 216 int maxheight = bindings->instance()->GetMaxHeightAttribute(); | |
| 217 INT32_TO_NPVARIANT(maxheight, *result); | |
| 218 return true; | |
| 219 } | |
| 220 | |
| 221 if (IdentifierIsMaxWidthAttribute(name)) { | |
| 222 int maxwidth = bindings->instance()->GetMaxWidthAttribute(); | |
| 223 INT32_TO_NPVARIANT(maxwidth, *result); | |
| 224 return true; | |
| 225 } | |
| 226 | |
| 227 if (IdentifierIsMinHeightAttribute(name)) { | |
| 228 int minheight = bindings->instance()->GetMinHeightAttribute(); | |
| 229 INT32_TO_NPVARIANT(minheight, *result); | |
| 230 return true; | |
| 231 } | |
| 232 | |
| 233 if (IdentifierIsMinWidthAttribute(name)) { | |
| 234 int minwidth = bindings->instance()->GetMinWidthAttribute(); | |
| 235 INT32_TO_NPVARIANT(minwidth, *result); | |
| 236 return true; | |
| 237 } | |
| 238 | |
| 179 if (IdentifierIsPartitionAttribute(name)) { | 239 if (IdentifierIsPartitionAttribute(name)) { |
| 180 std::string partition_id = bindings->instance()->GetPartitionAttribute(); | 240 std::string partition_id = bindings->instance()->GetPartitionAttribute(); |
| 181 return StringToNPVariant(partition_id, result); | 241 return StringToNPVariant(partition_id, result); |
| 182 } | 242 } |
| 183 | 243 |
| 184 return false; | 244 return false; |
| 185 } | 245 } |
| 186 | 246 |
| 187 bool BrowserPluginBindingsSetProperty(NPObject* np_obj, NPIdentifier name, | 247 bool BrowserPluginBindingsSetProperty(NPObject* np_obj, NPIdentifier name, |
| 188 const NPVariant* variant) { | 248 const NPVariant* variant) { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 208 std::string error_message; | 268 std::string error_message; |
| 209 if (!bindings->instance()->SetPartitionAttribute(partition_id, | 269 if (!bindings->instance()->SetPartitionAttribute(partition_id, |
| 210 error_message)) { | 270 error_message)) { |
| 211 WebBindings::setException( | 271 WebBindings::setException( |
| 212 np_obj, static_cast<const NPUTF8 *>(error_message.c_str())); | 272 np_obj, static_cast<const NPUTF8 *>(error_message.c_str())); |
| 213 return false; | 273 return false; |
| 214 } | 274 } |
| 215 return true; | 275 return true; |
| 216 } | 276 } |
| 217 | 277 |
| 278 if (IdentifierIsAutoSizeAttribute(name)) { | |
| 279 bool autosize = NPVARIANT_TO_BOOLEAN(*variant); | |
| 280 bindings->instance()->SetAutoSizeAttribute(autosize); | |
| 281 return true; | |
| 282 } | |
| 283 | |
| 284 if (IdentifierIsMaxHeightAttribute(name)) { | |
| 285 int maxheight = Int32FromNPVariant(*variant); | |
| 286 bindings->instance()->SetMaxHeightAttribute(maxheight); | |
| 287 return true; | |
| 288 } | |
| 289 | |
| 290 if (IdentifierIsMaxWidthAttribute(name)) { | |
| 291 int maxwidth = Int32FromNPVariant(*variant); | |
| 292 bindings->instance()->SetMaxWidthAttribute(maxwidth); | |
| 293 return true; | |
| 294 } | |
| 295 | |
| 296 if (IdentifierIsMinHeightAttribute(name)) { | |
| 297 int minheight = Int32FromNPVariant(*variant); | |
|
jam
2012/11/02 19:11:10
ditto
Fady Samuel
2012/11/02 20:32:23
Done.
| |
| 298 bindings->instance()->SetMinHeightAttribute(minheight); | |
| 299 return true; | |
| 300 } | |
| 301 | |
| 302 if (IdentifierIsMinWidthAttribute(name)) { | |
| 303 int minwidth = Int32FromNPVariant(*variant); | |
| 304 bindings->instance()->SetMinWidthAttribute(minwidth); | |
| 305 return true; | |
| 306 } | |
| 307 | |
| 218 return false; | 308 return false; |
| 219 } | 309 } |
| 220 | 310 |
| 221 bool BrowserPluginBindingsEnumerate(NPObject *np_obj, NPIdentifier **value, | 311 bool BrowserPluginBindingsEnumerate(NPObject *np_obj, NPIdentifier **value, |
| 222 uint32_t *count) { | 312 uint32_t *count) { |
| 223 NOTIMPLEMENTED(); | 313 NOTIMPLEMENTED(); |
| 224 return true; | 314 return true; |
| 225 } | 315 } |
| 226 | 316 |
| 227 NPClass browser_plugin_message_class = { | 317 NPClass browser_plugin_message_class = { |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 532 for (BindingList::iterator iter = method_bindings_.begin(); | 622 for (BindingList::iterator iter = method_bindings_.begin(); |
| 533 iter != method_bindings_.end(); | 623 iter != method_bindings_.end(); |
| 534 ++iter) { | 624 ++iter) { |
| 535 if ((*iter)->MatchesName(name) && (*iter)->arg_count() == arg_count) | 625 if ((*iter)->MatchesName(name) && (*iter)->arg_count() == arg_count) |
| 536 return (*iter)->Invoke(this, args, result); | 626 return (*iter)->Invoke(this, args, result); |
| 537 } | 627 } |
| 538 return false; | 628 return false; |
| 539 } | 629 } |
| 540 | 630 |
| 541 } // namespace content | 631 } // namespace content |
| OLD | NEW |