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/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 if (!web_view_) { |
72 DCHECK_EQ(ACTIVITY_UNLOADED, current_state_); | 66 DCHECK_EQ(ACTIVITY_UNLOADED, current_state_); |
73 return ACTIVITY_UNLOADED; | |
74 } | 67 } |
oshima
2014/09/04 16:39:23
nuke {}
Mr4D (OOO till 08-26)
2014/09/04 19:10:57
Done.
| |
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_; | 68 return current_state_; |
82 } | 69 } |
83 | 70 |
84 bool AppActivity::IsVisible() { | 71 bool AppActivity::IsVisible() { |
85 return web_view_ && | 72 return web_view_ && |
86 web_view_->IsDrawn() && | 73 web_view_->visible() && |
87 current_state_ != ACTIVITY_UNLOADED && | 74 current_state_ != ACTIVITY_UNLOADED; |
88 GetWindow() && | |
89 GetWindow()->IsVisible(); | |
90 } | 75 } |
91 | 76 |
92 Activity::ActivityMediaState AppActivity::GetMediaState() { | 77 Activity::ActivityMediaState AppActivity::GetMediaState() { |
93 // TODO(skuhne): The function GetTabMediaStateForContents(WebContents), | 78 // TODO(skuhne): The function GetTabMediaStateForContents(WebContents), |
94 // and the AudioStreamMonitor needs to be moved from Chrome into contents to | 79 // 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. | 80 // make it more modular and so that we can use it from here. |
96 return Activity::ACTIVITY_MEDIA_STATE_NONE; | 81 return Activity::ACTIVITY_MEDIA_STATE_NONE; |
97 } | 82 } |
98 | 83 |
99 aura::Window* AppActivity::GetWindow() { | 84 aura::Window* AppActivity::GetWindow() { |
100 return !web_view_ ? NULL : web_view_->GetWidget()->GetNativeWindow(); | 85 return !web_view_ ? NULL : web_view_->GetWidget()->GetNativeWindow(); |
101 } | 86 } |
102 | 87 |
103 void AppActivity::Init() { | 88 void AppActivity::Init() { |
89 DCHECK(app_activity_registry_); | |
90 Activity* app_proxy = app_activity_registry_->unloaded_activity_proxy(); | |
91 if (app_proxy) { | |
92 // TODO(skuhne): This should call the WindowListProvider to re-arrange. | |
93 // Note: At this time the |AppActivity| did not get registered to the | |
94 // |ResourceManager| - so we can move it around if needed. | |
95 aura::Window* proxy_window = app_proxy->GetWindow(); | |
96 proxy_window->parent()->StackChildBelow(GetWindow(), proxy_window); | |
97 Activity::CloseActivity(app_proxy); | |
98 // With the removal the object, the proxy should be deleted. | |
99 DCHECK(!app_activity_registry_->unloaded_activity_proxy()); | |
100 } | |
104 } | 101 } |
105 | 102 |
106 SkColor AppActivity::GetRepresentativeColor() const { | 103 SkColor AppActivity::GetRepresentativeColor() const { |
107 // TODO(sad): Compute the color from the favicon. | 104 // TODO(sad): Compute the color from the favicon. |
108 return SK_ColorGRAY; | 105 return SK_ColorGRAY; |
109 } | 106 } |
110 | 107 |
111 base::string16 AppActivity::GetTitle() const { | 108 base::string16 AppActivity::GetTitle() const { |
112 return web_view_->GetWebContents()->GetTitle(); | 109 return web_view_->GetWebContents()->GetTitle(); |
113 } | 110 } |
114 | 111 |
115 bool AppActivity::UsesFrame() const { | 112 bool AppActivity::UsesFrame() const { |
116 return false; | 113 return false; |
117 } | 114 } |
118 | 115 |
119 views::View* AppActivity::GetContentsView() { | 116 views::View* AppActivity::GetContentsView() { |
120 if (!web_view_) { | 117 if (!web_view_) { |
121 // TODO(oshima): use apps::NativeAppWindowViews | 118 // TODO(oshima): use apps::NativeAppWindowViews |
122 content::WebContents* web_contents = GetWebContents(); | 119 content::WebContents* web_contents = GetWebContents(); |
123 web_view_ = new views::WebView(web_contents->GetBrowserContext()); | 120 web_view_ = new views::WebView(web_contents->GetBrowserContext()); |
124 web_view_->SetWebContents(web_contents); | 121 web_view_->SetWebContents(web_contents); |
125 SetCurrentState(ACTIVITY_INVISIBLE); | 122 // Make sure the content gets properly shown. |
123 if (current_state_ == ACTIVITY_VISIBLE) { | |
124 MakeVisible(); | |
125 } else if (current_state_ == ACTIVITY_INVISIBLE) { | |
126 MakeInvisible(); | |
127 } else { | |
128 // If not previously specified, we change the state now to invisible.. | |
129 SetCurrentState(ACTIVITY_INVISIBLE); | |
130 } | |
126 Observe(web_contents); | 131 Observe(web_contents); |
127 overview_mode_image_ = gfx::ImageSkia(); | |
128 RegisterActivity(); | 132 RegisterActivity(); |
129 } | 133 } |
130 return web_view_; | 134 return web_view_; |
131 } | 135 } |
132 | 136 |
133 void AppActivity::CreateOverviewModeImage() { | 137 void AppActivity::CreateOverviewModeImage() { |
134 // TODO(skuhne): Implement this! | 138 // TODO(skuhne): Implement this! |
135 } | 139 } |
136 | 140 |
137 gfx::ImageSkia AppActivity::GetOverviewModeImage() { | 141 gfx::ImageSkia AppActivity::GetOverviewModeImage() { |
138 return overview_mode_image_; | 142 return overview_mode_image_; |
139 } | 143 } |
140 | 144 |
145 AppActivity::~AppActivity() { | |
146 // If this activity is registered, we unregister it now. | |
147 if (app_activity_registry_) | |
148 app_activity_registry_->UnregisterAppActivity(this); | |
149 } | |
150 | |
141 void AppActivity::TitleWasSet(content::NavigationEntry* entry, | 151 void AppActivity::TitleWasSet(content::NavigationEntry* entry, |
142 bool explicit_set) { | 152 bool explicit_set) { |
143 ActivityManager::Get()->UpdateActivity(this); | 153 ActivityManager::Get()->UpdateActivity(this); |
144 } | 154 } |
145 | 155 |
146 void AppActivity::DidUpdateFaviconURL( | 156 void AppActivity::DidUpdateFaviconURL( |
147 const std::vector<content::FaviconURL>& candidates) { | 157 const std::vector<content::FaviconURL>& candidates) { |
148 ActivityManager::Get()->UpdateActivity(this); | 158 ActivityManager::Get()->UpdateActivity(this); |
149 } | 159 } |
150 | 160 |
151 // Register an |activity| with an application. | 161 // Register an |activity| with an application. |
152 // Note: This should only get called once for an |app_window| of the | 162 // Note: This should only get called once for an |app_window| of the |
153 // |activity|. | 163 // |activity|. |
154 void AppActivity::RegisterActivity() { | 164 void AppActivity::RegisterActivity() { |
155 content::WebContents* web_contents = GetWebContents(); | 165 content::WebContents* web_contents = GetWebContents(); |
156 AppRegistry* app_registry = AppRegistry::Get(); | 166 AppRegistry* app_registry = AppRegistry::Get(); |
157 // Get the application's registry. | 167 // Get the application's registry. |
158 app_activity_registry_ = app_registry->GetAppActivityRegistry( | 168 app_activity_registry_ = app_registry->GetAppActivityRegistry( |
159 app_id_, web_contents->GetBrowserContext()); | 169 app_id_, web_contents->GetBrowserContext()); |
160 DCHECK(app_activity_registry_); | 170 DCHECK(app_activity_registry_); |
161 // Register the activity. | 171 // Register the activity. |
162 app_activity_registry_->RegisterAppActivity(this); | 172 app_activity_registry_->RegisterAppActivity(this); |
163 } | 173 } |
164 | 174 |
175 void AppActivity::MakeVisible() { | |
176 // TODO(skuhne): Once we know how to handle the Overview mode, this has to | |
177 // be moved into an ActivityContentController which is used by all activities. | |
178 // Make the content visible. | |
179 // TODO(skuhne): If this can be combined with web_activity, move this into a | |
180 // separate class. | |
181 web_view_->SetVisible(true); | |
182 web_view_->GetWebContents()->WasShown(); | |
183 // Remove our proxy image. | |
184 // TODO(skuhne): Once we have figured out how to do overview mode that code | |
185 // needs to go here. | |
186 overview_mode_image_ = gfx::ImageSkia(); | |
187 } | |
188 | |
189 void AppActivity::MakeInvisible() { | |
190 // TODO(skuhne): Once we know how to handle the Overview mode, this has to | |
191 // be moved into an ActivityContentController which is used by all activities. | |
192 // TODO(skuhne): If this can be combined with web_activity, move this into a | |
193 // separate class. | |
194 DCHECK(web_view_->visible()); | |
195 // Create our proxy image. | |
196 if (current_state_ == ACTIVITY_VISIBLE) { | |
197 // Create a proxy image of the current visible content. | |
198 // TODO(skuhne): Do this once we figure out how to do overview mode. | |
199 overview_mode_image_ = gfx::ImageSkia(); | |
200 } | |
201 // Now we can hide this. | |
202 // Note: This might have to be done asynchronously after the readback took | |
203 // place. | |
204 web_view_->GetWebContents()->WasHidden(); | |
205 web_view_->SetVisible(false); | |
206 } | |
207 | |
165 } // namespace athena | 208 } // namespace athena |
OLD | NEW |