Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / athena / content / content_proxy.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 ATHENA_CONTENT_CONTENT_PROXY_H_
6 #define ATHENA_CONTENT_CONTENT_PROXY_H_
7
8 #include "base/macros.h"
9 #include "base/memory/ref_counted_memory.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "ui/gfx/image/image_skia.h"
13
14 namespace views {
15 class WebView;
16 }
17
18 namespace athena {
19
20 class ProxyImageData;
21
22 // This object creates and holds proxy content which gets shown instead of the
23 // actual web content, generated from the passed |web_view|.
24 // The created |proxy_content_| will be destroyed with the destruction of this
25 // object.
26 // Calling EvictContent() will release the rendered content.
27 // When ContentGetsDestroyed() gets called, the old view will be made visible
28 // and then the link to the |web_view_| will get severed.
29 class ContentProxy {
30  public:
31   // Creates the object by creating a sized down |web_view| layer.
32   explicit ContentProxy(views::WebView* web_view);
33   // TODO(skuhne): Add a function to create this object from a passed PNG, so
34   // that we can create it from a session restore.
35
36   // With the destruction of the object, the layer should get destroyed and the
37   // content should become visible again.
38   virtual ~ContentProxy();
39
40   // Called when the content will get unloaded.
41   void ContentWillUnload();
42
43   // Can be called to save resources by creating a layer with a solid color
44   // instead of creating a content image layer.
45   // Note: Currently the GPU does create a full size texture and fills it with
46   // the given color - so there isn't really memory savings yet.
47   void EvictContent();
48
49   // Get the image of the content. If there is no image known, an empty image
50   // will be returned.
51   gfx::ImageSkia GetContentImage();
52
53   // The content is about to get destroyed by its creator.
54   // Note: This function should only be used by AppActivity.
55   void OnPreContentDestroyed();
56
57  private:
58   // Make the original (web)content visible. This call should only be paired
59   // with HideOriginalContent.
60   void ShowOriginalContent();
61
62   // Make the content invisible. This call should only be paired with
63   // MakeVisible.
64   void HideOriginalContent();
65
66   // Creates proxy content from |web_view_|.
67   void CreateProxyContent();
68
69   // Creates an image from the current content.
70   bool CreateContentImage();
71
72   // Called once the content was read back.
73   void OnContentImageRead(bool success, const SkBitmap& bitmap);
74
75   // Called once the image content has been converted to PNG.
76   void OnContentImageEncodeComplete(scoped_refptr<ProxyImageData> image);
77
78   // The web view which was passed on creation and is associated with this
79   // object. It will be shown when OnPreContentDestroyed() gets called and then
80   // set to nullptr. The ownership remains with the creator.
81   views::WebView* web_view_;
82
83   // While we are doing our PNG encode, we keep the read back image to have
84   // something which we can pass back to the overview mode. (It would make no
85   // sense to the user to see that more recent windows get painted later than
86   // older ones).
87   gfx::ImageSkia raw_image_;
88
89   // True if the content is visible.
90   bool content_visible_;
91
92   // True if the content is loaded and needs a re-layout when it gets shown
93   // again.
94   bool content_loaded_;
95
96   // True if a content creation was kicked off once. This ensures that the
97   // function is never called twice.
98   bool content_creation_called_;
99
100   // The PNG image data.
101   scoped_refptr<base::RefCountedBytes> png_data_;
102
103   // Creating an encoded image from the content will be asynchronous. Use a
104   // weakptr for the callback to make sure that the read back / encoding image
105   // completion callback does not trigger on a destroyed ContentProxy.
106   base::WeakPtrFactory<ContentProxy> proxy_content_to_image_factory_;
107
108   DISALLOW_COPY_AND_ASSIGN(ContentProxy);
109 };
110
111 }  // namespace athena
112
113 #endif  // ATHENA_CONTENT_CONTENT_PROXY_H_