Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / athena / content / app_activity_proxy.cc
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
16 namespace athena {
17
18 AppActivityProxy::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
27 AppActivityProxy::~AppActivityProxy() {
28   app_activity_registry_->ProxyDestroyed(this);
29 }
30
31 ActivityViewModel* AppActivityProxy::GetActivityViewModel() {
32   return this;
33 }
34
35 void 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
43 Activity::ActivityState AppActivityProxy::GetCurrentState() {
44   return ACTIVITY_UNLOADED;
45 }
46
47 bool AppActivityProxy::IsVisible() {
48   return false;
49 }
50
51 Activity::ActivityMediaState AppActivityProxy::GetMediaState() {
52   // This proxy has never any media playing.
53   return ACTIVITY_MEDIA_STATE_NONE;
54 }
55
56 aura::Window* AppActivityProxy::GetWindow() {
57   return view_->GetWidget()->GetNativeWindow();
58 }
59
60 content::WebContents* AppActivityProxy::GetWebContents() {
61   return NULL;
62 }
63
64 void 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
81 SkColor AppActivityProxy::GetRepresentativeColor() const {
82   return color_;
83 }
84
85 base::string16 AppActivityProxy::GetTitle() const {
86   return title_;
87 }
88
89 gfx::ImageSkia AppActivityProxy::GetIcon() const {
90   return gfx::ImageSkia();
91 }
92
93 bool AppActivityProxy::UsesFrame() const {
94   return true;
95 }
96
97 views::View* AppActivityProxy::GetContentsView() {
98   return view_;
99 }
100
101 views::Widget* AppActivityProxy::CreateWidget() {
102   return NULL;
103 }
104
105 gfx::ImageSkia AppActivityProxy::GetOverviewModeImage() {
106   return content_proxy_->GetContentImage();
107 }
108
109 void AppActivityProxy::PrepareContentsForOverview() {
110 }
111
112 void AppActivityProxy::ResetContentsView() {
113 }
114
115 }  // namespace athena