blob: 48f9b6c0c1fe5011b81114dc67275daafca4a378 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "athena/content/app_activity.h"
#include "athena/activity/public/activity_manager.h"
#include "athena/content/app_activity_registry.h"
#include "athena/content/public/app_registry.h"
#include "content/public/browser/web_contents.h"
#include "ui/views/controls/webview/webview.h"
#include "ui/views/widget/widget.h"
namespace athena {
// TODO(mukai): specifies the same accelerators of WebActivity.
AppActivity::AppActivity(const std::string& app_id)
: app_id_(app_id),
web_view_(NULL),
current_state_(ACTIVITY_UNLOADED),
app_activity_registry_(NULL) {
}
AppActivity::~AppActivity() {
// If this activity is registered, we unregister it now.
if (app_activity_registry_)
app_activity_registry_->UnregisterAppActivity(this);
}
ActivityViewModel* AppActivity::GetActivityViewModel() {
return this;
}
void AppActivity::SetCurrentState(Activity::ActivityState state) {
ActivityState current_state = state;
// Remember the last requested state now so that a call to GetCurrentState()
// returns the new state.
current_state_ = state;
switch (state) {
case ACTIVITY_VISIBLE:
// Fall through (for the moment).
case ACTIVITY_INVISIBLE:
// By clearing the overview mode image we allow the content to be shown.
overview_mode_image_ = gfx::ImageSkia();
// Note: A reload from the unloaded state will be performed through the
// |AppActivityProxy| object and no further action isn't necessary here.
break;
case ACTIVITY_BACKGROUND_LOW_PRIORITY:
DCHECK(ACTIVITY_VISIBLE == current_state ||
ACTIVITY_INVISIBLE == current_state);
// TODO(skuhne): Do this.
break;
case ACTIVITY_PERSISTENT:
DCHECK_EQ(ACTIVITY_BACKGROUND_LOW_PRIORITY, current_state);
// TODO(skuhne): Do this.
break;
case ACTIVITY_UNLOADED:
DCHECK_NE(ACTIVITY_UNLOADED, current_state);
// This will cause the application to shut down, close its windows and
// delete this object. Instead a |AppActivityProxy| will be created as
// place holder.
if (app_activity_registry_)
app_activity_registry_->Unload();
break;
}
}
Activity::ActivityState AppActivity::GetCurrentState() {
if (!web_view_) {
DCHECK_EQ(ACTIVITY_UNLOADED, current_state_);
return ACTIVITY_UNLOADED;
}
// TODO(skuhne): This should be controlled by an observer and should not
// reside here.
if (IsVisible() && current_state_ != ACTIVITY_VISIBLE)
SetCurrentState(ACTIVITY_VISIBLE);
// Note: If the activity is not visible it does not necessarily mean that it
// does not have GPU compositor resources (yet).
return current_state_;
}
bool AppActivity::IsVisible() {
return web_view_ && web_view_->IsDrawn();
}
Activity::ActivityMediaState AppActivity::GetMediaState() {
// TODO(skuhne): The function GetTabMediaStateForContents(WebContents),
// and the AudioStreamMonitor needs to be moved from Chrome into contents to
// make it more modular and so that we can use it from here.
return Activity::ACTIVITY_MEDIA_STATE_NONE;
}
aura::Window* AppActivity::GetWindow() {
return !web_view_ ? NULL : web_view_->GetWidget()->GetNativeWindow();
}
void AppActivity::Init() {
}
SkColor AppActivity::GetRepresentativeColor() const {
// TODO(sad): Compute the color from the favicon.
return SK_ColorGRAY;
}
base::string16 AppActivity::GetTitle() const {
return web_view_->GetWebContents()->GetTitle();
}
bool AppActivity::UsesFrame() const {
return false;
}
views::View* AppActivity::GetContentsView() {
if (!web_view_) {
// TODO(oshima): use apps::NativeAppWindowViews
content::WebContents* web_contents = GetWebContents();
web_view_ = new views::WebView(web_contents->GetBrowserContext());
web_view_->SetWebContents(web_contents);
SetCurrentState(ACTIVITY_INVISIBLE);
Observe(web_contents);
overview_mode_image_ = gfx::ImageSkia();
RegisterActivity();
}
return web_view_;
}
void AppActivity::CreateOverviewModeImage() {
// TODO(skuhne): Implement this!
}
gfx::ImageSkia AppActivity::GetOverviewModeImage() {
return overview_mode_image_;
}
void AppActivity::TitleWasSet(content::NavigationEntry* entry,
bool explicit_set) {
ActivityManager::Get()->UpdateActivity(this);
}
void AppActivity::DidUpdateFaviconURL(
const std::vector<content::FaviconURL>& candidates) {
ActivityManager::Get()->UpdateActivity(this);
}
// Register an |activity| with an application.
// Note: This should only get called once for an |app_window| of the
// |activity|.
void AppActivity::RegisterActivity() {
content::WebContents* web_contents = GetWebContents();
AppRegistry* app_registry = AppRegistry::Get();
// Get the application's registry.
app_activity_registry_ = app_registry->GetAppActivityRegistry(
app_id_, web_contents->GetBrowserContext());
DCHECK(app_activity_registry_);
// Register the activity.
app_activity_registry_->RegisterAppActivity(this);
}
} // namespace athena
|