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 "ui/gfx/image/image_skia.h"
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
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.
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.
36 // With the destruction of the object, the layer should get destroyed and the
37 // content should become visible again.
38 virtual ~ContentProxy();
40 // Called when the content will get unloaded.
41 void ContentWillUnload();
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.
49 // Get the image of the content. If there is no image known, an empty image
51 gfx::ImageSkia
GetContentImage();
53 // The content is about to get destroyed by its creator.
54 // Note: This function should only be used by AppActivity.
55 void OnPreContentDestroyed();
58 // Make the original (web)content visible. This call should only be paired
59 // with HideOriginalContent.
60 void ShowOriginalContent();
62 // Make the content invisible. This call should only be paired with
64 void HideOriginalContent();
66 // Creates proxy content from |web_view_|.
67 void CreateProxyContent();
69 // Creates an image from the current content.
70 bool CreateContentImage();
72 // Called once the content was read back.
73 void OnContentImageRead(bool success
, const SkBitmap
& bitmap
);
75 // Called once the image content has been converted to PNG.
76 void OnContentImageEncodeComplete(scoped_refptr
<ProxyImageData
> image
);
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 NULL. The ownership remains with the creator.
81 views::WebView
* web_view_
;
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
87 gfx::ImageSkia raw_image_
;
89 // True if the content is visible.
90 bool content_visible_
;
92 // True if the content is loaded and needs a re-layout when it gets shown
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_
;
100 // The PNG image data.
101 scoped_refptr
<base::RefCountedBytes
> png_data_
;
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_
;
108 DISALLOW_COPY_AND_ASSIGN(ContentProxy
);
111 } // namespace athena
113 #endif // ATHENA_CONTENT_CONTENT_PROXY_H_