Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / content / renderer / pepper / pepper_webplugin_impl.cc
index 8947d73..ecdd9e5 100644 (file)
@@ -11,9 +11,9 @@
 #include "content/public/common/page_zoom.h"
 #include "content/public/renderer/content_renderer_client.h"
 #include "content/renderer/pepper/message_channel.h"
-#include "content/renderer/pepper/npobject_var.h"
 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
 #include "content/renderer/pepper/plugin_module.h"
+#include "content/renderer/pepper/v8object_var.h"
 #include "content/renderer/render_frame_impl.h"
 #include "ppapi/shared_impl/ppapi_globals.h"
 #include "ppapi/shared_impl/var_tracker.h"
@@ -31,7 +31,7 @@
 #include "third_party/WebKit/public/web/WebPrintScalingOption.h"
 #include "url/gurl.h"
 
-using ppapi::NPObjectVar;
+using ppapi::V8ObjectVar;
 using blink::WebCanvas;
 using blink::WebPlugin;
 using blink::WebPluginContainer;
@@ -54,10 +54,9 @@ struct PepperWebPluginImpl::InitData {
   GURL url;
 };
 
-PepperWebPluginImpl::PepperWebPluginImpl(
-    PluginModule* plugin_module,
-    const WebPluginParams& params,
-    RenderFrameImpl* render_frame)
+PepperWebPluginImpl::PepperWebPluginImpl(PluginModule* plugin_module,
+                                         const WebPluginParams& params,
+                                         RenderFrameImpl* render_frame)
     : init_data_(new InitData()),
       full_frame_(params.loadManually),
       instance_object_(PP_MakeUndefined()),
@@ -75,8 +74,7 @@ PepperWebPluginImpl::PepperWebPluginImpl(
   base::debug::SetCrashKeyValue("subresource_url", init_data_->url.spec());
 }
 
