OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "athena/content/app_activity.h" | 5 #include "athena/content/app_activity.h" |
6 | 6 |
7 #include "apps/shell/browser/shell_app_window.h" | 7 #include "apps/shell/browser/shell_app_window.h" |
8 #include "athena/activity/public/activity_manager.h" | 8 #include "athena/activity/public/activity_manager.h" |
9 #include "content/public/browser/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
10 #include "ui/views/controls/webview/webview.h" | 10 #include "ui/views/controls/webview/webview.h" |
11 | 11 |
12 namespace athena { | 12 namespace athena { |
13 | 13 |
14 // TODO(mukai): specifies the same accelerators of WebActivity. | 14 // TODO(mukai): specifies the same accelerators of WebActivity. |
15 AppActivity::AppActivity(apps::ShellAppWindow* app_window) | 15 AppActivity::AppActivity(apps::ShellAppWindow* app_window) |
16 : app_window_(app_window), web_view_(NULL) { | 16 : app_window_(app_window), |
| 17 web_view_(NULL), |
| 18 last_requested_state_(ACTIVITY_UNLOAD) { |
17 DCHECK(app_window_); | 19 DCHECK(app_window_); |
18 } | 20 } |
19 | 21 |
20 AppActivity::~AppActivity() { | 22 AppActivity::~AppActivity() { |
| 23 if (GetCurrentState() != ACTIVITY_STATE_UNLOADED) |
| 24 SetCurrentState(ACTIVITY_UNLOAD); |
21 } | 25 } |
22 | 26 |
23 ActivityViewModel* AppActivity::GetActivityViewModel() { | 27 ActivityViewModel* AppActivity::GetActivityViewModel() { |
24 return this; | 28 return this; |
25 } | 29 } |
26 | 30 |
| 31 void AppActivity::SetCurrentState(Activity::ActivityStateTransition state) { |
| 32 switch (state) { |
| 33 case ACTIVITY_LOAD: |
| 34 // By clearing the overview mode image we allow the content to be shown. |
| 35 overview_mode_image_ = gfx::ImageSkia(); |
| 36 // TODO(skuhne): Find out how to reload an app from the extension system. |
| 37 // If this does not work, the eviction needs to take place at a higher level. |
| 38 // if (web_view_->IsContentEvicted()) { |
| 39 // DCHECK_EQ(ACTIVITY_UNLOAD, last_requested_state_); |
| 40 // web_view_->ReloadContent(); |
| 41 // } |
| 42 break; |
| 43 case ACTIVITY_DEEP_SLEEP_1: |
| 44 DCHECK_EQ(ACTIVITY_LOAD, last_requested_state_); |
| 45 // TODO(skuhne): Do this. As soon as the new resource management is |
| 46 // agreed upon - or remove otherwise. |
| 47 break; |
| 48 case ACTIVITY_DEEP_SLEEP_2: |
| 49 DCHECK_EQ(ACTIVITY_DEEP_SLEEP_1, last_requested_state_); |
| 50 // TODO(skuhne): Do this. As soon as the new resource management is |
| 51 // agreed upon - or remove otherwise. |
| 52 break; |
| 53 case ACTIVITY_UNLOAD: |
| 54 DCHECK_NE(ACTIVITY_UNLOAD, last_requested_state_); |
| 55 // TODO(skuhne): Find out how to evict an app from the extension system. |
| 56 // web_view_->EvictContent(); |
| 57 break; |
| 58 } |
| 59 // Remember the last requested state. |
| 60 last_requested_state_ = state; |
| 61 } |
| 62 |
| 63 Activity::ActivityState AppActivity::GetCurrentState() { |
| 64 if (!web_view_) { |
| 65 DCHECK_EQ(ACTIVITY_UNLOAD, last_requested_state_); |
| 66 return ACTIVITY_STATE_UNLOADED; |
| 67 } |
| 68 |
| 69 switch(last_requested_state_) { |
| 70 case ACTIVITY_LOAD: |
| 71 if (web_view_->IsDrawn()) |
| 72 return ACTIVITY_STATE_VISIBLE; |
| 73 /* |
| 74 // TODO(skuhne): AudioStreamMonitor is currently a part of Chrome and |
| 75 // needs to be moved some levels up. |
| 76 AudioStreamMonitor* const audio_stream_monitor = |
| 77 AudioStreamMonitor::FromWebContents(contents); |
| 78 if (audio_stream_monitor && audio_stream_monitor->WasRecentlyAudible()) |
| 79 return ACTIVITY_STATE_BACKGROUND_ACTIVE; |
| 80 */ |
| 81 return ACTIVITY_STATE_HIDDEN; |
| 82 case ACTIVITY_DEEP_SLEEP_1: |
| 83 return ACTIVITY_STATE_DEEP_SLEEP_1; |
| 84 case ACTIVITY_DEEP_SLEEP_2: |
| 85 return ACTIVITY_STATE_DEEP_SLEEP_2; |
| 86 case ACTIVITY_UNLOAD: |
| 87 return ACTIVITY_STATE_UNLOADED; |
| 88 } |
| 89 return ACTIVITY_STATE_UNLOADED; |
| 90 } |
| 91 |
27 void AppActivity::Init() { | 92 void AppActivity::Init() { |
28 } | 93 } |
29 | 94 |
30 SkColor AppActivity::GetRepresentativeColor() { | 95 SkColor AppActivity::GetRepresentativeColor() { |
31 // TODO(sad): Compute the color from the favicon. | 96 // TODO(sad): Compute the color from the favicon. |
32 return SK_ColorGRAY; | 97 return SK_ColorGRAY; |
33 } | 98 } |
34 | 99 |
35 base::string16 AppActivity::GetTitle() { | 100 base::string16 AppActivity::GetTitle() { |
36 return web_view_->GetWebContents()->GetTitle(); | 101 return web_view_->GetWebContents()->GetTitle(); |
37 } | 102 } |
38 | 103 |
39 views::View* AppActivity::GetContentsView() { | 104 views::View* AppActivity::GetContentsView() { |
40 if (!web_view_) { | 105 if (!web_view_) { |
41 content::WebContents* web_contents = | 106 content::WebContents* web_contents = |
42 app_window_->GetAssociatedWebContents(); | 107 app_window_->GetAssociatedWebContents(); |
43 web_view_ = new views::WebView(web_contents->GetBrowserContext()); | 108 web_view_ = new views::WebView(web_contents->GetBrowserContext()); |
44 web_view_->SetWebContents(web_contents); | 109 web_view_->SetWebContents(web_contents); |
| 110 SetCurrentState(ACTIVITY_LOAD); |
45 Observe(web_contents); | 111 Observe(web_contents); |
| 112 overview_mode_image_ = gfx::ImageSkia(); |
46 } | 113 } |
47 return web_view_; | 114 return web_view_; |
48 } | 115 } |
49 | 116 |
| 117 void AppActivity::CreateOverviewModeImage() { |
| 118 // TODO(skuhne): Implement this! |
| 119 } |
| 120 |
| 121 gfx::ImageSkia AppActivity::GetOverviewModeImage() { |
| 122 return overview_mode_image_; |
| 123 } |
| 124 |
50 void AppActivity::TitleWasSet(content::NavigationEntry* entry, | 125 void AppActivity::TitleWasSet(content::NavigationEntry* entry, |
51 bool explicit_set) { | 126 bool explicit_set) { |
52 ActivityManager::Get()->UpdateActivity(this); | 127 ActivityManager::Get()->UpdateActivity(this); |
53 } | 128 } |
54 | 129 |
55 void AppActivity::DidUpdateFaviconURL( | 130 void AppActivity::DidUpdateFaviconURL( |
56 const std::vector<content::FaviconURL>& candidates) { | 131 const std::vector<content::FaviconURL>& candidates) { |
57 ActivityManager::Get()->UpdateActivity(this); | 132 ActivityManager::Get()->UpdateActivity(this); |
58 } | 133 } |
59 | 134 |
60 } // namespace athena | 135 } // namespace athena |
OLD | NEW |