Home | History | Annotate | Download | only in java
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CONTENT_RENDERER_JAVA_GIN_JAVA_BRIDGE_OBJECT_H_
      6 #define CONTENT_RENDERER_JAVA_GIN_JAVA_BRIDGE_OBJECT_H_
      7 
      8 #include <map>
      9 
     10 #include "base/memory/scoped_ptr.h"
     11 #include "base/memory/weak_ptr.h"
     12 #include "content/renderer/java/gin_java_bridge_dispatcher.h"
     13 #include "gin/handle.h"
     14 #include "gin/interceptor.h"
     15 #include "gin/object_template_builder.h"
     16 #include "gin/wrappable.h"
     17 
     18 namespace blink {
     19 class WebFrame;
     20 }
     21 
     22 namespace content {
     23 
     24 class GinJavaBridgeValueConverter;
     25 
     26 class GinJavaBridgeObject : public gin::Wrappable<GinJavaBridgeObject>,
     27                             public gin::NamedPropertyInterceptor {
     28  public:
     29   static gin::WrapperInfo kWrapperInfo;
     30 
     31   GinJavaBridgeDispatcher::ObjectID object_id() const { return object_id_; }
     32 
     33   // gin::Wrappable.
     34   virtual gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
     35       v8::Isolate* isolate) OVERRIDE;
     36 
     37   // gin::NamedPropertyInterceptor
     38   virtual v8::Local<v8::Value> GetNamedProperty(
     39       v8::Isolate* isolate, const std::string& property) OVERRIDE;
     40   virtual std::vector<std::string> EnumerateNamedProperties(
     41       v8::Isolate* isolate) OVERRIDE;
     42 
     43   static GinJavaBridgeObject* InjectNamed(
     44       blink::WebFrame* frame,
     45       const base::WeakPtr<GinJavaBridgeDispatcher>& dispatcher,
     46       const std::string& object_name,
     47       GinJavaBridgeDispatcher::ObjectID object_id);
     48   static GinJavaBridgeObject* InjectAnonymous(
     49       const base::WeakPtr<GinJavaBridgeDispatcher>& dispatcher,
     50       GinJavaBridgeDispatcher::ObjectID object_id);
     51 
     52  private:
     53   GinJavaBridgeObject(v8::Isolate* isolate,
     54                       const base::WeakPtr<GinJavaBridgeDispatcher>& dispatcher,
     55                       GinJavaBridgeDispatcher::ObjectID object_id);
     56   virtual ~GinJavaBridgeObject();
     57 
     58   v8::Handle<v8::Value> InvokeMethod(const std::string& name,
     59                                      gin::Arguments* args);
     60 
     61   base::WeakPtr<GinJavaBridgeDispatcher> dispatcher_;
     62   GinJavaBridgeDispatcher::ObjectID object_id_;
     63   scoped_ptr<GinJavaBridgeValueConverter> converter_;
     64   std::map<std::string, bool> known_methods_;
     65 
     66   DISALLOW_COPY_AND_ASSIGN(GinJavaBridgeObject);
     67 };
     68 
     69 }  // namespace content
     70 
     71 #endif  // CONTENT_RENDERER_JAVA_GIN_JAVA_BRIDGE_OBJECT_H_
     72