103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)// found in the LICENSE file.
403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "athena/content/app_activity_proxy.h"
603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
71320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "athena/content/app_activity.h"
803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "athena/content/app_activity_registry.h"
91320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "athena/wm/public/window_list_provider.h"
101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "athena/wm/public/window_manager.h"
111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "ui/aura/window.h"
1203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "ui/views/view.h"
1303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "ui/views/widget/widget.h"
141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "ui/wm/core/window_util.h"
1503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
1603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)namespace athena {
1703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciAppActivityProxy::AppActivityProxy(AppActivity* replaced_activity,
1903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)                                   AppActivityRegistry* creator) :
2003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    app_activity_registry_(creator),
211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    title_(replaced_activity->GetActivityViewModel()->GetTitle()),
221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    color_(replaced_activity->GetActivityViewModel()->GetRepresentativeColor()),
231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    replaced_activity_(replaced_activity),
241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    view_(new views::View()) {
251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
2603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
2703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)AppActivityProxy::~AppActivityProxy() {
2803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  app_activity_registry_->ProxyDestroyed(this);
2903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)}
3003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
3103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)ActivityViewModel* AppActivityProxy::GetActivityViewModel() {
3203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  return this;
3303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)}
3403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
3503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)void AppActivityProxy::SetCurrentState(ActivityState state) {
361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // We only restart the application when we are switching to visible.
371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (state != ACTIVITY_VISIBLE)
3803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    return;
3903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  app_activity_registry_->RestartApplication(this);
4003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // Note: This object is now destroyed.
4103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)}
4203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
4303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)Activity::ActivityState AppActivityProxy::GetCurrentState() {
4403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  return ACTIVITY_UNLOADED;
4503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)}
4603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
4703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)bool AppActivityProxy::IsVisible() {
481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  return false;
4903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)}
5003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
5103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)Activity::ActivityMediaState AppActivityProxy::GetMediaState() {
5203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // This proxy has never any media playing.
5303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  return ACTIVITY_MEDIA_STATE_NONE;
5403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)}
5503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
5603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)aura::Window* AppActivityProxy::GetWindow() {
5703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  return view_->GetWidget()->GetNativeWindow();
5803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)}
5903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccicontent::WebContents* AppActivityProxy::GetWebContents() {
611320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  return NULL;
621320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
631320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
6403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)void AppActivityProxy::Init() {
651320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  DCHECK(replaced_activity_);
661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Get the content proxy to present the content.
671320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  content_proxy_ = replaced_activity_->GetContentProxy();
681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  WindowListProvider* window_list_provider =
691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      WindowManager::Get()->GetWindowListProvider();
701320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  window_list_provider->StackWindowBehindTo(GetWindow(),
711320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                            replaced_activity_->GetWindow());
721320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Creating this object was moving the activation to this window which should
731320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // not be the active window. As such we re-activate the top activity window.
741320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // TODO(skuhne): This should possibly move to the WindowListProvider.
751320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  wm::ActivateWindow(window_list_provider->GetWindowList().back());
761320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // After the Init() function returns, the passed |replaced_activity_| might
771320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // get destroyed. Since we do not need it anymore we reset it.
781320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  replaced_activity_ = NULL;
7903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)}
8003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
8103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)SkColor AppActivityProxy::GetRepresentativeColor() const {
8203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  return color_;
8303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)}
8403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
8503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)base::string16 AppActivityProxy::GetTitle() const {
8603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  return title_;
8703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)}
8803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
891320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccigfx::ImageSkia AppActivityProxy::GetIcon() const {
901320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  return gfx::ImageSkia();
911320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
921320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
9303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)bool AppActivityProxy::UsesFrame() const {
9403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  return true;
9503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)}
9603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
9703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)views::View* AppActivityProxy::GetContentsView() {
9803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  return view_;
9903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)}
10003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
1011320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciviews::Widget* AppActivityProxy::CreateWidget() {
1021320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  return NULL;
10303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)}
10403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
10503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)gfx::ImageSkia AppActivityProxy::GetOverviewModeImage() {
1061320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  return content_proxy_->GetContentImage();
1071320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
1081320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1091320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccivoid AppActivityProxy::PrepareContentsForOverview() {
1101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
1111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccivoid AppActivityProxy::ResetContentsView() {
11303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)}
11403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
11503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)}  // namespace athena
116