Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / extensions / renderer / guest_view / guest_view_container.h
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 CHROME_RENDERER_GUEST_VIEW_GUEST_VIEW_CONTAINER_H_
6 #define CHROME_RENDERER_GUEST_VIEW_GUEST_VIEW_CONTAINER_H_
7
8 #include "base/memory/scoped_ptr.h"
9 #include "base/values.h"
10 #include "content/public/renderer/browser_plugin_delegate.h"
11 #include "content/public/renderer/render_frame_observer.h"
12 #include "extensions/renderer/scoped_persistent.h"
13
14 namespace extensions {
15
16 class GuestViewContainer : public content::BrowserPluginDelegate,
17                            public content::RenderFrameObserver {
18  public:
19   GuestViewContainer(content::RenderFrame* render_frame,
20                      const std::string& mime_type);
21   virtual ~GuestViewContainer();
22
23   static GuestViewContainer* FromID(int render_view_routing_id,
24                                     int element_instance_id);
25
26   void AttachGuest(int element_instance_id,
27                    int guest_instance_id,
28                    scoped_ptr<base::DictionaryValue> params,
29                    v8::Handle<v8::Function> callback,
30                    v8::Isolate* isolate);
31
32   // BrowserPluginDelegate implementation.
33   virtual void SetElementInstanceID(int element_instance_id) OVERRIDE;
34   virtual void DidFinishLoading() OVERRIDE;
35   virtual void DidReceiveData(const char* data, int data_length) OVERRIDE;
36
37   // RenderFrameObserver override.
38   virtual void OnDestruct() OVERRIDE;
39   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
40
41  private:
42   void OnCreateMimeHandlerViewGuestACK(int element_instance_id);
43   void OnGuestAttached(int element_instance_id, int guest_routing_id);
44
45   static bool ShouldHandleMessage(const IPC::Message& mesage);
46
47   const std::string mime_type_;
48   int element_instance_id_;
49   std::string html_string_;
50   // Save the RenderView RoutingID here so that we can use it during
51   // destruction.
52   int render_view_routing_id_;
53
54   bool attached_;
55   bool attach_pending_;
56
57   ScopedPersistent<v8::Function> callback_;
58   v8::Isolate* isolate_;
59
60   DISALLOW_COPY_AND_ASSIGN(GuestViewContainer);
61 };
62
63 }  // namespace extensions
64
65 #endif  // CHROME_RENDERER_GUEST_VIEW_GUEST_VIEW_CONTAINER_H_