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

Side by Side Diff: content/renderer/browser_plugin/browser_plugin_bindings.cc

Issue 10917225: Browser Plugin: Reload and Stop operations (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments + merged with ToT/latest patch 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 kRemoveEventListener[] = "removeEventListener"; 42 const char kRemoveEventListener[] = "removeEventListener";
43 const char kReloadMethod[] = "reload";
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
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
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();
lazyboy 2012/09/19 15:06:06 return true; here too?
Fady Samuel 2012/09/19 15:50:56 Done.
180 }
181
157 return false; 182 return false;
158 } 183 }
159 184
160 bool BrowserPluginBindingsInvokeDefault(NPObject* np_obj, 185 bool BrowserPluginBindingsInvokeDefault(NPObject* np_obj,
161 const NPVariant* args, 186 const NPVariant* args,
162 uint32 arg_count, 187 uint32 arg_count,
163 NPVariant* result) { 188 NPVariant* result) {
164 NOTIMPLEMENTED(); 189 NOTIMPLEMENTED();
165 return false; 190 return false;
166 } 191 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 WebBindings::createObject(NULL, &browser_plugin_message_class); 269 WebBindings::createObject(NULL, &browser_plugin_message_class);
245 np_object_ = static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(obj); 270 np_object_ = static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(obj);
246 np_object_->message_channel = weak_ptr_factory_.GetWeakPtr(); 271 np_object_->message_channel = weak_ptr_factory_.GetWeakPtr();
247 } 272 }
248 273
249 BrowserPluginBindings::~BrowserPluginBindings() { 274 BrowserPluginBindings::~BrowserPluginBindings() {
250 WebBindings::releaseObject(np_object_); 275 WebBindings::releaseObject(np_object_);
251 } 276 }
252 277
253 } // namespace content 278 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698