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 #include "athena/content/app_activity_proxy.h"
7 #include "athena/content/app_activity.h"
8 #include "athena/content/app_activity_registry.h"
9 #include "athena/wm/public/window_list_provider.h"
10 #include "athena/wm/public/window_manager.h"
11 #include "ui/aura/window.h"
12 #include "ui/views/view.h"
13 #include "ui/views/widget/widget.h"
17 AppActivityProxy::AppActivityProxy(AppActivity
* replaced_activity
,
18 AppActivityRegistry
* creator
) :
19 app_activity_registry_(creator
),
20 title_(replaced_activity
->GetActivityViewModel()->GetTitle()),
21 color_(replaced_activity
->GetActivityViewModel()->GetRepresentativeColor()),
22 replaced_activity_(replaced_activity
),
23 view_(new views::View()),
24 restart_called_(false) {
27 ActivityViewModel
* AppActivityProxy::GetActivityViewModel() {
31 void AppActivityProxy::SetCurrentState(ActivityState state
) {
32 // We only restart the application when we are switching to visible, and only
34 if (state
!= ACTIVITY_VISIBLE
|| restart_called_
)
36 restart_called_
= true;
37 app_activity_registry_
->RestartApplication(this);
38 // Note: This object is now destroyed.
41 Activity::ActivityState
AppActivityProxy::GetCurrentState() {
42 return ACTIVITY_UNLOADED
;
45 bool AppActivityProxy::IsVisible() {
49 Activity::ActivityMediaState
AppActivityProxy::GetMediaState() {
50 // This proxy has never any media playing.
51 return ACTIVITY_MEDIA_STATE_NONE
;
54 aura::Window
* AppActivityProxy::GetWindow() {
55 return view_
->GetWidget() ? view_
->GetWidget()->GetNativeWindow() : nullptr;
58 content::WebContents
* AppActivityProxy::GetWebContents() {
62 void AppActivityProxy::Init() {
63 DCHECK(replaced_activity_
);
64 // Get the content proxy to present the content.
65 content_proxy_
= replaced_activity_
->GetContentProxy();
66 WindowListProvider
* window_list_provider
=
67 WindowManager::Get()->GetWindowListProvider();
68 window_list_provider
->StackWindowBehindTo(GetWindow(),
69 replaced_activity_
->GetWindow());
70 // After the Init() function returns, the passed |replaced_activity_| might
71 // get destroyed. Since we do not need it anymore we reset it.
72 replaced_activity_
= nullptr;
75 SkColor
AppActivityProxy::GetRepresentativeColor() const {
79 base::string16
AppActivityProxy::GetTitle() const {
83 gfx::ImageSkia
AppActivityProxy::GetIcon() const {
84 return gfx::ImageSkia();
87 void AppActivityProxy::SetActivityView(ActivityView
* view
) {
90 bool AppActivityProxy::UsesFrame() const {
94 views::View
* AppActivityProxy::GetContentsView() {
98 gfx::ImageSkia
AppActivityProxy::GetOverviewModeImage() {
99 return content_proxy_
->GetContentImage();
102 void AppActivityProxy::PrepareContentsForOverview() {
105 void AppActivityProxy::ResetContentsView() {
108 AppActivityProxy::~AppActivityProxy() {
109 app_activity_registry_
->ProxyDestroyed(this);
112 } // namespace athena