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 WebActivity::SetCurrentState(ActivityStateTranstion 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 ActivityState WebActivity::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_ACTIVE; |
| 80 */ |
| 81 return ACTIVITY_STATE_HIDDEN; |
| 82 case ACTIVITY_DEEP_SLEEP_1: |
| 83 return ACTIVITY_DEEP_SLEEP_1; |
| 84 case ACTIVITY_DEEP_SLEEP_2: |
| 85 return ACTIVITY_DEEP_SLEEP_2; |
| 86 case ACTIVITY_UNLOAD: |
| 87 return ACTIVITY_STATE_UNLOADED; |
| 88 } |
| 89 } |
| 90 |
27 void AppActivity::Init() { | 91 void AppActivity::Init() { |
28 } | 92 } |
29 | 93 |
30 SkColor AppActivity::GetRepresentativeColor() { | 94 SkColor AppActivity::GetRepresentativeColor() { |
31 // TODO(sad): Compute the color from the favicon. | 95 // TODO(sad): Compute the color from the favicon. |
32 return SK_ColorGRAY; | 96 return SK_ColorGRAY; |
33 } | 97 } |
34 | 98 |
35 base::string16 AppActivity::GetTitle() { | 99 base::string16 AppActivity::GetTitle() { |
36 return web_view_->GetWebContents()->GetTitle(); | 100 return web_view_->GetWebContents()->GetTitle(); |
37 } | 101 } |
38 | 102 |
39 views::View* AppActivity::GetContentsView() { | 103 views::View* AppActivity::GetContentsView() { |
40 if (!web_view_) { | 104 if (!web_view_) { |
41 content::WebContents* web_contents = | 105 content::WebContents* web_contents = |
42 app_window_->GetAssociatedWebContents(); | 106 app_window_->GetAssociatedWebContents(); |
43 web_view_ = new views::WebView(web_contents->GetBrowserContext()); | 107 web_view_ = new views::WebView(web_contents->GetBrowserContext()); |
44 web_view_->SetWebContents(web_contents); | 108 web_view_->SetWebContents(web_contents); |
| 109 SetCurrentState(ACTIVITY_LOAD); |
45 Observe(web_contents); | 110 Observe(web_contents); |
| 111 overview_mode_image_ = gfx::ImageSkia(); |
46 } | 112 } |
47 return web_view_; | 113 return web_view_; |
48 } | 114 } |
49 | 115 |
50 void AppActivity::TitleWasSet(content::NavigationEntry* entry, | 116 void AppActivity::TitleWasSet(content::NavigationEntry* entry, |
51 bool explicit_set) { | 117 bool explicit_set) { |
52 ActivityManager::Get()->UpdateActivity(this); | 118 ActivityManager::Get()->UpdateActivity(this); |
53 } | 119 } |
54 | 120 |
55 void AppActivity::DidUpdateFaviconURL( | 121 void AppActivity::DidUpdateFaviconURL( |
56 const std::vector<content::FaviconURL>& candidates) { | 122 const std::vector<content::FaviconURL>& candidates) { |
57 ActivityManager::Get()->UpdateActivity(this); | 123 ActivityManager::Get()->UpdateActivity(this); |
58 } | 124 } |
59 | 125 |
| 126 void AppActivity::CreateOverviewModeImage() { |
| 127 // TODO(skuhne): Implement this! |
| 128 } |
| 129 |
| 130 const gfx::ImageSkia AppActivity::GetOverviewModeImage() { |
| 131 return overview_mode_image_; |
| 132 } |
| 133 |
60 } // namespace athena | 134 } // namespace athena |
OLD | NEW |