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"
14 #include "ui/wm/core/window_util.h"
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()) {
27 AppActivityProxy::~AppActivityProxy() {
28 app_activity_registry_->ProxyDestroyed(this);
31 ActivityViewModel* AppActivityProxy::GetActivityViewModel() {
35 void AppActivityProxy::SetCurrentState(ActivityState state) {
36 // We only restart the application when we are switching to visible.
37 if (state != ACTIVITY_VISIBLE)
39 app_activity_registry_->RestartApplication(this);
40 // Note: This object is now destroyed.
43 Activity::ActivityState AppActivityProxy::GetCurrentState() {
44 return ACTIVITY_UNLOADED;
47 bool AppActivityProxy::IsVisible() {
51 Activity::ActivityMediaState AppActivityProxy::GetMediaState() {
52 // This proxy has never any media playing.
53 return ACTIVITY_MEDIA_STATE_NONE;
56 aura::Window* AppActivityProxy::GetWindow() {
57 return view_->GetWidget()->GetNativeWindow();
60 content::WebContents* AppActivityProxy::GetWebContents() {
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;
81 SkColor AppActivityProxy::GetRepresentativeColor() const {
85 base::string16 AppActivityProxy::GetTitle() const {
89 gfx::ImageSkia AppActivityProxy::GetIcon() const {
90 return gfx::ImageSkia();
93 bool AppActivityProxy::UsesFrame() const {
97 views::View* AppActivityProxy::GetContentsView() {
101 views::Widget* AppActivityProxy::CreateWidget() {
105 gfx::ImageSkia AppActivityProxy::GetOverviewModeImage() {
106 return content_proxy_->GetContentImage();
109 void AppActivityProxy::PrepareContentsForOverview() {
112 void AppActivityProxy::ResetContentsView() {
115 } // namespace athena