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.
5 #ifndef ATHENA_CONTENT_CONTENT_PROXY_H_
6 #define ATHENA_CONTENT_CONTENT_PROXY_H_
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 "content/public/browser/readback_types.h"
13 #include "ui/gfx/image/image_skia.h"
23 // This object creates and holds proxy content which gets shown instead of the
24 // actual web content, generated from the passed |web_view|.
25 // The created |proxy_content_| will be destroyed with the destruction of this
27 // Calling EvictContent() will release the rendered content.
28 // When ContentGetsDestroyed() gets called, the old view will be made visible
29 // and then the link to the |web_view_| will get severed.
32 // Creates the object by creating a sized down |web_view| layer.
33 explicit ContentProxy(views::WebView
* web_view
);
34 // TODO(skuhne): Add a function to create this object from a passed PNG, so
35 // that we can create it from a session restore.
37 // With the destruction of the object, the layer should get destroyed and the
38 // content should become visible again.
39 virtual ~ContentProxy();
41 // Called when the content will get unloaded.
42 void ContentWillUnload();
44 // Can be called to save resources by creating a layer with a solid color
45 // instead of creating a content image layer.
46 // Note: Currently the GPU does create a full size texture and fills it with
47 // the given color - so there isn't really memory savings yet.
50 // Get the image of the content. If there is no image known, an empty image
52 gfx::ImageSkia
GetContentImage();
54 // The content is about to get destroyed by its creator.
55 // Note: This function should only be used by AppActivity.
56 void OnPreContentDestroyed();
59 // Make the original (web)content visible. This call should only be paired
60 // with HideOriginalContent.
61 void ShowOriginalContent();
63 // Make the content invisible. This call should only be paired with
65 void HideOriginalContent();
67 // Creates proxy content from |web_view_|.
68 void CreateProxyContent();
70 // Creates an image from the current content.
71 bool CreateContentImage();
73 // Called once the content was read back.
74 void OnContentImageRead(const SkBitmap
& bitmap
,
75 content::ReadbackResponse response
);
77 // Called once the image content has been converted to PNG.
78 void OnContentImageEncodeComplete(scoped_refptr
<ProxyImageData
> image
);
80 // The web view which was passed on creation and is associated with this
81 // object. It will be shown when OnPreContentDestroyed() gets called and then
82 // set to nullptr. The ownership remains with the creator.
83 views::WebView
* web_view_
;
85 // While we are doing our PNG encode, we keep the read back image to have
86 // something which we can pass back to the overview mode. (It would make no
87 // sense to the user to see that more recent windows get painted later than
89 gfx::ImageSkia raw_image_
;
91 // True if the content is visible.
92 bool content_visible_
;
94 // True if the content is loaded and needs a re-layout when it gets shown
98 // True if a content creation was kicked off once. This ensures that the
99 // function is never called twice.
100 bool content_creation_called_
;
102 // The PNG image data.
103 scoped_refptr
<base::RefCountedBytes
> png_data_
;
105 // Creating an encoded image from the content will be asynchronous. Use a
106 // weakptr for the callback to make sure that the read back / encoding image
107 // completion callback does not trigger on a destroyed ContentProxy.
108 base::WeakPtrFactory
<ContentProxy
> proxy_content_to_image_factory_
;
110 DISALLOW_COPY_AND_ASSIGN(ContentProxy
);
113 } // namespace athena
115 #endif // ATHENA_CONTENT_CONTENT_PROXY_H_