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 22 matching lines...) Expand all Loading... | |
| 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 kRemoveEventListener[] = "removeEventListener"; | 42 const char kRemoveEventListener[] = "removeEventListener"; |
| 43 const char kReloadMethod[] = "reload"; | |
|
Charlie Reis
2012/09/20 00:07:19
nit: Reload before Remove. :)
| |
| 44 const char kStopMethod[] = "stop"; | |
| 43 const char kSrcAttribute[] = "src"; | 45 const char kSrcAttribute[] = "src"; |
| 44 | 46 |
| 45 BrowserPluginBindings* GetBindings(NPObject* object) { | 47 BrowserPluginBindings* GetBindings(NPObject* object) { |
| 46 return static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(object)-> | 48 return static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(object)-> |
| 47 message_channel; | 49 message_channel; |
| 48 } | 50 } |
| 49 | 51 |
| 52 bool IdentifierIsReload(NPIdentifier identifier) { | |
| 53 return WebBindings::getStringIdentifier(kReloadMethod) == identifier; | |
| 54 } | |
| 55 | |
| 56 bool IdentifierIsStop(NPIdentifier identifier) { | |
| 57 return WebBindings::getStringIdentifier(kStopMethod) == identifier; | |
| 58 } | |
| 59 | |
| 50 bool IdentifierIsAddEventListener(NPIdentifier identifier) { | 60 bool IdentifierIsAddEventListener(NPIdentifier identifier) { |
| 51 return WebBindings::getStringIdentifier(kAddEventListener) == identifier; | 61 return WebBindings::getStringIdentifier(kAddEventListener) == identifier; |
| 52 } | 62 } |
| 53 | 63 |
| 54 bool IdentifierIsRemoveEventListener(NPIdentifier identifier) { | 64 bool IdentifierIsRemoveEventListener(NPIdentifier identifier) { |
| 55 return WebBindings::getStringIdentifier(kRemoveEventListener) == identifier; | 65 return WebBindings::getStringIdentifier(kRemoveEventListener) == identifier; |
| 56 } | 66 } |
| 57 | 67 |
| 58 bool IdentifierIsSrcAttribute(NPIdentifier identifier) { | 68 bool IdentifierIsSrcAttribute(NPIdentifier identifier) { |
| 59 return WebBindings::getStringIdentifier(kSrcAttribute) == identifier; | 69 return WebBindings::getStringIdentifier(kSrcAttribute) == identifier; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 bool BrowserPluginBindingsHasMethod(NPObject* np_obj, NPIdentifier name) { | 115 bool BrowserPluginBindingsHasMethod(NPObject* np_obj, NPIdentifier name) { |
| 106 if (!np_obj) | 116 if (!np_obj) |
| 107 return false; | 117 return false; |
| 108 | 118 |
| 109 if (IdentifierIsAddEventListener(name)) | 119 if (IdentifierIsAddEventListener(name)) |
| 110 return true; | 120 return true; |
| 111 | 121 |
| 112 if (IdentifierIsRemoveEventListener(name)) | 122 if (IdentifierIsRemoveEventListener(name)) |
| 113 return true; | 123 return true; |
| 114 | 124 |
| 125 if (IdentifierIsStop(name)) | |
| 126 return true; | |
| 127 | |
| 128 if (IdentifierIsReload(name)) | |
| 129 return true; | |
| 130 | |
| 115 return false; | 131 return false; |
| 116 } | 132 } |
| 117 | 133 |
| 118 bool BrowserPluginBindingsInvoke(NPObject* np_obj, NPIdentifier name, | 134 bool BrowserPluginBindingsInvoke(NPObject* np_obj, NPIdentifier name, |
| 119 const NPVariant* args, uint32 arg_count, | 135 const NPVariant* args, uint32 arg_count, |
| 120 NPVariant* result) { | 136 NPVariant* result) { |
| 121 if (!np_obj) | 137 if (!np_obj) |
| 122 return false; | 138 return false; |
| 123 | 139 |
| 124 BrowserPluginBindings* bindings = GetBindings(np_obj); | 140 BrowserPluginBindings* bindings = GetBindings(np_obj); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 147 v8::Local<v8::Value> value = | 163 v8::Local<v8::Value> value = |
| 148 v8::Local<v8::Value>::New(WebBindings::toV8Value(&args[1])); | 164 v8::Local<v8::Value>::New(WebBindings::toV8Value(&args[1])); |
| 149 | 165 |
| 150 if (value.IsEmpty() || !value->IsFunction()) | 166 if (value.IsEmpty() || !value->IsFunction()) |
| 151 return false; | 167 return false; |
| 152 | 168 |
| 153 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value); | 169 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value); |
| 154 return bindings->instance()->RemoveEventListener(event_name, function); | 170 return bindings->instance()->RemoveEventListener(event_name, function); |
| 155 } | 171 } |
| 156 | 172 |
| 173 if (IdentifierIsStop(name) && !arg_count) { | |
| 174 bindings->instance()->Stop(); | |
| 175 return true; | |
| 176 } | |
| 177 | |
| 178 if (IdentifierIsReload(name) && !arg_count) { | |
| 179 bindings->instance()->Reload(); | |
| 180 return true; | |
| 181 } | |
| 182 | |
| 157 return false; | 183 return false; |
| 158 } | 184 } |
| 159 | 185 |
| 160 bool BrowserPluginBindingsInvokeDefault(NPObject* np_obj, | 186 bool BrowserPluginBindingsInvokeDefault(NPObject* np_obj, |
| 161 const NPVariant* args, | 187 const NPVariant* args, |
| 162 uint32 arg_count, | 188 uint32 arg_count, |
| 163 NPVariant* result) { | 189 NPVariant* result) { |
| 164 NOTIMPLEMENTED(); | 190 NOTIMPLEMENTED(); |
| 165 return false; | 191 return false; |
| 166 } | 192 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 WebBindings::createObject(NULL, &browser_plugin_message_class); | 270 WebBindings::createObject(NULL, &browser_plugin_message_class); |
| 245 np_object_ = static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(obj); | 271 np_object_ = static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(obj); |
| 246 np_object_->message_channel = weak_ptr_factory_.GetWeakPtr(); | 272 np_object_->message_channel = weak_ptr_factory_.GetWeakPtr(); |
| 247 } | 273 } |
| 248 | 274 |
| 249 BrowserPluginBindings::~BrowserPluginBindings() { | 275 BrowserPluginBindings::~BrowserPluginBindings() { |
| 250 WebBindings::releaseObject(np_object_); | 276 WebBindings::releaseObject(np_object_); |
| 251 } | 277 } |
| 252 | 278 |
| 253 } // namespace content | 279 } // namespace content |
| OLD | NEW |