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#include "athena/content/app_activity_proxy.h"
6
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"
14#include "ui/wm/core/window_util.h"
15
16namespace athena {
17
18AppActivityProxy::AppActivityProxy(AppActivity* replaced_activity,
19                                   AppActivityRegistry* creator) :
20    app_activity_registry_(creator),
21    title_(replaced_activity->GetActivityViewModel()->GetTitle()),
22    color_(replaced_activity->GetActivityViewModel()->GetRepresentativeColor()),
23    replaced_activity_(replaced_activity),
24    view_(new views::View()) {
25}
26
27AppActivityProxy::~AppActivityProxy() {
28  app_activity_registry_->ProxyDestroyed(this);
29}
30
31ActivityViewModel* AppActivityProxy::GetActivityViewModel() {
32  return this;
33}
34
35void AppActivityProxy::SetCurrentState(ActivityState state) {
36  // We only restart the application when we are switching to visible.
37  if (state != ACTIVITY_VISIBLE)
38    return;
39  app_activity_registry_->RestartApplication(this);
40  // Note: This object is now destroyed.
41}
42
43Activity::ActivityState AppActivityProxy::GetCurrentState() {
44  return ACTIVITY_UNLOADED;
45}
46
47bool AppActivityProxy::IsVisible() {
48  return false;
49}
50
51Activity::ActivityMediaState AppActivityProxy::GetMediaState() {
52  // This proxy has never any media playing.
53  return ACTIVITY_MEDIA_STATE_NONE;
54}
55
56aura::Window* AppActivityProxy::GetWindow() {
57  return view_->GetWidget()->GetNativeWindow();
58}
59
60content::WebContents* AppActivityProxy::GetWebContents() {
61  return NULL;
62}
63
64void AppActivityProxy::Init() {
65  DCHECK(replaced_activity_);
66  // Get the content proxy to present the content.
67  content_proxy_ = replaced_activity_->GetContentProxy();
68  WindowListProvider* window_list_provider =
69      WindowManager::Get()->GetWindowListProvider();
70  window_list_provider->StackWindowBehindTo(GetWindow(),
71                                            replaced_activity_->GetWindow());
72  // Creating this object was moving the activation to this window which should
73  // not be the active window. As such we re-activate the top activity window.
74  // TODO(skuhne): This should possibly move to the WindowListProvider.
75  wm::ActivateWindow(window_list_provider->GetWindowList().back());
76  // After the Init() function returns, the passed |replaced_activity_| might
77  // get destroyed. Since we do not need it anymore we reset it.
78  replaced_activity_ = NULL;
79}
80
81SkColor AppActivityProxy::GetRepresentativeColor() const {
82  return color_;
83}
84
85base::string16 AppActivityProxy::GetTitle() const {
86  return title_;
87}
88
89gfx::ImageSkia AppActivityProxy::GetIcon() const {
90  return gfx::ImageSkia();
91}
92
93bool AppActivityProxy::UsesFrame() const {
94  return true;
95}
96
97views::View* AppActivityProxy::GetContentsView() {
98  return view_;
99}
100
101views::Widget* AppActivityProxy::CreateWidget() {
102  return NULL;
103}
104
105gfx::ImageSkia AppActivityProxy::GetOverviewModeImage() {
106  return content_proxy_->GetContentImage();
107}
108
109void AppActivityProxy::PrepareContentsForOverview() {
110}
111
112void AppActivityProxy::ResetContentsView() {
113}
114
115}  // namespace athena
116