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

Unified Diff: content/renderer/browser_plugin/browser_plugin_bindings.cc

Issue 11826005: Browser Plugin: Implement BrowserPluginObserver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with ToT Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/browser_plugin/browser_plugin_bindings.cc
diff --git a/content/renderer/browser_plugin/browser_plugin_bindings.cc b/content/renderer/browser_plugin/browser_plugin_bindings.cc
index 05d57a9728fd04e06998f3dd15c490a076796efb..d331cf6973f6859685bdbeb42930be790e97700b 100644
--- a/content/renderer/browser_plugin/browser_plugin_bindings.cc
+++ b/content/renderer/browser_plugin/browser_plugin_bindings.cc
@@ -13,8 +13,10 @@
#include "base/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/utf_string_conversions.h"
-#include "content/renderer/browser_plugin/browser_plugin.h"
+#include "content/public/renderer/browser_plugin/browser_plugin_method_binding.h"
+#include "content/public/renderer/browser_plugin/browser_plugin_property_binding.h"
#include "content/renderer/browser_plugin/browser_plugin_constants.h"
+#include "content/renderer/browser_plugin/browser_plugin_impl.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMMessageEvent.h"
@@ -71,6 +73,10 @@ bool StringToNPVariant(const std::string &in, NPVariant *variant) {
return true;
}
+bool MatchesName(const std::string& value, NPIdentifier name) {
+ return WebKit::WebBindings::getStringIdentifier(value.c_str()) == name;
+}
+
//------------------------------------------------------------------------------
// Implementations of NPClass functions. These are here to:
// - Implement src attribute.
@@ -187,44 +193,44 @@ NPClass browser_plugin_message_class = {
} // namespace
-// BrowserPluginMethodBinding --------------------------------------------------
+// Method Bindings ------------------------------------------------------------
-class BrowserPluginMethodBinding {
+class BrowserPluginMethodBindingImpl : public BrowserPluginMethodBinding {
public:
- BrowserPluginMethodBinding(const char name[], uint32 arg_count)
- : name_(name),
+ BrowserPluginMethodBindingImpl(BrowserPluginImpl* browser_plugin,
+ const char name[],
+ uint32 arg_count)
+ : browser_plugin_(browser_plugin),
+ name_(name),
arg_count_(arg_count) {
}
- virtual ~BrowserPluginMethodBinding() {}
-
- bool MatchesName(NPIdentifier name) const {
- return WebBindings::getStringIdentifier(name_.c_str()) == name;
- }
+ virtual ~BrowserPluginMethodBindingImpl() {}
- uint32 arg_count() const { return arg_count_; }
+ BrowserPluginImpl* browser_plugin() const { return browser_plugin_; }
- virtual bool Invoke(BrowserPluginBindings* bindings,
- const NPVariant* args,
- NPVariant* result) = 0;
+ virtual const std::string& GetName() const OVERRIDE {
+ return name_;
+ }
+ virtual uint32 GetArgCount() const OVERRIDE { return arg_count_; }
private:
+ BrowserPluginImpl* browser_plugin_;
std::string name_;
uint32 arg_count_;
- DISALLOW_COPY_AND_ASSIGN(BrowserPluginMethodBinding);
+ DISALLOW_COPY_AND_ASSIGN(BrowserPluginMethodBindingImpl);
};
-class BrowserPluginBindingBack : public BrowserPluginMethodBinding {
+class BrowserPluginBindingBack : public BrowserPluginMethodBindingImpl {
public:
- BrowserPluginBindingBack()
- : BrowserPluginMethodBinding(browser_plugin::kMethodBack, 0) {
+ BrowserPluginBindingBack(BrowserPluginImpl* browser_plugin)
+ : BrowserPluginMethodBindingImpl(browser_plugin,
+ browser_plugin::kMethodBack, 0) {
}
- virtual bool Invoke(BrowserPluginBindings* bindings,
- const NPVariant* args,
- NPVariant* result) OVERRIDE {
- bindings->instance()->Back();
+ virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE {
+ browser_plugin()->Back();
return true;
}
@@ -232,16 +238,15 @@ class BrowserPluginBindingBack : public BrowserPluginMethodBinding {
DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingBack);
};
-class BrowserPluginBindingCanGoBack : public BrowserPluginMethodBinding {
+class BrowserPluginBindingCanGoBack : public BrowserPluginMethodBindingImpl {
public:
- BrowserPluginBindingCanGoBack()
- : BrowserPluginMethodBinding(browser_plugin::kMethodCanGoBack, 0) {
+ BrowserPluginBindingCanGoBack(BrowserPluginImpl* browser_plugin)
+ : BrowserPluginMethodBindingImpl(browser_plugin,
+ browser_plugin::kMethodCanGoBack, 0) {
}
- virtual bool Invoke(BrowserPluginBindings* bindings,
- const NPVariant* args,
- NPVariant* result) OVERRIDE {
- BOOLEAN_TO_NPVARIANT(bindings->instance()->CanGoBack(), *result);
+ virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE {
+ BOOLEAN_TO_NPVARIANT(browser_plugin()->CanGoBack(), *result);
return true;
}
@@ -249,16 +254,15 @@ class BrowserPluginBindingCanGoBack : public BrowserPluginMethodBinding {
DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingCanGoBack);
};
-class BrowserPluginBindingCanGoForward : public BrowserPluginMethodBinding {
+class BrowserPluginBindingCanGoForward : public BrowserPluginMethodBindingImpl {
public:
- BrowserPluginBindingCanGoForward()
- : BrowserPluginMethodBinding(browser_plugin::kMethodCanGoForward, 0) {
+ BrowserPluginBindingCanGoForward(BrowserPluginImpl* browser_plugin)
+ : BrowserPluginMethodBindingImpl(browser_plugin,
+ browser_plugin::kMethodCanGoForward, 0) {
}
- virtual bool Invoke(BrowserPluginBindings* bindings,
- const NPVariant* args,
- NPVariant* result) OVERRIDE {
- BOOLEAN_TO_NPVARIANT(bindings->instance()->CanGoForward(), *result);
+ virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE {
+ BOOLEAN_TO_NPVARIANT(browser_plugin()->CanGoForward(), *result);
return true;
}
@@ -266,16 +270,15 @@ class BrowserPluginBindingCanGoForward : public BrowserPluginMethodBinding {
DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingCanGoForward);
};
-class BrowserPluginBindingForward : public BrowserPluginMethodBinding {
+class BrowserPluginBindingForward : public BrowserPluginMethodBindingImpl {
public:
- BrowserPluginBindingForward()
- : BrowserPluginMethodBinding(browser_plugin::kMethodForward, 0) {
+ BrowserPluginBindingForward(BrowserPluginImpl* browser_plugin)
+ : BrowserPluginMethodBindingImpl(browser_plugin,
+ browser_plugin::kMethodForward, 0) {
}
- virtual bool Invoke(BrowserPluginBindings* bindings,
- const NPVariant* args,
- NPVariant* result) OVERRIDE {
- bindings->instance()->Forward();
+ virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE {
+ browser_plugin()->Forward();
return true;
}
@@ -285,17 +288,15 @@ class BrowserPluginBindingForward : public BrowserPluginMethodBinding {
// Note: This is a method that is used internally by the <webview> shim only.
// This should not be exposed to developers.
-class BrowserPluginBindingGetRouteID : public BrowserPluginMethodBinding {
+class BrowserPluginBindingGetRouteID : public BrowserPluginMethodBindingImpl {
public:
- BrowserPluginBindingGetRouteID()
- : BrowserPluginMethodBinding(browser_plugin::kMethodGetRouteId, 0) {
+ BrowserPluginBindingGetRouteID(BrowserPluginImpl* browser_plugin)
+ : BrowserPluginMethodBindingImpl(browser_plugin,
+ browser_plugin::kMethodGetRouteId, 0) {
}
- virtual bool Invoke(BrowserPluginBindings* bindings,
- const NPVariant* args,
- NPVariant* result) OVERRIDE {
- int route_id = bindings->instance()->guest_route_id();
- INT32_TO_NPVARIANT(route_id, *result);
+ virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE {
+ INT32_TO_NPVARIANT(browser_plugin()->guest_route_id(), *result);
return true;
}
@@ -303,17 +304,16 @@ class BrowserPluginBindingGetRouteID : public BrowserPluginMethodBinding {
DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingGetRouteID);
};
-class BrowserPluginBindingGetProcessID : public BrowserPluginMethodBinding {
+class BrowserPluginBindingGetProcessID :
+ public BrowserPluginMethodBindingImpl {
public:
- BrowserPluginBindingGetProcessID()
- : BrowserPluginMethodBinding(browser_plugin::kMethodGetProcessId, 0) {
+ BrowserPluginBindingGetProcessID(BrowserPluginImpl* browser_plugin)
+ : BrowserPluginMethodBindingImpl(browser_plugin,
+ browser_plugin::kMethodGetProcessId, 0) {
}
- virtual bool Invoke(BrowserPluginBindings* bindings,
- const NPVariant* args,
- NPVariant* result) OVERRIDE {
- int process_id = bindings->instance()->guest_process_id();
- INT32_TO_NPVARIANT(process_id, *result);
+ virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE {
+ INT32_TO_NPVARIANT(browser_plugin()->guest_process_id(), *result);
return true;
}
@@ -321,16 +321,15 @@ class BrowserPluginBindingGetProcessID : public BrowserPluginMethodBinding {
DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingGetProcessID);
};
-class BrowserPluginBindingGo : public BrowserPluginMethodBinding {
+class BrowserPluginBindingGo : public BrowserPluginMethodBindingImpl {
public:
- BrowserPluginBindingGo()
- : BrowserPluginMethodBinding(browser_plugin::kMethodGo, 1) {
+ BrowserPluginBindingGo(BrowserPluginImpl* browser_plugin)
+ : BrowserPluginMethodBindingImpl(browser_plugin,
+ browser_plugin::kMethodGo, 1) {
}
- virtual bool Invoke(BrowserPluginBindings* bindings,
- const NPVariant* args,
- NPVariant* result) OVERRIDE {
- bindings->instance()->Go(Int32FromNPVariant(args[0]));
+ virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE {
+ browser_plugin()->Go(Int32FromNPVariant(args[0]));
return true;
}
@@ -341,17 +340,15 @@ class BrowserPluginBindingGo : public BrowserPluginMethodBinding {
// Note: This is a method that is used internally by the <webview> shim only.
// This should not be exposed to developers.
class BrowserPluginBindingPersistRequestObject
- : public BrowserPluginMethodBinding {
+ : public BrowserPluginMethodBindingImpl {
public:
- BrowserPluginBindingPersistRequestObject()
- : BrowserPluginMethodBinding(browser_plugin::kMethodInternalPersistObject,
- 3) {
+ BrowserPluginBindingPersistRequestObject(BrowserPluginImpl* browser_plugin)
+ : BrowserPluginMethodBindingImpl(
+ browser_plugin, browser_plugin::kMethodInternalPersistObject, 3) {
}
- virtual bool Invoke(BrowserPluginBindings* bindings,
- const NPVariant* args,
- NPVariant* result) OVERRIDE {
- bindings->instance()->PersistRequestObject(
+ virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE {
+ browser_plugin()->PersistRequestObject(
args, StringFromNPVariant(args[1]), Int32FromNPVariant(args[2]));
return true;
}
@@ -360,16 +357,15 @@ class BrowserPluginBindingPersistRequestObject
DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingPersistRequestObject);
};
-class BrowserPluginBindingReload : public BrowserPluginMethodBinding {
+class BrowserPluginBindingReload : public BrowserPluginMethodBindingImpl {
public:
- BrowserPluginBindingReload()
- : BrowserPluginMethodBinding(browser_plugin::kMethodReload, 0) {
+ BrowserPluginBindingReload(BrowserPluginImpl* browser_plugin)
+ : BrowserPluginMethodBindingImpl(browser_plugin,
+ browser_plugin::kMethodReload, 0) {
}
- virtual bool Invoke(BrowserPluginBindings* bindings,
- const NPVariant* args,
- NPVariant* result) OVERRIDE {
- bindings->instance()->Reload();
+ virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE {
+ browser_plugin()->Reload();
return true;
}
@@ -377,16 +373,15 @@ class BrowserPluginBindingReload : public BrowserPluginMethodBinding {
DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingReload);
};
-class BrowserPluginBindingStop : public BrowserPluginMethodBinding {
+class BrowserPluginBindingStop : public BrowserPluginMethodBindingImpl {
public:
- BrowserPluginBindingStop()
- : BrowserPluginMethodBinding(browser_plugin::kMethodStop, 0) {
+ BrowserPluginBindingStop(BrowserPluginImpl* browser_plugin)
+ : BrowserPluginMethodBindingImpl(browser_plugin,
+ browser_plugin::kMethodStop, 0) {
}
- virtual bool Invoke(BrowserPluginBindings* bindings,
- const NPVariant* args,
- NPVariant* result) OVERRIDE {
- bindings->instance()->Stop();
+ virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE {
+ browser_plugin()->Stop();
return true;
}
@@ -396,19 +391,18 @@ class BrowserPluginBindingStop : public BrowserPluginMethodBinding {
// Note: This is a method that is used internally by the <webview> shim only.
// This should not be exposed to developers.
-class BrowserPluginBindingSetPermission : public BrowserPluginMethodBinding {
+class BrowserPluginBindingSetPermission
+ : public BrowserPluginMethodBindingImpl {
public:
- BrowserPluginBindingSetPermission()
- : BrowserPluginMethodBinding(
- browser_plugin::kMethodInternalSetPermission, 2) {
+ BrowserPluginBindingSetPermission(BrowserPluginImpl* browser_plugin)
+ : BrowserPluginMethodBindingImpl(
+ browser_plugin, browser_plugin::kMethodInternalSetPermission, 2) {
}
- virtual bool Invoke(BrowserPluginBindings* bindings,
- const NPVariant* args,
- NPVariant* result) OVERRIDE {
+ virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE {
int request_id = Int32FromNPVariant(args[0]);
bool allow = NPVARIANT_TO_BOOLEAN(args[1]);
- bindings->instance()->OnEmbedderDecidedPermission(request_id, allow);
+ browser_plugin()->OnEmbedderDecidedPermission(request_id, allow);
return true;
}
@@ -416,16 +410,15 @@ class BrowserPluginBindingSetPermission : public BrowserPluginMethodBinding {
DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingSetPermission);
};
-class BrowserPluginBindingTerminate : public BrowserPluginMethodBinding {
+class BrowserPluginBindingTerminate : public BrowserPluginMethodBindingImpl {
public:
- BrowserPluginBindingTerminate()
- : BrowserPluginMethodBinding(browser_plugin::kMethodTerminate, 0) {
+ BrowserPluginBindingTerminate(BrowserPluginImpl* browser_plugin)
+ : BrowserPluginMethodBindingImpl(browser_plugin,
+ browser_plugin::kMethodTerminate, 0) {
}
- virtual bool Invoke(BrowserPluginBindings* bindings,
- const NPVariant* args,
- NPVariant* result) OVERRIDE {
- bindings->instance()->TerminateGuest();
+ virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE {
+ browser_plugin()->TerminateGuest();
return true;
}
@@ -433,27 +426,28 @@ class BrowserPluginBindingTerminate : public BrowserPluginMethodBinding {
DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingTerminate);
};
-// BrowserPluginPropertyBinding ------------------------------------------------
+// Property Bindings ----------------------------------------------------------
-class BrowserPluginPropertyBinding {
+class BrowserPluginPropertyBindingImpl : public BrowserPluginPropertyBinding {
public:
- explicit BrowserPluginPropertyBinding(const char name[]) : name_(name) {}
- virtual ~BrowserPluginPropertyBinding() {}
- const std::string& name() const { return name_; }
- bool MatchesName(NPIdentifier name) const {
- return WebBindings::getStringIdentifier(name_.c_str()) == name;
- }
- virtual bool GetProperty(BrowserPluginBindings* bindings,
- NPVariant* result) = 0;
- virtual bool SetProperty(BrowserPluginBindings* bindings,
- NPObject* np_obj,
- const NPVariant* variant) = 0;
- virtual void RemoveProperty(BrowserPluginBindings* bindings,
- NPObject* np_obj) = 0;
+ BrowserPluginPropertyBindingImpl(BrowserPluginImpl* browser_plugin,
+ const char name[])
+ : browser_plugin_(browser_plugin),
+ name_(name) {}
+
+ virtual ~BrowserPluginPropertyBindingImpl() {}
+
+ BrowserPluginImpl* browser_plugin() const {
+ return browser_plugin_;
+ }
+
+ // BrowserPluginPropertyBinding implementation.
+ virtual const std::string& GetName() const OVERRIDE {
+ return name_;
+ }
// Updates the DOM Attribute value with the current property value.
- void UpdateDOMAttribute(BrowserPluginBindings* bindings,
- std::string new_value) {
- bindings->instance()->UpdateDOMAttribute(name(), new_value);
+ void UpdateDOMAttribute(std::string new_value) {
+ browser_plugin_->UpdateDOMAttribute(name_, new_value);
}
protected:
// Depending on where the attribute comes from it could be a string, int32,
@@ -475,260 +469,240 @@ class BrowserPluginPropertyBinding {
}
return value;
}
+
private:
+ BrowserPluginImpl* browser_plugin_;
std::string name_;
- DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBinding);
+ DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingImpl);
};
class BrowserPluginPropertyBindingAutoSize
- : public BrowserPluginPropertyBinding {
+ : public BrowserPluginPropertyBindingImpl {
public:
- BrowserPluginPropertyBindingAutoSize()
- : BrowserPluginPropertyBinding(browser_plugin::kAttributeAutoSize) {
+ BrowserPluginPropertyBindingAutoSize(BrowserPluginImpl* browser_plugin) :
+ BrowserPluginPropertyBindingImpl(browser_plugin,
+ browser_plugin::kAttributeAutoSize) {
}
- virtual bool GetProperty(BrowserPluginBindings* bindings,
- NPVariant* result) OVERRIDE {
- bool auto_size = bindings->instance()->GetAutoSizeAttribute();
- BOOLEAN_TO_NPVARIANT(auto_size, *result);
+ virtual bool GetProperty(NPVariant* result) OVERRIDE {
+ BOOLEAN_TO_NPVARIANT(browser_plugin()->GetAutoSizeAttribute(), *result);
return true;
}
- virtual bool SetProperty(BrowserPluginBindings* bindings,
- NPObject* np_obj,
+ virtual bool SetProperty(NPObject* np_obj,
const NPVariant* variant) OVERRIDE {
std::string value = StringFromNPVariant(*variant);
- if (!bindings->instance()->HasDOMAttribute(name())) {
- UpdateDOMAttribute(bindings, value);
- bindings->instance()->ParseAutoSizeAttribute();
+ if (!browser_plugin()->HasDOMAttribute(GetName())) {
+ UpdateDOMAttribute(value);
+ browser_plugin()->ParseAutoSizeAttribute();
} else {
- UpdateDOMAttribute(bindings, value);
+ UpdateDOMAttribute(value);
}
return true;
}
- virtual void RemoveProperty(BrowserPluginBindings* bindings,
- NPObject* np_obj) OVERRIDE {
- bindings->instance()->RemoveDOMAttribute(name());
- bindings->instance()->ParseAutoSizeAttribute();
+ virtual void RemoveProperty(NPObject* np_obj) OVERRIDE {
+ browser_plugin()->RemoveDOMAttribute(GetName());
+ browser_plugin()->ParseAutoSizeAttribute();
}
private:
DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingAutoSize);
};
class BrowserPluginPropertyBindingContentWindow
- : public BrowserPluginPropertyBinding {
+ : public BrowserPluginPropertyBindingImpl {
public:
- BrowserPluginPropertyBindingContentWindow()
- : BrowserPluginPropertyBinding(browser_plugin::kAttributeContentWindow) {
+ BrowserPluginPropertyBindingContentWindow(BrowserPluginImpl* browser_plugin) :
+ BrowserPluginPropertyBindingImpl(
+ browser_plugin,
+ browser_plugin::kAttributeContentWindow) {
}
- virtual bool GetProperty(BrowserPluginBindings* bindings,
- NPVariant* result) OVERRIDE {
- NPObject* obj = bindings->instance()->GetContentWindow();
+ virtual bool GetProperty(NPVariant* result) OVERRIDE {
+ NPObject* obj = browser_plugin()->GetContentWindow();
if (obj) {
result->type = NPVariantType_Object;
result->value.objectValue = WebBindings::retainObject(obj);
}
return true;
}
- virtual bool SetProperty(BrowserPluginBindings* bindings,
- NPObject* np_obj,
+ virtual bool SetProperty(NPObject* np_obj,
const NPVariant* variant) OVERRIDE {
return false;
}
- virtual void RemoveProperty(BrowserPluginBindings* bindings,
- NPObject* np_obj) OVERRIDE {}
+ virtual void RemoveProperty(NPObject* np_obj) OVERRIDE {}
private:
DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingContentWindow);
};
class BrowserPluginPropertyBindingMaxHeight
- : public BrowserPluginPropertyBinding {
+ : public BrowserPluginPropertyBindingImpl {
public:
- BrowserPluginPropertyBindingMaxHeight()
- : BrowserPluginPropertyBinding(browser_plugin::kAttributeMaxHeight) {
+ BrowserPluginPropertyBindingMaxHeight(BrowserPluginImpl* browser_plugin) :
+ BrowserPluginPropertyBindingImpl(browser_plugin,
+ browser_plugin::kAttributeMaxHeight) {
}
- virtual bool GetProperty(BrowserPluginBindings* bindings,
- NPVariant* result) OVERRIDE {
- int max_height = bindings->instance()->GetMaxHeightAttribute();
- INT32_TO_NPVARIANT(max_height, *result);
+ virtual bool GetProperty(NPVariant* result) OVERRIDE {
+ INT32_TO_NPVARIANT(browser_plugin()->GetMaxHeightAttribute(), *result);
return true;
}
- virtual bool SetProperty(BrowserPluginBindings* bindings,
- NPObject* np_obj,
+ virtual bool SetProperty(NPObject* np_obj,
const NPVariant* variant) OVERRIDE {
int new_value = IntFromNPVariant(variant);
- if (bindings->instance()->GetMaxHeightAttribute() != new_value) {
- UpdateDOMAttribute(bindings, base::IntToString(new_value));
- bindings->instance()->ParseSizeContraintsChanged();
+ if (browser_plugin()->GetMaxHeightAttribute() != new_value) {
+ UpdateDOMAttribute(base::IntToString(new_value));
+ browser_plugin()->ParseSizeContraintsChanged();
}
return true;
}
- virtual void RemoveProperty(BrowserPluginBindings* bindings,
- NPObject* np_obj) OVERRIDE {
- bindings->instance()->RemoveDOMAttribute(name());
- bindings->instance()->ParseSizeContraintsChanged();
+ virtual void RemoveProperty(NPObject* np_obj) OVERRIDE {
+ browser_plugin()->RemoveDOMAttribute(GetName());
+ browser_plugin()->ParseSizeContraintsChanged();
}
private:
DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMaxHeight);
};
class BrowserPluginPropertyBindingMaxWidth
- : public BrowserPluginPropertyBinding {
+ : public BrowserPluginPropertyBindingImpl {
public:
- BrowserPluginPropertyBindingMaxWidth()
- : BrowserPluginPropertyBinding(browser_plugin::kAttributeMaxWidth) {
+ BrowserPluginPropertyBindingMaxWidth(BrowserPluginImpl* browser_plugin) :
+ BrowserPluginPropertyBindingImpl(browser_plugin,
+ browser_plugin::kAttributeMaxWidth) {
}
- virtual bool GetProperty(BrowserPluginBindings* bindings,
- NPVariant* result) OVERRIDE {
- int max_width = bindings->instance()->GetMaxWidthAttribute();
- INT32_TO_NPVARIANT(max_width, *result);
+ virtual bool GetProperty(NPVariant* result) OVERRIDE {
+ INT32_TO_NPVARIANT(browser_plugin()->GetMaxWidthAttribute(), *result);
return true;
}
- virtual bool SetProperty(BrowserPluginBindings* bindings,
- NPObject* np_obj,
+ virtual bool SetProperty(NPObject* np_obj,
const NPVariant* variant) OVERRIDE {
int new_value = IntFromNPVariant(variant);
- if (bindings->instance()->GetMaxWidthAttribute() != new_value) {
- UpdateDOMAttribute(bindings, base::IntToString(new_value));
- bindings->instance()->ParseSizeContraintsChanged();
+ if (browser_plugin()->GetMaxWidthAttribute() != new_value) {
+ UpdateDOMAttribute(base::IntToString(new_value));
+ browser_plugin()->ParseSizeContraintsChanged();
}
return true;
}
- virtual void RemoveProperty(BrowserPluginBindings* bindings,
- NPObject* np_obj) OVERRIDE {
- bindings->instance()->RemoveDOMAttribute(name());
- bindings->instance()->ParseSizeContraintsChanged();
+ virtual void RemoveProperty(NPObject* np_obj) OVERRIDE {
+ browser_plugin()->RemoveDOMAttribute(GetName());
+ browser_plugin()->ParseSizeContraintsChanged();
}
private:
DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMaxWidth);
};
class BrowserPluginPropertyBindingMinHeight
- : public BrowserPluginPropertyBinding {
+ : public BrowserPluginPropertyBindingImpl {
public:
- BrowserPluginPropertyBindingMinHeight()
- : BrowserPluginPropertyBinding(browser_plugin::kAttributeMinHeight) {
+ BrowserPluginPropertyBindingMinHeight(BrowserPluginImpl* browser_plugin) :
+ BrowserPluginPropertyBindingImpl(browser_plugin,
+ browser_plugin::kAttributeMinHeight) {
}
- virtual bool GetProperty(BrowserPluginBindings* bindings,
- NPVariant* result) OVERRIDE {
- int min_height = bindings->instance()->GetMinHeightAttribute();
- INT32_TO_NPVARIANT(min_height, *result);
+ virtual bool GetProperty(NPVariant* result) OVERRIDE {
+ INT32_TO_NPVARIANT(browser_plugin()->GetMinHeightAttribute(), *result);
return true;
}
- virtual bool SetProperty(BrowserPluginBindings* bindings,
- NPObject* np_obj,
+ virtual bool SetProperty(NPObject* np_obj,
const NPVariant* variant) OVERRIDE {
int new_value = IntFromNPVariant(variant);
- if (bindings->instance()->GetMinHeightAttribute() != new_value) {
- UpdateDOMAttribute(bindings, base::IntToString(new_value));
- bindings->instance()->ParseSizeContraintsChanged();
+ if (browser_plugin()->GetMinHeightAttribute() != new_value) {
+ UpdateDOMAttribute(base::IntToString(new_value));
+ browser_plugin()->ParseSizeContraintsChanged();
}
return true;
}
- virtual void RemoveProperty(BrowserPluginBindings* bindings,
- NPObject* np_obj) OVERRIDE {
- bindings->instance()->RemoveDOMAttribute(name());
- bindings->instance()->ParseSizeContraintsChanged();
+ virtual void RemoveProperty(NPObject* np_obj) OVERRIDE {
+ browser_plugin()->RemoveDOMAttribute(GetName());
+ browser_plugin()->ParseSizeContraintsChanged();
}
private:
DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinHeight);
};
class BrowserPluginPropertyBindingMinWidth
- : public BrowserPluginPropertyBinding {
+ : public BrowserPluginPropertyBindingImpl {
public:
- BrowserPluginPropertyBindingMinWidth()
- : BrowserPluginPropertyBinding(browser_plugin::kAttributeMinWidth) {
+ BrowserPluginPropertyBindingMinWidth(BrowserPluginImpl* browser_plugin) :
+ BrowserPluginPropertyBindingImpl(browser_plugin,
+ browser_plugin::kAttributeMinWidth) {
}
- virtual bool GetProperty(BrowserPluginBindings* bindings,
- NPVariant* result) OVERRIDE {
- int min_width = bindings->instance()->GetMinWidthAttribute();
- INT32_TO_NPVARIANT(min_width, *result);
+ virtual bool GetProperty(NPVariant* result) OVERRIDE {
+ INT32_TO_NPVARIANT(browser_plugin()->GetMinWidthAttribute(), *result);
return true;
}
- virtual bool SetProperty(BrowserPluginBindings* bindings,
- NPObject* np_obj,
+ virtual bool SetProperty(NPObject* np_obj,
const NPVariant* variant) OVERRIDE {
int new_value = IntFromNPVariant(variant);
- if (bindings->instance()->GetMinWidthAttribute() != new_value) {
- UpdateDOMAttribute(bindings, base::IntToString(new_value));
- bindings->instance()->ParseSizeContraintsChanged();
+ if (browser_plugin()->GetMinWidthAttribute() != new_value) {
+ UpdateDOMAttribute(base::IntToString(new_value));
+ browser_plugin()->ParseSizeContraintsChanged();
}
return true;
}
- virtual void RemoveProperty(BrowserPluginBindings* bindings,
- NPObject* np_obj) OVERRIDE {
- bindings->instance()->RemoveDOMAttribute(name());
- bindings->instance()->ParseSizeContraintsChanged();
+ virtual void RemoveProperty(NPObject* np_obj) OVERRIDE {
+ browser_plugin()->RemoveDOMAttribute(GetName());
+ browser_plugin()->ParseSizeContraintsChanged();
}
private:
DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinWidth);
};
class BrowserPluginPropertyBindingName
- : public BrowserPluginPropertyBinding {
+ : public BrowserPluginPropertyBindingImpl {
public:
- BrowserPluginPropertyBindingName()
- : BrowserPluginPropertyBinding(browser_plugin::kAttributeName) {
+ BrowserPluginPropertyBindingName(BrowserPluginImpl* browser_plugin) :
+ BrowserPluginPropertyBindingImpl(browser_plugin,
+ browser_plugin::kAttributeName) {
}
- virtual bool GetProperty(BrowserPluginBindings* bindings,
- NPVariant* result) OVERRIDE {
- std::string name = bindings->instance()->GetNameAttribute();
- return StringToNPVariant(name, result);
+ virtual bool GetProperty(NPVariant* result) OVERRIDE {
+ StringToNPVariant(browser_plugin()->GetNameAttribute(), result);
return true;
}
- virtual bool SetProperty(BrowserPluginBindings* bindings,
- NPObject* np_obj,
+ virtual bool SetProperty(NPObject* np_obj,
const NPVariant* variant) OVERRIDE {
std::string new_value = StringFromNPVariant(*variant);
- if (bindings->instance()->GetNameAttribute() != new_value) {
- UpdateDOMAttribute(bindings, new_value);
- bindings->instance()->ParseNameAttribute();
+ if (browser_plugin()->GetNameAttribute() != new_value) {
+ UpdateDOMAttribute(new_value);
+ browser_plugin()->ParseNameAttribute();
}
return true;
}
- virtual void RemoveProperty(BrowserPluginBindings* bindings,
- NPObject* np_obj) OVERRIDE {
- bindings->instance()->RemoveDOMAttribute(name());
- bindings->instance()->ParseNameAttribute();
+ virtual void RemoveProperty(NPObject* np_obj) OVERRIDE {
+ browser_plugin()->RemoveDOMAttribute(GetName());
+ browser_plugin()->ParseNameAttribute();
}
private:
DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingName);
};
class BrowserPluginPropertyBindingPartition
- : public BrowserPluginPropertyBinding {
+ : public BrowserPluginPropertyBindingImpl {
public:
- BrowserPluginPropertyBindingPartition()
- : BrowserPluginPropertyBinding(browser_plugin::kAttributePartition) {
+ BrowserPluginPropertyBindingPartition(BrowserPluginImpl* browser_plugin) :
+ BrowserPluginPropertyBindingImpl(browser_plugin,
+ browser_plugin::kAttributePartition) {
}
- virtual bool GetProperty(BrowserPluginBindings* bindings,
- NPVariant* result) OVERRIDE {
- std::string partition_id = bindings->instance()->GetPartitionAttribute();
- return StringToNPVariant(partition_id, result);
+ virtual bool GetProperty(NPVariant* result) OVERRIDE {
+ return StringToNPVariant(browser_plugin()->GetPartitionAttribute(), result);
}
- virtual bool SetProperty(BrowserPluginBindings* bindings,
- NPObject* np_obj,
+ virtual bool SetProperty(NPObject* np_obj,
const NPVariant* variant) OVERRIDE {
std::string new_value = StringFromNPVariant(*variant);
- std::string old_value = bindings->instance()->GetPartitionAttribute();
+ std::string old_value = browser_plugin()->GetPartitionAttribute();
if (old_value != new_value) {
- UpdateDOMAttribute(bindings, new_value);
+ UpdateDOMAttribute(new_value);
std::string error_message;
- if (!bindings->instance()->ParsePartitionAttribute(&error_message)) {
+ if (!browser_plugin()->ParsePartitionAttribute(&error_message)) {
WebBindings::setException(
np_obj, static_cast<const NPUTF8 *>(error_message.c_str()));
// Reset to old value on error.
- UpdateDOMAttribute(bindings, old_value);
+ UpdateDOMAttribute(old_value);
return false;
}
}
return true;
}
- virtual void RemoveProperty(BrowserPluginBindings* bindings,
- NPObject* np_obj) OVERRIDE {
+ virtual void RemoveProperty(NPObject* np_obj) OVERRIDE {
std::string error_message;
- if (bindings->instance()->CanRemovePartitionAttribute(&error_message)) {
- bindings->instance()->RemoveDOMAttribute(name());
+ if (browser_plugin()->CanRemovePartitionAttribute(&error_message)) {
+ browser_plugin()->RemoveDOMAttribute(GetName());
} else {
WebBindings::setException(
np_obj, static_cast<const NPUTF8 *>(error_message.c_str()));
@@ -738,53 +712,51 @@ class BrowserPluginPropertyBindingPartition
DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingPartition);
};
-class BrowserPluginPropertyBindingSrc : public BrowserPluginPropertyBinding {
+class BrowserPluginPropertyBindingSrc :
+ public BrowserPluginPropertyBindingImpl {
public:
- BrowserPluginPropertyBindingSrc()
- : BrowserPluginPropertyBinding(browser_plugin::kAttributeSrc) {
+ BrowserPluginPropertyBindingSrc(BrowserPluginImpl* browser_plugin) :
+ BrowserPluginPropertyBindingImpl(browser_plugin,
+ browser_plugin::kAttributeSrc) {
}
- virtual bool GetProperty(BrowserPluginBindings* bindings,
- NPVariant* result) OVERRIDE {
- std::string src = bindings->instance()->GetSrcAttribute();
- return StringToNPVariant(src, result);
+ virtual bool GetProperty(NPVariant* result) OVERRIDE {
+ return StringToNPVariant(browser_plugin()->GetSrcAttribute(), result);
}
- virtual bool SetProperty(BrowserPluginBindings* bindings,
- NPObject* np_obj,
+ virtual bool SetProperty(NPObject* np_obj,
const NPVariant* variant) OVERRIDE {
std::string new_value = StringFromNPVariant(*variant);
// We should not be issuing navigation IPCs if we attempt to set the
// src property to the empty string. Instead, we want to simply restore
// the src attribute back to its old value.
if (new_value.empty()) {
- RemoveProperty(bindings, np_obj);
+ RemoveProperty(np_obj);
return true;
}
- std::string old_value = bindings->instance()->GetSrcAttribute();
- bool guest_crashed = bindings->instance()->guest_crashed();
+ std::string old_value = browser_plugin()->GetSrcAttribute();
+ bool guest_crashed = browser_plugin()->guest_crashed();
if ((old_value != new_value) || guest_crashed) {
// If the new value was empty then we're effectively resetting the
// attribute to the old value here. This will be picked up by <webview>'s
// mutation observer and will restore the src attribute after it has been
// removed.
- UpdateDOMAttribute(bindings, new_value);
+ UpdateDOMAttribute(new_value);
std::string error_message;
- if (!bindings->instance()->ParseSrcAttribute(&error_message)) {
+ if (!browser_plugin()->ParseSrcAttribute(&error_message)) {
WebBindings::setException(
np_obj, static_cast<const NPUTF8 *>(error_message.c_str()));
// Reset to old value on error.
- UpdateDOMAttribute(bindings, old_value);
+ UpdateDOMAttribute(old_value);
return false;
}
}
return true;
}
- virtual void RemoveProperty(BrowserPluginBindings* bindings,
- NPObject* np_obj) OVERRIDE {
- std::string old_value = bindings->instance()->GetSrcAttribute();
+ virtual void RemoveProperty(NPObject* np_obj) OVERRIDE {
+ std::string old_value = browser_plugin()->GetSrcAttribute();
// Remove the DOM attribute to trigger the mutation observer when it is
// restored to its original value again.
- bindings->instance()->RemoveDOMAttribute(name());
- UpdateDOMAttribute(bindings, old_value);
+ browser_plugin()->RemoveDOMAttribute(GetName());
+ UpdateDOMAttribute(old_value);
}
private:
DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingSrc);
@@ -799,7 +771,7 @@ BrowserPluginBindings::BrowserPluginNPObject::BrowserPluginNPObject() {
BrowserPluginBindings::BrowserPluginNPObject::~BrowserPluginNPObject() {
}
-BrowserPluginBindings::BrowserPluginBindings(BrowserPlugin* instance)
+BrowserPluginBindings::BrowserPluginBindings(BrowserPluginImpl* instance)
: instance_(instance),
np_object_(NULL),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
@@ -808,28 +780,38 @@ BrowserPluginBindings::BrowserPluginBindings(BrowserPlugin* instance)
np_object_ = static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(obj);
np_object_->message_channel = weak_ptr_factory_.GetWeakPtr();
- method_bindings_.push_back(new BrowserPluginBindingBack);
- method_bindings_.push_back(new BrowserPluginBindingCanGoBack);
- method_bindings_.push_back(new BrowserPluginBindingCanGoForward);
- method_bindings_.push_back(new BrowserPluginBindingForward);
- method_bindings_.push_back(new BrowserPluginBindingGetProcessID);
- method_bindings_.push_back(new BrowserPluginBindingGetRouteID);
- method_bindings_.push_back(new BrowserPluginBindingGo);
- method_bindings_.push_back(new BrowserPluginBindingPersistRequestObject);
- method_bindings_.push_back(new BrowserPluginBindingReload);
- method_bindings_.push_back(new BrowserPluginBindingSetPermission);
- method_bindings_.push_back(new BrowserPluginBindingStop);
- method_bindings_.push_back(new BrowserPluginBindingTerminate);
-
- property_bindings_.push_back(new BrowserPluginPropertyBindingAutoSize);
- property_bindings_.push_back(new BrowserPluginPropertyBindingContentWindow);
- property_bindings_.push_back(new BrowserPluginPropertyBindingMaxHeight);
- property_bindings_.push_back(new BrowserPluginPropertyBindingMaxWidth);
- property_bindings_.push_back(new BrowserPluginPropertyBindingMinHeight);
- property_bindings_.push_back(new BrowserPluginPropertyBindingMinWidth);
- property_bindings_.push_back(new BrowserPluginPropertyBindingName);
- property_bindings_.push_back(new BrowserPluginPropertyBindingPartition);
- property_bindings_.push_back(new BrowserPluginPropertyBindingSrc);
+ method_bindings_.push_back(new BrowserPluginBindingBack(instance));
+ method_bindings_.push_back(new BrowserPluginBindingCanGoBack(instance));
+ method_bindings_.push_back(new BrowserPluginBindingCanGoForward(instance));
+ method_bindings_.push_back(new BrowserPluginBindingForward(instance));
+ method_bindings_.push_back(new BrowserPluginBindingGetProcessID(instance));
+ method_bindings_.push_back(new BrowserPluginBindingGetRouteID(instance));
+ method_bindings_.push_back(new BrowserPluginBindingGo(instance));
+ method_bindings_.push_back(
+ new BrowserPluginBindingPersistRequestObject(instance));
+ method_bindings_.push_back(new BrowserPluginBindingReload(instance));
+ method_bindings_.push_back(new BrowserPluginBindingSetPermission(instance));
+ method_bindings_.push_back(new BrowserPluginBindingStop(instance));
+ method_bindings_.push_back(new BrowserPluginBindingTerminate(instance));
+
+ property_bindings_.push_back(
+ new BrowserPluginPropertyBindingAutoSize(instance));
+ property_bindings_.push_back(
+ new BrowserPluginPropertyBindingContentWindow(instance));
+ property_bindings_.push_back(
+ new BrowserPluginPropertyBindingMaxHeight(instance));
+ property_bindings_.push_back(
+ new BrowserPluginPropertyBindingMaxWidth(instance));
+ property_bindings_.push_back(
+ new BrowserPluginPropertyBindingMinHeight(instance));
+ property_bindings_.push_back(
+ new BrowserPluginPropertyBindingMinWidth(instance));
+ property_bindings_.push_back(
+ new BrowserPluginPropertyBindingName(instance));
+ property_bindings_.push_back(
+ new BrowserPluginPropertyBindingPartition(instance));
+ property_bindings_.push_back(
+ new BrowserPluginPropertyBindingSrc(instance));
}
BrowserPluginBindings::~BrowserPluginBindings() {
@@ -840,7 +822,8 @@ bool BrowserPluginBindings::HasMethod(NPIdentifier name) const {
for (BindingList::const_iterator iter = method_bindings_.begin();
iter != method_bindings_.end();
++iter) {
- if ((*iter)->MatchesName(name))
+ BrowserPluginMethodBinding* method = *iter;
+ if (MatchesName(method->GetName(), name))
return true;
}
return false;
@@ -853,8 +836,10 @@ bool BrowserPluginBindings::InvokeMethod(NPIdentifier name,
for (BindingList::iterator iter = method_bindings_.begin();
iter != method_bindings_.end();
++iter) {
- if ((*iter)->MatchesName(name) && (*iter)->arg_count() == arg_count)
- return (*iter)->Invoke(this, args, result);
+ BrowserPluginMethodBinding* method = *iter;
+ if (MatchesName(method->GetName(), name) &&
+ method->GetArgCount() == arg_count)
+ return method->Invoke(args, result);
}
return false;
}
@@ -863,7 +848,8 @@ bool BrowserPluginBindings::HasProperty(NPIdentifier name) const {
for (PropertyBindingList::const_iterator iter = property_bindings_.begin();
iter != property_bindings_.end();
++iter) {
- if ((*iter)->MatchesName(name))
+ BrowserPluginPropertyBinding* property = *iter;
+ if (MatchesName(property->GetName(), name))
return true;
}
return false;
@@ -875,10 +861,10 @@ bool BrowserPluginBindings::SetProperty(NPObject* np_obj,
for (PropertyBindingList::iterator iter = property_bindings_.begin();
iter != property_bindings_.end();
++iter) {
- if ((*iter)->MatchesName(name)) {
- if ((*iter)->SetProperty(this, np_obj, variant)) {
+ BrowserPluginPropertyBinding* property = *iter;
+ if (MatchesName(property->GetName(), name)) {
+ if (property->SetProperty(np_obj, variant))
return true;
- }
break;
}
}
@@ -890,8 +876,9 @@ bool BrowserPluginBindings::RemoveProperty(NPObject* np_obj,
for (PropertyBindingList::iterator iter = property_bindings_.begin();
iter != property_bindings_.end();
++iter) {
- if ((*iter)->MatchesName(name)) {
- (*iter)->RemoveProperty(this, np_obj);
+ BrowserPluginPropertyBinding* property = *iter;
+ if (MatchesName(property->GetName(), name)) {
+ property->RemoveProperty(np_obj);
return true;
}
}
@@ -902,10 +889,21 @@ bool BrowserPluginBindings::GetProperty(NPIdentifier name, NPVariant* result) {
for (PropertyBindingList::iterator iter = property_bindings_.begin();
iter != property_bindings_.end();
++iter) {
- if ((*iter)->MatchesName(name))
- return (*iter)->GetProperty(this, result);
+ BrowserPluginPropertyBinding* property = *iter;
+ if (MatchesName(property->GetName(), name))
+ return property->GetProperty(result);
}
return false;
}
+void BrowserPluginBindings::AddMethodBinding(
+ BrowserPluginMethodBinding* method_binding) {
+ method_bindings_.push_back(method_binding);
+}
+
+void BrowserPluginBindings::AddPropertyBinding(
+ BrowserPluginPropertyBinding* property_binding) {
+ property_bindings_.push_back(property_binding);
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698