Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(414)

Side by Side Diff: athena/content/app_activity.cc

Issue 536013002: Decoupling visibility states from webcontent, adding visibility management in ResourceManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « athena/content/app_activity.h ('k') | athena/content/app_activity_proxy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "athena/content/app_activity.h" 5 #include "athena/content/app_activity.h"
6 6
7 #include "athena/activity/public/activity_manager.h" 7 #include "athena/activity/public/activity_manager.h"
8 #include "athena/content/app_activity_registry.h" 8 #include "athena/content/app_activity_registry.h"
9 #include "athena/content/public/app_registry.h" 9 #include "athena/content/public/app_registry.h"
10 #include "content/public/browser/web_contents.h" 10 #include "content/public/browser/web_contents.h"
11 #include "ui/aura/window.h" 11 #include "ui/aura/window.h"
12 #include "ui/views/controls/webview/webview.h" 12 #include "ui/views/controls/webview/webview.h"
13 #include "ui/views/widget/widget.h" 13 #include "ui/views/widget/widget.h"
14 14
15 namespace athena { 15 namespace athena {
16 16
17 // TODO(mukai): specifies the same accelerators of WebActivity. 17 // TODO(mukai): specifies the same accelerators of WebActivity.
18 AppActivity::AppActivity(const std::string& app_id) 18 AppActivity::AppActivity(const std::string& app_id)
19 : app_id_(app_id), 19 : app_id_(app_id),
20 web_view_(NULL), 20 web_view_(NULL),
21 current_state_(ACTIVITY_UNLOADED), 21 current_state_(ACTIVITY_UNLOADED),
22 app_activity_registry_(NULL) { 22 app_activity_registry_(NULL) {
23 } 23 }
24 24
25 AppActivity::~AppActivity() {
26 // If this activity is registered, we unregister it now.
27 if (app_activity_registry_)
28 app_activity_registry_->UnregisterAppActivity(this);
29 }
30
31 ActivityViewModel* AppActivity::GetActivityViewModel() { 25 ActivityViewModel* AppActivity::GetActivityViewModel() {
32 return this; 26 return this;
33 } 27 }
34 28
35 void AppActivity::SetCurrentState(Activity::ActivityState state) { 29 void AppActivity::SetCurrentState(Activity::ActivityState state) {
36 ActivityState current_state = state; 30 DCHECK_NE(state, current_state_);
31 ActivityState current_state = current_state_;
37 // Remember the last requested state now so that a call to GetCurrentState() 32 // Remember the last requested state now so that a call to GetCurrentState()
38 // returns the new state. 33 // returns the new state.
39 current_state_ = state; 34 current_state_ = state;
40 35
41 switch (state) { 36 switch (state) {
42 case ACTIVITY_VISIBLE: 37 case ACTIVITY_VISIBLE:
43 // Fall through (for the moment). 38 MakeVisible();
39 return;
44 case ACTIVITY_INVISIBLE: 40 case ACTIVITY_INVISIBLE:
45 // By clearing the overview mode image we allow the content to be shown. 41 if (current_state == ACTIVITY_VISIBLE)
46 overview_mode_image_ = gfx::ImageSkia(); 42 MakeInvisible();
47 // Note: A reload from the unloaded state will be performed through the
48 // |AppActivityProxy| object and no further action isn't necessary here.
49 break; 43 break;
50 case ACTIVITY_BACKGROUND_LOW_PRIORITY: 44 case ACTIVITY_BACKGROUND_LOW_PRIORITY:
51 DCHECK(ACTIVITY_VISIBLE == current_state || 45 DCHECK(ACTIVITY_VISIBLE == current_state ||
52 ACTIVITY_INVISIBLE == current_state); 46 ACTIVITY_INVISIBLE == current_state);
53 // TODO(skuhne): Do this. 47 // TODO(skuhne): Do this.
54 break; 48 break;
55 case ACTIVITY_PERSISTENT: 49 case ACTIVITY_PERSISTENT:
56 DCHECK_EQ(ACTIVITY_BACKGROUND_LOW_PRIORITY, current_state); 50 DCHECK_EQ(ACTIVITY_BACKGROUND_LOW_PRIORITY, current_state);
57 // TODO(skuhne): Do this. 51 // TODO(skuhne): Do this.
58 break; 52 break;
59 case ACTIVITY_UNLOADED: 53 case ACTIVITY_UNLOADED:
60 DCHECK_NE(ACTIVITY_UNLOADED, current_state); 54 DCHECK_NE(ACTIVITY_UNLOADED, current_state);
61 // This will cause the application to shut down, close its windows and 55 // This will cause the application to shut down, close its windows and
62 // delete this object. Instead a |AppActivityProxy| will be created as 56 // delete this object. Instead a |AppActivityProxy| will be created as
63 // place holder. 57 // place holder.
64 if (app_activity_registry_) 58 if (app_activity_registry_)
65 app_activity_registry_->Unload(); 59 app_activity_registry_->Unload();
66 break; 60 break;
67 } 61 }
68 } 62 }
69 63
70 Activity::ActivityState AppActivity::GetCurrentState() { 64 Activity::ActivityState AppActivity::GetCurrentState() {
71 if (!web_view_) { 65 DCHECK(web_view_ || ACTIVITY_UNLOADED == current_state_);
72 DCHECK_EQ(ACTIVITY_UNLOADED, current_state_);
73 return ACTIVITY_UNLOADED;
74 }
75 // TODO(skuhne): This should be controlled by an observer and should not
76 // reside here.
77 if (IsVisible() && current_state_ != ACTIVITY_VISIBLE)
78 SetCurrentState(ACTIVITY_VISIBLE);
79 // Note: If the activity is not visible it does not necessarily mean that it
80 // does not have GPU compositor resources (yet).
81 return current_state_; 66 return current_state_;
82 } 67 }
83 68
84 bool AppActivity::IsVisible() { 69 bool AppActivity::IsVisible() {
85 return web_view_ && 70 return web_view_ &&
86 web_view_->IsDrawn() && 71 web_view_->visible() &&
87 current_state_ != ACTIVITY_UNLOADED && 72 current_state_ != ACTIVITY_UNLOADED;
88 GetWindow() &&
89 GetWindow()->IsVisible();
90 } 73 }
91 74
92 Activity::ActivityMediaState AppActivity::GetMediaState() { 75 Activity::ActivityMediaState AppActivity::GetMediaState() {
93 // TODO(skuhne): The function GetTabMediaStateForContents(WebContents), 76 // TODO(skuhne): The function GetTabMediaStateForContents(WebContents),
94 // and the AudioStreamMonitor needs to be moved from Chrome into contents to 77 // and the AudioStreamMonitor needs to be moved from Chrome into contents to
95 // make it more modular and so that we can use it from here. 78 // make it more modular and so that we can use it from here.
96 return Activity::ACTIVITY_MEDIA_STATE_NONE; 79 return Activity::ACTIVITY_MEDIA_STATE_NONE;
97 } 80 }
98 81
99 aura::Window* AppActivity::GetWindow() { 82 aura::Window* AppActivity::GetWindow() {
100 return !web_view_ ? NULL : web_view_->GetWidget()->GetNativeWindow(); 83 return !web_view_ ? NULL : web_view_->GetWidget()->GetNativeWindow();
101 } 84 }
102 85
103 void AppActivity::Init() { 86 void AppActivity::Init() {
87 DCHECK(app_activity_registry_);
88 Activity* app_proxy = app_activity_registry_->unloaded_activity_proxy();
89 if (app_proxy) {
90 // TODO(skuhne): This should call the WindowListProvider to re-arrange.
91 // Note: At this time the |AppActivity| did not get registered to the
92 // |ResourceManager| - so we can move it around if needed.
93 aura::Window* proxy_window = app_proxy->GetWindow();
94 proxy_window->parent()->StackChildBelow(GetWindow(), proxy_window);
95 Activity::Delete(app_proxy);
96 // With the removal the object, the proxy should be deleted.
97 DCHECK(!app_activity_registry_->unloaded_activity_proxy());
98 }
104 } 99 }
105 100
106 SkColor AppActivity::GetRepresentativeColor() const { 101 SkColor AppActivity::GetRepresentativeColor() const {
107 // TODO(sad): Compute the color from the favicon. 102 // TODO(sad): Compute the color from the favicon.
108 return SK_ColorGRAY; 103 return SK_ColorGRAY;
109 } 104 }
110 105
111 base::string16 AppActivity::GetTitle() const { 106 base::string16 AppActivity::GetTitle() const {
112 return web_view_->GetWebContents()->GetTitle(); 107 return web_view_->GetWebContents()->GetTitle();
113 } 108 }
114 109
115 bool AppActivity::UsesFrame() const { 110 bool AppActivity::UsesFrame() const {
116 return false; 111 return false;
117 } 112 }
118 113
119 views::View* AppActivity::GetContentsView() { 114 views::View* AppActivity::GetContentsView() {
120 if (!web_view_) { 115 if (!web_view_) {
121 // TODO(oshima): use apps::NativeAppWindowViews 116 // TODO(oshima): use apps::NativeAppWindowViews
122 content::WebContents* web_contents = GetWebContents(); 117 content::WebContents* web_contents = GetWebContents();
123 web_view_ = new views::WebView(web_contents->GetBrowserContext()); 118 web_view_ = new views::WebView(web_contents->GetBrowserContext());
124 web_view_->SetWebContents(web_contents); 119 web_view_->SetWebContents(web_contents);
125 SetCurrentState(ACTIVITY_INVISIBLE); 120 // Make sure the content gets properly shown.
121 if (current_state_ == ACTIVITY_VISIBLE) {
122 MakeVisible();
123 } else if (current_state_ == ACTIVITY_INVISIBLE) {
124 MakeInvisible();
125 } else {
126 // If not previously specified, we change the state now to invisible..
127 SetCurrentState(ACTIVITY_INVISIBLE);
128 }
126 Observe(web_contents); 129 Observe(web_contents);
127 overview_mode_image_ = gfx::ImageSkia();
128 RegisterActivity(); 130 RegisterActivity();
129 } 131 }
130 return web_view_; 132 return web_view_;
131 } 133 }
132 134
133 void AppActivity::CreateOverviewModeImage() { 135 void AppActivity::CreateOverviewModeImage() {
134 // TODO(skuhne): Implement this! 136 // TODO(skuhne): Implement this!
135 } 137 }
136 138
137 gfx::ImageSkia AppActivity::GetOverviewModeImage() { 139 gfx::ImageSkia AppActivity::GetOverviewModeImage() {
138 return overview_mode_image_; 140 return overview_mode_image_;
139 } 141 }
140 142
143 AppActivity::~AppActivity() {
144 // If this activity is registered, we unregister it now.
145 if (app_activity_registry_)
146 app_activity_registry_->UnregisterAppActivity(this);
147 }
148
141 void AppActivity::TitleWasSet(content::NavigationEntry* entry, 149 void AppActivity::TitleWasSet(content::NavigationEntry* entry,
142 bool explicit_set) { 150 bool explicit_set) {
143 ActivityManager::Get()->UpdateActivity(this); 151 ActivityManager::Get()->UpdateActivity(this);
144 } 152 }
145 153
146 void AppActivity::DidUpdateFaviconURL( 154 void AppActivity::DidUpdateFaviconURL(
147 const std::vector<content::FaviconURL>& candidates) { 155 const std::vector<content::FaviconURL>& candidates) {
148 ActivityManager::Get()->UpdateActivity(this); 156 ActivityManager::Get()->UpdateActivity(this);
149 } 157 }
150 158
151 // Register an |activity| with an application. 159 // Register an |activity| with an application.
152 // Note: This should only get called once for an |app_window| of the 160 // Note: This should only get called once for an |app_window| of the
153 // |activity|. 161 // |activity|.
154 void AppActivity::RegisterActivity() { 162 void AppActivity::RegisterActivity() {
155 content::WebContents* web_contents = GetWebContents(); 163 content::WebContents* web_contents = GetWebContents();
156 AppRegistry* app_registry = AppRegistry::Get(); 164 AppRegistry* app_registry = AppRegistry::Get();
157 // Get the application's registry. 165 // Get the application's registry.
158 app_activity_registry_ = app_registry->GetAppActivityRegistry( 166 app_activity_registry_ = app_registry->GetAppActivityRegistry(
159 app_id_, web_contents->GetBrowserContext()); 167 app_id_, web_contents->GetBrowserContext());
160 DCHECK(app_activity_registry_); 168 DCHECK(app_activity_registry_);
161 // Register the activity. 169 // Register the activity.
162 app_activity_registry_->RegisterAppActivity(this); 170 app_activity_registry_->RegisterAppActivity(this);
163 } 171 }
164 172
173 void AppActivity::MakeVisible() {
174 // TODO(skuhne): Once we know how to handle the Overview mode, this has to
175 // be moved into an ActivityContentController which is used by all activities.
176 // Make the content visible.
177 // TODO(skuhne): If this can be combined with web_activity, move this into a
178 // separate class.
179 web_view_->SetVisible(true);
180 web_view_->GetWebContents()->GetNativeView()->Show();
181
182 // Remove our proxy image.
183 // TODO(skuhne): Once we have figured out how to do overview mode that code
184 // needs to go here.
185 overview_mode_image_ = gfx::ImageSkia();
186 }
187
188 void AppActivity::MakeInvisible() {
189 // TODO(skuhne): Once we know how to handle the Overview mode, this has to
190 // be moved into an ActivityContentController which is used by all activities.
191 // TODO(skuhne): If this can be combined with web_activity, move this into a
192 // separate class.
193 DCHECK(web_view_->visible());
194 // Create our proxy image.
195 if (current_state_ == ACTIVITY_VISIBLE) {
196 // Create a proxy image of the current visible content.
197 // TODO(skuhne): Do this once we figure out how to do overview mode.
198 overview_mode_image_ = gfx::ImageSkia();
199 }
200 // Now we can hide this.
201 // Note: This might have to be done asynchronously after the readback took
202 // place.
203 web_view_->SetVisible(false);
204 web_view_->GetWebContents()->GetNativeView()->Hide();
205 }
206
165 } // namespace athena 207 } // namespace athena
OLDNEW
« no previous file with comments | « athena/content/app_activity.h ('k') | athena/content/app_activity_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698