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

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

Issue 10829225: Browser Plugin: Add HTML5-like postMessage support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed nits Created 8 years, 2 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 23 matching lines...) Expand all
34 using WebKit::WebString; 34 using WebKit::WebString;
35 35
36 namespace content { 36 namespace content {
37 37
38 namespace { 38 namespace {
39 39
40 const char kAddEventListener[] = "addEventListener"; 40 const char kAddEventListener[] = "addEventListener";
41 const char kBackMethod[] = "back"; 41 const char kBackMethod[] = "back";
42 const char kCanGoBack[] = "canGoBack"; 42 const char kCanGoBack[] = "canGoBack";
43 const char kCanGoForward[] = "canGoForward"; 43 const char kCanGoForward[] = "canGoForward";
44 const char kContentWindow[] = "contentWindow";
44 const char kForwardMethod[] = "forward"; 45 const char kForwardMethod[] = "forward";
45 const char kGetProcessId[] = "getProcessId"; 46 const char kGetProcessId[] = "getProcessId";
46 const char kGoMethod[] = "go"; 47 const char kGoMethod[] = "go";
47 const char kPartitionAttribute[] = "partition"; 48 const char kPartitionAttribute[] = "partition";
48 const char kReloadMethod[] = "reload"; 49 const char kReloadMethod[] = "reload";
49 const char kRemoveEventListener[] = "removeEventListener"; 50 const char kRemoveEventListener[] = "removeEventListener";
50 const char kSrcAttribute[] = "src"; 51 const char kSrcAttribute[] = "src";
51 const char kStopMethod[] = "stop"; 52 const char kStopMethod[] = "stop";
52 const char kTerminateMethod[] = "terminate"; 53 const char kTerminateMethod[] = "terminate";
53 54
54 BrowserPluginBindings* GetBindings(NPObject* object) { 55 BrowserPluginBindings* GetBindings(NPObject* object) {
55 return static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(object)-> 56 return static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(object)->
56 message_channel; 57 message_channel;
57 } 58 }
58 59
60 bool IdentifierIsContentWindow(NPIdentifier identifier) {
61 return WebBindings::getStringIdentifier(kContentWindow) == identifier;
62 }
63
59 bool IdentifierIsPartitionAttribute(NPIdentifier identifier) { 64 bool IdentifierIsPartitionAttribute(NPIdentifier identifier) {
60 return WebBindings::getStringIdentifier(kPartitionAttribute) == identifier; 65 return WebBindings::getStringIdentifier(kPartitionAttribute) == identifier;
61 } 66 }
62 67
63 bool IdentifierIsSrcAttribute(NPIdentifier identifier) { 68 bool IdentifierIsSrcAttribute(NPIdentifier identifier) {
64 return WebBindings::getStringIdentifier(kSrcAttribute) == identifier; 69 return WebBindings::getStringIdentifier(kSrcAttribute) == identifier;
65 } 70 }
66 71
67 int Int32FromNPVariant(const NPVariant& variant) { 72 int Int32FromNPVariant(const NPVariant& variant) {
68 if (NPVARIANT_IS_INT32(variant)) 73 if (NPVARIANT_IS_INT32(variant))
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 bool BrowserPluginBindingsInvokeDefault(NPObject* np_obj, 139 bool BrowserPluginBindingsInvokeDefault(NPObject* np_obj,
135 const NPVariant* args, 140 const NPVariant* args,
136 uint32 arg_count, 141 uint32 arg_count,
137 NPVariant* result) { 142 NPVariant* result) {
138 NOTIMPLEMENTED(); 143 NOTIMPLEMENTED();
139 return false; 144 return false;
140 } 145 }
141 146
142 bool BrowserPluginBindingsHasProperty(NPObject* np_obj, NPIdentifier name) { 147 bool BrowserPluginBindingsHasProperty(NPObject* np_obj, NPIdentifier name) {
143 return IdentifierIsSrcAttribute(name) || 148 return IdentifierIsSrcAttribute(name) ||
149 IdentifierIsContentWindow(name) ||
144 IdentifierIsPartitionAttribute(name); 150 IdentifierIsPartitionAttribute(name);
145 } 151 }
146 152
147 bool BrowserPluginBindingsGetProperty(NPObject* np_obj, NPIdentifier name, 153 bool BrowserPluginBindingsGetProperty(NPObject* np_obj, NPIdentifier name,
148 NPVariant* result) { 154 NPVariant* result) {
149 if (!np_obj) 155 if (!np_obj)
150 return false; 156 return false;
151 157
152 if (!result) 158 if (!result)
153 return false; 159 return false;
154 160
155 // All attributes from here on rely on the bindings, so retrieve it once and 161 // All attributes from here on rely on the bindings, so retrieve it once and
156 // return on failure. 162 // return on failure.
157 BrowserPluginBindings* bindings = GetBindings(np_obj); 163 BrowserPluginBindings* bindings = GetBindings(np_obj);
158 if (!bindings) 164 if (!bindings)
159 return false; 165 return false;
160 166
161 if (IdentifierIsSrcAttribute(name)) { 167 if (IdentifierIsSrcAttribute(name)) {
162 std::string src = bindings->instance()->GetSrcAttribute(); 168 std::string src = bindings->instance()->GetSrcAttribute();
163 return StringToNPVariant(src, result); 169 return StringToNPVariant(src, result);
164 } 170 }
165 171
172 if (IdentifierIsContentWindow(name)) {
173 NPObject* obj = bindings->instance()->GetContentWindow();
174 if (obj) {
175 result->type = NPVariantType_Object;
176 result->value.objectValue = WebBindings::retainObject(obj);
177 }
178 return true;
179 }
180
166 if (IdentifierIsPartitionAttribute(name)) { 181 if (IdentifierIsPartitionAttribute(name)) {
167 std::string partition_id = bindings->instance()->GetPartitionAttribute(); 182 std::string partition_id = bindings->instance()->GetPartitionAttribute();
168 return StringToNPVariant(partition_id, result); 183 return StringToNPVariant(partition_id, result);
169 } 184 }
170 185
171 return false; 186 return false;
172 } 187 }
173 188
174 bool BrowserPluginBindingsSetProperty(NPObject* np_obj, NPIdentifier name, 189 bool BrowserPluginBindingsSetProperty(NPObject* np_obj, NPIdentifier name,
175 const NPVariant* variant) { 190 const NPVariant* variant) {
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 for (BindingList::iterator iter = method_bindings_.begin(); 536 for (BindingList::iterator iter = method_bindings_.begin();
522 iter != method_bindings_.end(); 537 iter != method_bindings_.end();
523 ++iter) { 538 ++iter) {
524 if ((*iter)->MatchesName(name) && (*iter)->arg_count() == arg_count) 539 if ((*iter)->MatchesName(name) && (*iter)->arg_count() == arg_count)
525 return (*iter)->Invoke(this, args, result); 540 return (*iter)->Invoke(this, args, result);
526 } 541 }
527 return false; 542 return false;
528 } 543 }
529 544
530 } // namespace content 545 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/browser_plugin/browser_plugin.cc ('k') | content/renderer/browser_plugin/browser_plugin_manager_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698