-PepperWebPluginImpl::~PepperWebPluginImpl() {
-}
+PepperWebPluginImpl::~PepperWebPluginImpl() {}
 
 blink::WebPluginContainer* PepperWebPluginImpl::container() const {
   return container_;
@@ -92,9 +90,8 @@ bool PepperWebPluginImpl::initialize(WebPluginContainer* container) {
   // Enable script objects for this plugin.
   container->allowScriptObjects();
 
-  bool success = instance_->Initialize(init_data_->arg_names,
-                                       init_data_->arg_values,
-                                       full_frame_);
+  bool success = instance_->Initialize(
+      init_data_->arg_names, init_data_->arg_values, full_frame_);
   if (!success) {
     instance_->Delete();
     instance_ = NULL;
@@ -129,35 +126,32 @@ void PepperWebPluginImpl::destroy() {
   base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
 }
 
-NPObject* PepperWebPluginImpl::scriptableObject() {
+v8::Local<v8::Object> PepperWebPluginImpl::v8ScriptableObject(
+      v8::Isolate* isolate) {
   // Call through the plugin to get its instance object. The plugin should pass
   // us a reference which we release in destroy().
   if (instance_object_.type == PP_VARTYPE_UNDEFINED)
-    instance_object_ = instance_->GetInstanceObject();
+    instance_object_ = instance_->GetInstanceObject(isolate);
   // GetInstanceObject talked to the plugin which may have removed the instance
   // from the DOM, in which case instance_ would be NULL now.
   if (!instance_.get())
-    return NULL;
+    return v8::Local<v8::Object>();
 
-  scoped_refptr<NPObjectVar> object(NPObjectVar::FromPPVar(instance_object_));
+  scoped_refptr<V8ObjectVar> object_var(
+      V8ObjectVar::FromPPVar(instance_object_));
   // If there's an InstanceObject, tell the Instance's MessageChannel to pass
   // any non-postMessage calls to it.
-  if (object.get()) {
-    instance_->message_channel().SetPassthroughObject(object->np_object());
+  if (object_var.get()) {
+    MessageChannel* message_channel = instance_->message_channel();
+    if (message_channel)
+      message_channel->SetPassthroughObject(object_var->GetHandle());
   }
-  NPObject* message_channel_np_object(instance_->message_channel().np_object());
-  // The object is expected to be retained before it is returned.
-  blink::WebBindings::retainObject(message_channel_np_object);
-  return message_channel_np_object;
-}
 
-NPP PepperWebPluginImpl::pluginNPP() {
-  return instance_->instanceNPP();
+  v8::Handle<v8::Object> result = instance_->GetMessageChannelObject();
+  return result;
 }
 
-bool PepperWebPluginImpl::getFormValue(WebString& value) {
-  return false;
-}
+bool PepperWebPluginImpl::getFormValue(WebString& value) { return false; }
 
 void PepperWebPluginImpl::paint(WebCanvas* canvas, const WebRect& rect) {
   if (!instance_->FlashIsFullscreenOrPending())
@@ -182,12 +176,9 @@ void PepperWebPluginImpl::updateFocus(bool focused) {
   instance_->SetWebKitFocus(focused);
 }
 
-void PepperWebPluginImpl::updateVisibility(bool visible) {
-}
+void PepperWebPluginImpl::updateVisibility(bool visible) {}
 
-bool PepperWebPluginImpl::acceptsInputEvents() {
-  return true;
-}
+bool PepperWebPluginImpl::acceptsInputEvents() { return true; }
 
 bool PepperWebPluginImpl::handleInputEvent(const blink::WebInputEvent& event,
                                            blink::WebCursorInfo& cursor_info) {
@@ -211,7 +202,8 @@ void PepperWebPluginImpl::didReceiveData(const char* data, int data_length) {
 void PepperWebPluginImpl::didFinishLoading() {
   blink::WebURLLoaderClient* document_loader = instance_->document_loader();
   if (document_loader)
-    document_loader->didFinishLoading(NULL, 0.0);
+    document_loader->didFinishLoading(
+        NULL, 0.0, blink::WebURLLoaderClient::kUnknownEncodedDataLength);
 }
 
 void PepperWebPluginImpl::didFailLoading(const blink::WebURLError& error) {
@@ -220,16 +212,13 @@ void PepperWebPluginImpl::didFailLoading(const blink::WebURLError& error) {
     document_loader->didFail(NULL, error);
 }
 
-void PepperWebPluginImpl::didFinishLoadingFrameRequest(
-    const blink::WebURL& url,
-    void* notify_data) {
-}
+void PepperWebPluginImpl::didFinishLoadingFrameRequest(const blink::WebURL& url,
+                                                       void* notify_data) {}
 
 void PepperWebPluginImpl::didFailLoadingFrameRequest(
     const blink::WebURL& url,
     void* notify_data,
-    const blink::WebURLError& error) {
-}
+    const blink::WebURLError& error) {}
 
 bool PepperWebPluginImpl::hasSelection() const {
   return !selectionAsText().isEmpty();
@@ -261,9 +250,7 @@ void PepperWebPluginImpl::selectFindResult(bool forward) {
   instance_->SelectFindResult(forward);
 }
 
-void PepperWebPluginImpl::stopFind() {
-  instance_->StopFind();
-}
+void PepperWebPluginImpl::stopFind() { instance_->StopFind(); }
 
 bool PepperWebPluginImpl::supportsPaginatedPrint() {
   return instance_->SupportsPrintInterface();
@@ -277,25 +264,18 @@ int PepperWebPluginImpl::printBegin(const WebPrintParams& print_params) {
   return instance_->PrintBegin(print_params);
 }
 
-bool PepperWebPluginImpl::printPage(int page_number,
-                                    blink::WebCanvas* canvas) {
+bool PepperWebPluginImpl::printPage(int page_number, blink::WebCanvas* canvas) {
   return instance_->PrintPage(page_number, canvas);
 }
 
-void PepperWebPluginImpl::printEnd() {
-  return instance_->PrintEnd();
-}
+void PepperWebPluginImpl::printEnd() { return instance_->PrintEnd(); }
 
-bool PepperWebPluginImpl::canRotateView() {
-  return instance_->CanRotateView();
-}
+bool PepperWebPluginImpl::canRotateView() { return instance_->CanRotateView(); }
 
 void PepperWebPluginImpl::rotateView(RotationType type) {
   instance_->RotateView(type);
 }
 
-bool PepperWebPluginImpl::isPlaceholder() {
-  return false;
-}
+bool PepperWebPluginImpl::isPlaceholder() { return false; }
 
 }  // namespace content