Index: chrome/renderer/browser_plugin/chrome_webview_bindings.cc |
diff --git a/chrome/renderer/browser_plugin/chrome_webview_bindings.cc b/chrome/renderer/browser_plugin/chrome_webview_bindings.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..951d1a03c8f202872edffce3df7521e0e9e2055f |
--- /dev/null |
+++ b/chrome/renderer/browser_plugin/chrome_webview_bindings.cc |
@@ -0,0 +1,108 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/renderer/browser_plugin/chrome_browser_plugin_observer.h" |
+#include "chrome/renderer/browser_plugin/chrome_webview_bindings.h" |
+#include "chrome/renderer/browser_plugin/chrome_webview_constants.h" |
+ |
+namespace chrome { |
+ |
+namespace { |
+ |
+int Int32FromNPVariant(const NPVariant& variant) { |
+ if (NPVARIANT_IS_INT32(variant)) |
+ return NPVARIANT_TO_INT32(variant); |
+ |
+ if (NPVARIANT_IS_DOUBLE(variant)) |
+ return NPVARIANT_TO_DOUBLE(variant); |
+ |
+ return 0; |
+} |
+ |
+} // namespace |
+ |
+WebViewMethodBinding::WebViewMethodBinding( |
+ ChromeBrowserPluginObserver* browser_plugin_observer, |
+ const char name[], |
+ uint32 arg_count) |
+ : browser_plugin_observer_(browser_plugin_observer), |
+ name_(name), |
+ arg_count_(arg_count) { |
+} |
+ |
+WebViewMethodBinding::~WebViewMethodBinding() { |
+} |
+ |
+const std::string& WebViewMethodBinding::GetName() const { |
+ return name_; |
+} |
+ |
+uint32 WebViewMethodBinding::GetArgCount() const { |
+ return arg_count_; |
+} |
+ |
+//------------------------------------------------------------------------------ |
+ |
+WebViewPropertyBinding::WebViewPropertyBinding(const char name[]) |
+ : name_(name) { |
+} |
+ |
+WebViewPropertyBinding::~WebViewPropertyBinding() { |
+} |
+ |
+const std::string& WebViewPropertyBinding::GetName() const { |
+ return name_; |
+} |
+ |
+//------------------------------------------------------------------------------ |
+ |
+WebViewMethodBindingBack::WebViewMethodBindingBack( |
+ ChromeBrowserPluginObserver* browser_plugin_observer) |
+ : WebViewMethodBinding(browser_plugin_observer, webview::kMethodBack, 0) { |
+} |
+ |
+WebViewMethodBindingBack::~WebViewMethodBindingBack() { |
+} |
+ |
+bool WebViewMethodBindingBack::Invoke(const NPVariant* args, |
+ NPVariant* result) { |
+ browser_plugin_observer()->Go(-1); |
+ return true; |
+} |
+ |
+//------------------------------------------------------------------------------ |
+ |
+WebViewMethodBindingForward::WebViewMethodBindingForward( |
+ ChromeBrowserPluginObserver* browser_plugin_observer) |
+ : WebViewMethodBinding(browser_plugin_observer, |
+ webview::kMethodForward, 0) { |
+} |
+ |
+WebViewMethodBindingForward::~WebViewMethodBindingForward() { |
+} |
+ |
+bool WebViewMethodBindingForward::Invoke(const NPVariant* args, |
+ NPVariant* result) { |
+ browser_plugin_observer()->Go(1); |
+ return true; |
+} |
+ |
+//------------------------------------------------------------------------------ |
+ |
+WebViewMethodBindingGo::WebViewMethodBindingGo( |
+ ChromeBrowserPluginObserver* browser_plugin_observer) |
+ : WebViewMethodBinding(browser_plugin_observer, |
+ webview::kMethodGo, 1) { |
+} |
+ |
+WebViewMethodBindingGo::~WebViewMethodBindingGo() { |
+} |
+ |
+bool WebViewMethodBindingGo::Invoke(const NPVariant* args, |
+ NPVariant* result) { |
+ browser_plugin_observer()->Go(Int32FromNPVariant(args[0])); |
+ return true; |
+} |
+ |
+} // namespace chrome |