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 "athena/activity/public/activity_manager.h" | 7 #include "athena/activity/public/activity_manager.h" |
8 #include "athena/content/app_activity_registry.h" | |
9 #include "athena/content/public/app_content_delegate.h" | |
10 #include "athena/content/public/app_registry.h" | |
8 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
9 #include "extensions/shell/browser/shell_app_window.h" | 12 #include "extensions/shell/browser/shell_app_window.h" |
10 #include "ui/views/controls/webview/webview.h" | 13 #include "ui/views/controls/webview/webview.h" |
14 #include "ui/views/widget/widget.h" | |
11 | 15 |
12 namespace athena { | 16 namespace athena { |
13 | 17 |
14 // TODO(mukai): specifies the same accelerators of WebActivity. | 18 // TODO(mukai): specifies the same accelerators of WebActivity. |
15 AppActivity::AppActivity(extensions::ShellAppWindow* app_window) | 19 AppActivity::AppActivity(extensions::ShellAppWindow* app_window) |
16 : app_window_(app_window), | 20 : app_window_(app_window), |
17 web_view_(NULL), | 21 web_view_(NULL), |
18 current_state_(ACTIVITY_UNLOADED) { | 22 current_state_(ACTIVITY_UNLOADED), |
19 DCHECK(app_window_); | 23 app_activity_registry_(NULL) { |
20 } | 24 } |
21 | 25 |
22 AppActivity::~AppActivity() { | 26 AppActivity::~AppActivity() { |
23 if (GetCurrentState() != ACTIVITY_UNLOADED) | 27 // If this activity is registered, we unregister it now. |
24 SetCurrentState(ACTIVITY_UNLOADED); | 28 if (app_activity_registry_) |
29 app_activity_registry_->UnregisterAppActivity(this); | |
25 } | 30 } |
26 | 31 |
27 ActivityViewModel* AppActivity::GetActivityViewModel() { | 32 ActivityViewModel* AppActivity::GetActivityViewModel() { |
28 return this; | 33 return this; |
29 } | 34 } |
30 | 35 |
31 void AppActivity::SetCurrentState(Activity::ActivityState state) { | 36 void AppActivity::SetCurrentState(Activity::ActivityState state) { |
37 ActivityState current_state = state; | |
38 // Remember the last requested state now so that a call to GetCurrentState() | |
39 // returns the new state. | |
40 current_state_ = state; | |
41 | |
32 switch (state) { | 42 switch (state) { |
33 case ACTIVITY_VISIBLE: | 43 case ACTIVITY_VISIBLE: |
34 // Fall through (for the moment). | 44 // Fall through (for the moment). |
35 case ACTIVITY_INVISIBLE: | 45 case ACTIVITY_INVISIBLE: |
36 // By clearing the overview mode image we allow the content to be shown. | 46 // By clearing the overview mode image we allow the content to be shown. |
37 overview_mode_image_ = gfx::ImageSkia(); | 47 overview_mode_image_ = gfx::ImageSkia(); |
38 // TODO(skuhne): Find out how to reload an app from the extension system. | 48 // Note: A reload from the unloaded state will be performed through the |
49 // |AppActivityProxy| object and no further action isn't necessary here. | |
39 break; | 50 break; |
40 case ACTIVITY_BACKGROUND_LOW_PRIORITY: | 51 case ACTIVITY_BACKGROUND_LOW_PRIORITY: |
41 DCHECK(ACTIVITY_VISIBLE == current_state_ || | 52 DCHECK(ACTIVITY_VISIBLE == current_state || |
42 ACTIVITY_INVISIBLE == current_state_); | 53 ACTIVITY_INVISIBLE == current_state); |
43 // TODO(skuhne): Do this. | 54 // TODO(skuhne): Do this. |
44 break; | 55 break; |
45 case ACTIVITY_PERSISTENT: | 56 case ACTIVITY_PERSISTENT: |
46 DCHECK_EQ(ACTIVITY_BACKGROUND_LOW_PRIORITY, current_state_); | 57 DCHECK_EQ(ACTIVITY_BACKGROUND_LOW_PRIORITY, current_state); |
47 // TODO(skuhne): Do this. | 58 // TODO(skuhne): Do this. |
48 break; | 59 break; |
49 case ACTIVITY_UNLOADED: | 60 case ACTIVITY_UNLOADED: |
50 DCHECK_NE(ACTIVITY_UNLOADED, current_state_); | 61 DCHECK_NE(ACTIVITY_UNLOADED, current_state); |
51 // TODO(skuhne): Find out how to evict an app from the extension system. | 62 // This will cause the application to shut down, close its windows and |
52 // web_view_->EvictContent(); | 63 // delete this object. Instead a |AppActivityProxy| will be created as |
64 // place holder. | |
65 if (app_activity_registry_) | |
66 app_activity_registry_->Unload(); | |
oshima
2014/08/15 15:15:59
Design question rather than code question:
I gues
Mr4D (OOO till 08-26)
2014/08/18 16:09:32
Actually... I implemented it the way that each act
| |
53 break; | 67 break; |
54 } | 68 } |
55 // Remember the last requested state. | |
56 current_state_ = state; | |
57 } | 69 } |
58 | 70 |
59 Activity::ActivityState AppActivity::GetCurrentState() { | 71 Activity::ActivityState AppActivity::GetCurrentState() { |
60 // TODO(skuhne): Check here also eviction status. | |
61 if (!web_view_) { | 72 if (!web_view_) { |
62 DCHECK_EQ(ACTIVITY_UNLOADED, current_state_); | 73 DCHECK_EQ(ACTIVITY_UNLOADED, current_state_); |
63 return ACTIVITY_UNLOADED; | 74 return ACTIVITY_UNLOADED; |
64 } | 75 } |
65 // TODO(skuhne): This should be controlled by an observer and should not | 76 // TODO(skuhne): This should be controlled by an observer and should not |
66 // reside here. | 77 // reside here. |
67 if (IsVisible() && current_state_ != ACTIVITY_VISIBLE) | 78 if (IsVisible() && current_state_ != ACTIVITY_VISIBLE) |
68 SetCurrentState(ACTIVITY_VISIBLE); | 79 SetCurrentState(ACTIVITY_VISIBLE); |
69 // Note: If the activity is not visible it does not necessarily mean that it | 80 // Note: If the activity is not visible it does not necessarily mean that it |
70 // does not have GPU compositor resources (yet). | 81 // does not have GPU compositor resources (yet). |
71 return current_state_; | 82 return current_state_; |
72 } | 83 } |
73 | 84 |
74 bool AppActivity::IsVisible() { | 85 bool AppActivity::IsVisible() { |
75 return web_view_ && web_view_->IsDrawn(); | 86 return web_view_ && web_view_->IsDrawn(); |
76 } | 87 } |
77 | 88 |
78 Activity::ActivityMediaState AppActivity::GetMediaState() { | 89 Activity::ActivityMediaState AppActivity::GetMediaState() { |
79 // TODO(skuhne): The function GetTabMediaStateForContents(WebContents), | 90 // TODO(skuhne): The function GetTabMediaStateForContents(WebContents), |
80 // and the AudioStreamMonitor needs to be moved from Chrome into contents to | 91 // 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. | 92 // make it more modular and so that we can use it from here. |
82 return Activity::ACTIVITY_MEDIA_STATE_NONE; | 93 return Activity::ACTIVITY_MEDIA_STATE_NONE; |
83 } | 94 } |
84 | 95 |
96 aura::Window* AppActivity::GetWindow() { | |
97 if (!web_view_) | |
oshima
2014/08/15 15:15:59
nit:
? :
Mr4D (OOO till 08-26)
2014/08/18 16:09:32
Done.
| |
98 return NULL; | |
99 return web_view_->GetWidget()->GetNativeWindow(); | |
100 } | |
101 | |
85 void AppActivity::Init() { | 102 void AppActivity::Init() { |
86 } | 103 } |
87 | 104 |
88 SkColor AppActivity::GetRepresentativeColor() const { | 105 SkColor AppActivity::GetRepresentativeColor() const { |
89 // TODO(sad): Compute the color from the favicon. | 106 // TODO(sad): Compute the color from the favicon. |
90 return SK_ColorGRAY; | 107 return SK_ColorGRAY; |
91 } | 108 } |
92 | 109 |
93 base::string16 AppActivity::GetTitle() const { | 110 base::string16 AppActivity::GetTitle() const { |
94 return web_view_->GetWebContents()->GetTitle(); | 111 return web_view_->GetWebContents()->GetTitle(); |
(...skipping 28 matching lines...) Expand all Loading... | |
123 void AppActivity::TitleWasSet(content::NavigationEntry* entry, | 140 void AppActivity::TitleWasSet(content::NavigationEntry* entry, |
124 bool explicit_set) { | 141 bool explicit_set) { |
125 ActivityManager::Get()->UpdateActivity(this); | 142 ActivityManager::Get()->UpdateActivity(this); |
126 } | 143 } |
127 | 144 |
128 void AppActivity::DidUpdateFaviconURL( | 145 void AppActivity::DidUpdateFaviconURL( |
129 const std::vector<content::FaviconURL>& candidates) { | 146 const std::vector<content::FaviconURL>& candidates) { |
130 ActivityManager::Get()->UpdateActivity(this); | 147 ActivityManager::Get()->UpdateActivity(this); |
131 } | 148 } |
132 | 149 |
150 void AppActivity::DidStartNavigationToPendingEntry( | |
151 const GURL& url, | |
152 content::NavigationController::ReloadType reload_type) { | |
153 if (!app_activity_registry_) | |
oshima
2014/08/15 15:15:59
can this be NULL in this callback?
Mr4D (OOO till 08-26)
2014/08/18 16:09:32
Yes upon first call the app_id is unknown since Ge
| |
154 RegisterActivity(); | |
155 } | |
156 | |
157 // Register an |activity| with an application. | |
158 // Note: This should only get called once for an |app_window| of the | |
159 // |activity|. | |
160 void AppActivity::RegisterActivity() { | |
161 if (app_activity_registry_) | |
162 return; | |
163 content::WebContents* web_contents = app_window_->GetAssociatedWebContents(); | |
164 AppRegistry* app_registry = AppRegistry::Get(); | |
165 // Get the application's registry. | |
166 app_activity_registry_ = app_registry->GetAppActivityRegistry( | |
167 app_registry->GetDelegate()->GetExtensionID(web_contents), | |
168 web_contents->GetBrowserContext()); | |
169 DCHECK(app_activity_registry_); | |
170 // Register the activity. | |
171 app_activity_registry_->RegisterAppActivity(this); | |
172 } | |
173 | |
133 } // namespace athena | 174 } // namespace athena |
OLD | NEW |