OLD | NEW |
(Empty) | |
| 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/scoped_ptr.h" |
| 10 #include "ui/gfx/image/image_skia.h" |
| 11 |
| 12 namespace aura { |
| 13 class Window; |
| 14 } |
| 15 |
| 16 namespace views { |
| 17 class View; |
| 18 class WebView; |
| 19 } |
| 20 |
| 21 typedef unsigned int SkColor; |
| 22 |
| 23 namespace athena { |
| 24 |
| 25 class Activity; |
| 26 class AppActivity; |
| 27 class AppActivityProxy; |
| 28 class WebActivity; |
| 29 |
| 30 // This object creates and holds proxy content which gets shown instead of the |
| 31 // actual web content, generated from the passed |web_view|. |
| 32 // The created |proxy_content_| will be destroyed with the destruction of this |
| 33 // object. |
| 34 // Calling EvictContent() will release the rendered content and replaces it with |
| 35 // a solid color to save memory. |
| 36 // Calling Reparent() will transfer the |proxy_content_| to an ActivityProxy, |
| 37 // allowing the destruction of the original activity / content. |
| 38 class ContentProxy { |
| 39 public: |
| 40 // Creates the object by creating a sized down |web_view| layer and making it |
| 41 // visible inside |activity|'s window. |
| 42 ContentProxy(views::WebView* web_view, Activity* activity); |
| 43 // TODO(skuhne): Add a function to create this object from a passed PNG, so |
| 44 // that we can create it from a session restore. |
| 45 |
| 46 // With the destruction of the object, the layer should get destroyed and the |
| 47 // content should become visible again. |
| 48 virtual ~ContentProxy(); |
| 49 |
| 50 // Called when the content will get unloaded. |
| 51 void ContentWillUnload(); |
| 52 |
| 53 // Can be called to save resources by creating a layer with a solid color |
| 54 // instead of creating a content image layer. |
| 55 // Note: Currently the GPU does create a full size texture and fills it with |
| 56 // the given color - so there isn't really memory savings yet. |
| 57 void EvictContent(); |
| 58 |
| 59 // Get the image of the content. If there is no image known, an empty image |
| 60 // will be returned. |
| 61 gfx::ImageSkia GetContentImage(); |
| 62 |
| 63 // Transfer the owned |proxy_content_| to the |new_parent_window|. |
| 64 // Once called, the |web_view_| will be made visible again and the connection |
| 65 // to it will be removed since the old activity might go away. |
| 66 // Note: This function should only be used by AppActivity. |
| 67 void Reparent(aura::Window* new_parent_window); |
| 68 |
| 69 private: |
| 70 // Make the original (web)content visible. This call should only be paired |
| 71 // with HideOriginalContent. |
| 72 void ShowOriginalContent(); |
| 73 |
| 74 // Make the content invisible. This call should only be paired with |
| 75 // MakeVisible. |
| 76 void HideOriginalContent(); |
| 77 |
| 78 // Creates proxy content from |web_view_|. If there is no |web_view_|, |
| 79 // a solid |proxy_content_| with |background_color_| will be created. |
| 80 void CreateProxyContent(); |
| 81 |
| 82 // Creates a solid |proxy_content_| with |background_color_|. |
| 83 void CreateSolidProxyContent(); |
| 84 |
| 85 // Show the |proxy_content_| in the current |window_|. |
| 86 void ShowProxyContent(); |
| 87 |
| 88 // Removes the |proxy_content_| from the window again. |
| 89 void HideProxyContent(); |
| 90 |
| 91 // The web view which is associated with this object. It will be NULL after |
| 92 // the object got called with Reparent(), since the Activity which owns it |
| 93 // will be destroyed shortly after. |
| 94 views::WebView* web_view_; |
| 95 |
| 96 // The window which shows our |proxy_content_|, |
| 97 aura::Window* window_; |
| 98 |
| 99 // The background color to use when evicted. |
| 100 SkColor background_color_; |
| 101 |
| 102 // If we have an image (e.g. from session restore) it is stored here. |
| 103 gfx::ImageSkia image_; |
| 104 |
| 105 // True if the content is loaded. |
| 106 bool content_loaded_; |
| 107 |
| 108 // The content representation which which will be presented to the user. It |
| 109 // will either contain a shrunken down image of the |web_view| content or a |
| 110 // solid |background_color_|. |
| 111 scoped_ptr<views::View> proxy_content_; |
| 112 |
| 113 DISALLOW_COPY_AND_ASSIGN(ContentProxy); |
| 114 }; |
| 115 |
| 116 } // namespace athena |
| 117 |
| 118 #endif // ATHENA_CONTENT_CONTENT_PROXY_H_ |
OLD | NEW |