OLD | NEW |
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/content_proxy.h" |
9 #include "athena/content/public/app_registry.h" | 10 #include "athena/content/public/app_registry.h" |
10 #include "athena/wm/public/window_list_provider.h" | 11 #include "athena/wm/public/window_list_provider.h" |
11 #include "athena/wm/public/window_manager.h" | 12 #include "athena/wm/public/window_manager.h" |
12 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
13 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
14 #include "ui/views/controls/webview/webview.h" | 15 #include "ui/views/controls/webview/webview.h" |
15 #include "ui/views/widget/widget.h" | 16 #include "ui/views/widget/widget.h" |
16 | 17 |
17 namespace athena { | 18 namespace athena { |
18 | 19 |
19 // TODO(mukai): specifies the same accelerators of WebActivity. | 20 // TODO(mukai): specifies the same accelerators of WebActivity. |
20 AppActivity::AppActivity(const std::string& app_id) | 21 AppActivity::AppActivity(const std::string& app_id) |
21 : app_id_(app_id), | 22 : app_id_(app_id), |
22 web_view_(NULL), | 23 web_view_(NULL), |
23 current_state_(ACTIVITY_UNLOADED), | 24 current_state_(ACTIVITY_UNLOADED), |
24 app_activity_registry_(NULL) { | 25 app_activity_registry_(NULL) { |
25 } | 26 } |
26 | 27 |
| 28 scoped_ptr<ContentProxy> AppActivity::GetContentProxy(aura::Window* window) { |
| 29 if (content_proxy_.get()) |
| 30 content_proxy_->Reparent(window); |
| 31 return content_proxy_.Pass(); |
| 32 } |
| 33 |
27 ActivityViewModel* AppActivity::GetActivityViewModel() { | 34 ActivityViewModel* AppActivity::GetActivityViewModel() { |
28 return this; | 35 return this; |
29 } | 36 } |
30 | 37 |
31 void AppActivity::SetCurrentState(Activity::ActivityState state) { | 38 void AppActivity::SetCurrentState(Activity::ActivityState state) { |
32 DCHECK_NE(state, current_state_); | 39 DCHECK_NE(state, current_state_); |
33 ActivityState current_state = current_state_; | 40 ActivityState current_state = current_state_; |
34 // Remember the last requested state now so that a call to GetCurrentState() | 41 // Remember the last requested state now so that a call to GetCurrentState() |
35 // returns the new state. | 42 // returns the new state. |
36 current_state_ = state; | 43 current_state_ = state; |
37 | 44 |
38 switch (state) { | 45 switch (state) { |
39 case ACTIVITY_VISIBLE: | 46 case ACTIVITY_VISIBLE: |
40 MakeVisible(); | 47 HideContentProxy(); |
41 return; | 48 return; |
42 case ACTIVITY_INVISIBLE: | 49 case ACTIVITY_INVISIBLE: |
43 if (current_state == ACTIVITY_VISIBLE) | 50 if (current_state == ACTIVITY_VISIBLE) |
44 MakeInvisible(); | 51 ShowContentProxy(); |
45 break; | 52 break; |
46 case ACTIVITY_BACKGROUND_LOW_PRIORITY: | 53 case ACTIVITY_BACKGROUND_LOW_PRIORITY: |
47 DCHECK(ACTIVITY_VISIBLE == current_state || | 54 DCHECK(ACTIVITY_VISIBLE == current_state || |
48 ACTIVITY_INVISIBLE == current_state); | 55 ACTIVITY_INVISIBLE == current_state); |
49 // TODO(skuhne): Do this. | 56 // TODO(skuhne): Do this. |
50 break; | 57 break; |
51 case ACTIVITY_PERSISTENT: | 58 case ACTIVITY_PERSISTENT: |
52 DCHECK_EQ(ACTIVITY_BACKGROUND_LOW_PRIORITY, current_state); | 59 DCHECK_EQ(ACTIVITY_BACKGROUND_LOW_PRIORITY, current_state); |
53 // TODO(skuhne): Do this. | 60 // TODO(skuhne): Do this. |
54 break; | 61 break; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 123 |
117 bool AppActivity::UsesFrame() const { | 124 bool AppActivity::UsesFrame() const { |
118 return false; | 125 return false; |
119 } | 126 } |
120 | 127 |
121 views::View* AppActivity::GetContentsView() { | 128 views::View* AppActivity::GetContentsView() { |
122 if (!web_view_) { | 129 if (!web_view_) { |
123 web_view_ = GetWebView(); | 130 web_view_ = GetWebView(); |
124 // Make sure the content gets properly shown. | 131 // Make sure the content gets properly shown. |
125 if (current_state_ == ACTIVITY_VISIBLE) { | 132 if (current_state_ == ACTIVITY_VISIBLE) { |
126 MakeVisible(); | 133 HideContentProxy(); |
127 } else if (current_state_ == ACTIVITY_INVISIBLE) { | 134 } else if (current_state_ == ACTIVITY_INVISIBLE) { |
128 MakeInvisible(); | 135 ShowContentProxy(); |
129 } else { | 136 } else { |
130 // If not previously specified, we change the state now to invisible.. | 137 // If not previously specified, we change the state now to invisible.. |
131 SetCurrentState(ACTIVITY_INVISIBLE); | 138 SetCurrentState(ACTIVITY_INVISIBLE); |
132 } | 139 } |
133 RegisterActivity(); | 140 RegisterActivity(); |
134 } | 141 } |
135 return web_view_; | 142 return web_view_; |
136 } | 143 } |
137 | 144 |
138 void AppActivity::CreateOverviewModeImage() { | |
139 // TODO(skuhne): Implement this! | |
140 } | |
141 | |
142 gfx::ImageSkia AppActivity::GetOverviewModeImage() { | 145 gfx::ImageSkia AppActivity::GetOverviewModeImage() { |
143 return overview_mode_image_; | 146 if (content_proxy_.get()) |
| 147 return content_proxy_->GetContentImage(); |
| 148 return gfx::ImageSkia(); |
144 } | 149 } |
145 | 150 |
146 void AppActivity::PrepareContentsForOverview() { | 151 void AppActivity::PrepareContentsForOverview() { |
147 // Turn on fast resizing to avoid re-laying out the web contents when | 152 // Turn on fast resizing to avoid re-laying out the web contents when |
148 // entering / exiting overview mode. | 153 // entering / exiting overview mode and the content is visible. |
149 web_view_->SetFastResize(true); | 154 if (!content_proxy_.get()) |
| 155 web_view_->SetFastResize(true); |
150 } | 156 } |
151 | 157 |
152 void AppActivity::ResetContentsView() { | 158 void AppActivity::ResetContentsView() { |
153 web_view_->SetFastResize(false); | 159 // Turn on fast resizing to avoid re-laying out the web contents when |
154 web_view_->Layout(); | 160 // entering / exiting overview mode and the content is visible. |
| 161 if (!content_proxy_.get()) { |
| 162 web_view_->SetFastResize(false); |
| 163 web_view_->Layout(); |
| 164 } |
155 } | 165 } |
156 | 166 |
157 AppActivity::~AppActivity() { | 167 AppActivity::~AppActivity() { |
158 // If this activity is registered, we unregister it now. | 168 // If this activity is registered, we unregister it now. |
159 if (app_activity_registry_) | 169 if (app_activity_registry_) |
160 app_activity_registry_->UnregisterAppActivity(this); | 170 app_activity_registry_->UnregisterAppActivity(this); |
161 } | 171 } |
162 | 172 |
163 void AppActivity::TitleWasSet(content::NavigationEntry* entry, | 173 void AppActivity::TitleWasSet(content::NavigationEntry* entry, |
164 bool explicit_set) { | 174 bool explicit_set) { |
(...skipping 12 matching lines...) Expand all Loading... |
177 content::WebContents* web_contents = web_view_->GetWebContents(); | 187 content::WebContents* web_contents = web_view_->GetWebContents(); |
178 AppRegistry* app_registry = AppRegistry::Get(); | 188 AppRegistry* app_registry = AppRegistry::Get(); |
179 // Get the application's registry. | 189 // Get the application's registry. |
180 app_activity_registry_ = app_registry->GetAppActivityRegistry( | 190 app_activity_registry_ = app_registry->GetAppActivityRegistry( |
181 app_id_, web_contents->GetBrowserContext()); | 191 app_id_, web_contents->GetBrowserContext()); |
182 DCHECK(app_activity_registry_); | 192 DCHECK(app_activity_registry_); |
183 // Register the activity. | 193 // Register the activity. |
184 app_activity_registry_->RegisterAppActivity(this); | 194 app_activity_registry_->RegisterAppActivity(this); |
185 } | 195 } |
186 | 196 |
187 void AppActivity::MakeVisible() { | 197 void AppActivity::HideContentProxy() { |
188 // TODO(skuhne): Once we know how to handle the Overview mode, this has to | 198 content_proxy_.reset(); |
189 // be moved into an ActivityContentController which is used by all activities. | |
190 // Make the content visible. | |
191 // TODO(skuhne): If this can be combined with web_activity, move this into a | |
192 // separate class. | |
193 web_view_->SetVisible(true); | |
194 web_view_->GetWebContents()->GetNativeView()->Show(); | |
195 | |
196 // Remove our proxy image. | |
197 // TODO(skuhne): Once we have figured out how to do overview mode that code | |
198 // needs to go here. | |
199 overview_mode_image_ = gfx::ImageSkia(); | |
200 } | 199 } |
201 | 200 |
202 void AppActivity::MakeInvisible() { | 201 void AppActivity::ShowContentProxy() { |
203 // TODO(skuhne): Once we know how to handle the Overview mode, this has to | 202 if (!content_proxy_.get() && web_view_) |
204 // be moved into an ActivityContentController which is used by all activities. | 203 content_proxy_.reset(new ContentProxy(web_view_, this)); |
205 // TODO(skuhne): If this can be combined with web_activity, move this into a | |
206 // separate class. | |
207 DCHECK(web_view_->visible()); | |
208 // Create our proxy image. | |
209 if (current_state_ == ACTIVITY_VISIBLE) { | |
210 // Create a proxy image of the current visible content. | |
211 // TODO(skuhne): Do this once we figure out how to do overview mode. | |
212 overview_mode_image_ = gfx::ImageSkia(); | |
213 } | |
214 // Now we can hide this. | |
215 // Note: This might have to be done asynchronously after the readback took | |
216 // place. | |
217 web_view_->SetVisible(false); | |
218 web_view_->GetWebContents()->GetNativeView()->Hide(); | |
219 } | 204 } |
220 | 205 |
221 } // namespace athena | 206 } // namespace athena |
OLD | NEW |