Change navigator.platform detection to accept either Win32 or Win64.
[chromium-blink-merge.git] / athena / content / app_activity.cc
blobc90daffa625e253e3498cdb11b9dd0ea6e9de7ca
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.h"
7 #include "athena/activity/public/activity_manager.h"
8 #include "content/public/browser/web_contents.h"
9 #include "extensions/shell/browser/shell_app_window.h"
10 #include "ui/views/controls/webview/webview.h"
12 namespace athena {
14 // TODO(mukai): specifies the same accelerators of WebActivity.
15 AppActivity::AppActivity(extensions::ShellAppWindow* app_window)
16 : app_window_(app_window),
17 web_view_(NULL),
18 current_state_(ACTIVITY_UNLOADED) {
19 DCHECK(app_window_);
22 AppActivity::~AppActivity() {
23 if (GetCurrentState() != ACTIVITY_UNLOADED)
24 SetCurrentState(ACTIVITY_UNLOADED);
27 ActivityViewModel* AppActivity::GetActivityViewModel() {
28 return this;
31 void AppActivity::SetCurrentState(Activity::ActivityState state) {
32 switch (state) {
33 case ACTIVITY_VISIBLE:
34 // Fall through (for the moment).
35 case ACTIVITY_INVISIBLE:
36 // By clearing the overview mode image we allow the content to be shown.
37 overview_mode_image_ = gfx::ImageSkia();
38 // TODO(skuhne): Find out how to reload an app from the extension system.
39 break;
40 case ACTIVITY_BACKGROUND_LOW_PRIORITY:
41 DCHECK(ACTIVITY_VISIBLE == current_state_ ||
42 ACTIVITY_INVISIBLE == current_state_);
43 // TODO(skuhne): Do this.
44 break;
45 case ACTIVITY_PERSISTENT:
46 DCHECK_EQ(ACTIVITY_BACKGROUND_LOW_PRIORITY, current_state_);
47 // TODO(skuhne): Do this.
48 break;
49 case ACTIVITY_UNLOADED:
50 DCHECK_NE(ACTIVITY_UNLOADED, current_state_);
51 // TODO(skuhne): Find out how to evict an app from the extension system.
52 // web_view_->EvictContent();
53 break;
55 // Remember the last requested state.
56 current_state_ = state;
59 Activity::ActivityState AppActivity::GetCurrentState() {
60 // TODO(skuhne): Check here also eviction status.
61 if (!web_view_) {
62 DCHECK_EQ(ACTIVITY_UNLOADED, current_state_);
63 return ACTIVITY_UNLOADED;
65 // TODO(skuhne): This should be controlled by an observer and should not
66 // reside here.
67 if (IsVisible() && current_state_ != ACTIVITY_VISIBLE)
68 SetCurrentState(ACTIVITY_VISIBLE);
69 // Note: If the activity is not visible it does not necessarily mean that it
70 // does not have GPU compositor resources (yet).
71 return current_state_;
74 bool AppActivity::IsVisible() {
75 return web_view_ && web_view_->IsDrawn();
78 Activity::ActivityMediaState AppActivity::GetMediaState() {
79 // TODO(skuhne): The function GetTabMediaStateForContents(WebContents),
80 // and the AudioStreamMonitor needs to be moved from Chrome into contents to
81 // make it more modular and so that we can use it from here.
82 return Activity::ACTIVITY_MEDIA_STATE_NONE;
85 void AppActivity::Init() {
88 SkColor AppActivity::GetRepresentativeColor() const {
89 // TODO(sad): Compute the color from the favicon.
90 return SK_ColorGRAY;
93 base::string16 AppActivity::GetTitle() const {
94 return web_view_->GetWebContents()->GetTitle();
97 bool AppActivity::UsesFrame() const {
98 return false;
101 views::View* AppActivity::GetContentsView() {
102 if (!web_view_) {
103 // TODO(oshima): use apps::NativeAppWindowViews
104 content::WebContents* web_contents =
105 app_window_->GetAssociatedWebContents();
106 web_view_ = new views::WebView(web_contents->GetBrowserContext());
107 web_view_->SetWebContents(web_contents);
108 SetCurrentState(ACTIVITY_INVISIBLE);
109 Observe(web_contents);
110 overview_mode_image_ = gfx::ImageSkia();
112 return web_view_;
115 void AppActivity::CreateOverviewModeImage() {
116 // TODO(skuhne): Implement this!
119 gfx::ImageSkia AppActivity::GetOverviewModeImage() {
120 return overview_mode_image_;
123 void AppActivity::TitleWasSet(content::NavigationEntry* entry,
124 bool explicit_set) {
125 ActivityManager::Get()->UpdateActivity(this);
128 void AppActivity::DidUpdateFaviconURL(
129 const std::vector<content::FaviconURL>& candidates) {
130 ActivityManager::Get()->UpdateActivity(this);
133 } // namespace athena