Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Side by Side Diff: chrome/browser/extensions/api/tabs/app_window_controller.cc

Issue 1099553002: extensions: windows: list all windows from the current profile (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add application windows resize constraint test Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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.
4
5 #include "base/values.h"
6 #include "chrome/browser/extensions/api/tabs/app_window_controller.h"
7 #include "chrome/browser/extensions/api/tabs/tabs_constants.h"
8 #include "chrome/browser/extensions/extension_tab_util.h"
9 #include "chrome/browser/extensions/window_controller.h"
10 #include "chrome/browser/extensions/window_controller_list.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/sessions/session_tab_helper.h"
13 #include "extensions/browser/app_window/app_window.h"
14 #include "extensions/browser/app_window/native_app_window.h"
15 #include "extensions/browser/app_window/size_constraints.h"
16 #include "extensions/common/extension.h"
17 #include "extensions/common/permissions/permissions_data.h"
18
19 namespace extensions {
20
21 AppBaseWindow::AppBaseWindow(AppWindow* app_window) : app_window_(app_window) {
22 }
23
24 AppBaseWindow::~AppBaseWindow() {
25 }
26
27 bool AppBaseWindow::IsActive() const {
28 return GetBaseWindow()->IsActive();
29 }
30
31 bool AppBaseWindow::IsMaximized() const {
32 return GetBaseWindow()->IsMaximized();
33 }
34
35 bool AppBaseWindow::IsMinimized() const {
36 return GetBaseWindow()->IsMinimized();
37 }
38
39 bool AppBaseWindow::IsFullscreen() const {
40 return GetBaseWindow()->IsFullscreen();
41 }
42
43 gfx::NativeWindow AppBaseWindow::GetNativeWindow() const {
44 return GetBaseWindow()->GetNativeWindow();
45 }
46
47 gfx::Rect AppBaseWindow::GetRestoredBounds() const {
48 return GetBaseWindow()->GetRestoredBounds();
49 }
50
51 ui::WindowShowState AppBaseWindow::GetRestoredState() const {
52 return GetBaseWindow()->GetRestoredState();
53 }
54
55 gfx::Rect AppBaseWindow::GetBounds() const {
56 return GetBaseWindow()->GetBounds();
57 }
58
59 void AppBaseWindow::Show() {
60 GetBaseWindow()->Show();
61 }
62
63 void AppBaseWindow::Hide() {
64 GetBaseWindow()->Hide();
65 }
66
67 void AppBaseWindow::ShowInactive() {
68 GetBaseWindow()->ShowInactive();
69 }
70
71 void AppBaseWindow::Close() {
72 GetBaseWindow()->Close();
73 }
74
75 void AppBaseWindow::Activate() {
76 GetBaseWindow()->Activate();
77 }
78
79 void AppBaseWindow::Deactivate() {
80 GetBaseWindow()->Deactivate();
81 }
82
83 void AppBaseWindow::Maximize() {
84 GetBaseWindow()->Maximize();
85 }
86
87 void AppBaseWindow::Minimize() {
88 GetBaseWindow()->Minimize();
89 }
90
91 void AppBaseWindow::Restore() {
92 GetBaseWindow()->Restore();
93 }
94
95 void AppBaseWindow::SetBounds(const gfx::Rect& bounds) {
96 // We constraint the given size to the min/max sizes of the
97 // application window.
98 gfx::Rect original_window_bounds = GetBaseWindow()->GetBounds();
99 gfx::Insets frame_insets = GetBaseWindow()->GetFrameInsets();
100 SizeConstraints constraints(
101 SizeConstraints::AddFrameToConstraints(
102 GetBaseWindow()->GetContentMinimumSize(), frame_insets),
103 SizeConstraints::AddFrameToConstraints(
104 GetBaseWindow()->GetContentMaximumSize(), frame_insets));
105
106 gfx::Rect new_bounds = bounds;
107 new_bounds.set_size(constraints.ClampSize(bounds.size()));
108
109 GetBaseWindow()->SetBounds(new_bounds);
110 }
111
112 void AppBaseWindow::FlashFrame(bool flash) {
113 GetBaseWindow()->FlashFrame(flash);
114 }
115
116 bool AppBaseWindow::IsAlwaysOnTop() const {
117 return GetBaseWindow()->IsAlwaysOnTop();
118 }
119
120 void AppBaseWindow::SetAlwaysOnTop(bool always_on_top) {
121 GetBaseWindow()->SetAlwaysOnTop(always_on_top);
122 }
123
124 NativeAppWindow* AppBaseWindow::GetBaseWindow() const {
125 return app_window_->GetBaseWindow();
126 }
127
128 AppWindowController::AppWindowController(AppWindow* app_window,
129 scoped_ptr<AppBaseWindow> base_window,
130 Profile* profile)
131 : WindowController(base_window.get(), profile),
132 app_window_(app_window),
133 base_window_(base_window.Pass()) {
134 WindowControllerList::GetInstance()->AddExtensionWindow(this);
135 }
136
137 AppWindowController::~AppWindowController() {
138 WindowControllerList::GetInstance()->RemoveExtensionWindow(this);
139 }
140
141 int AppWindowController::GetWindowId() const {
142 return static_cast<int>(app_window_->session_id().id());
143 }
144
145 std::string AppWindowController::GetWindowTypeText() const {
146 if (app_window_->window_type_is_panel())
147 return tabs_constants::kWindowTypeValuePanel;
148 return tabs_constants::kWindowTypeValueApp;
149 }
150
151 base::DictionaryValue* AppWindowController::CreateWindowValueWithTabs(
152 const Extension* extension) const {
153 base::DictionaryValue* result = CreateWindowValue();
154
155 DCHECK(IsVisibleToExtension(extension));
156 base::DictionaryValue* tab_value = CreateTabValue(extension, 0);
157 if (!tab_value)
158 return result;
159
160 base::ListValue* tab_list = new base::ListValue();
161 tab_list->Append(tab_value);
162 result->Set(tabs_constants::kTabsKey, tab_list);
163
164 return result;
165 }
166
167 base::DictionaryValue* AppWindowController::CreateTabValue(
dcheng 2015/06/29 18:15:49 Please use scoped_ptr here and elsewhere.
llandwerlin-old 2015/06/30 10:20:47 These methods are overridden from extension::Windo
168 const Extension* extension,
169 int tab_index) const {
170 if (tab_index > 0)
171 return nullptr;
172
173 content::WebContents* web_contents = app_window_->web_contents();
174 if (!web_contents)
175 return nullptr;
176
177 base::DictionaryValue* tab_value = new base::DictionaryValue();
178 tab_value->SetInteger(tabs_constants::kIdKey,
179 SessionTabHelper::IdForTab(web_contents));
180 tab_value->SetInteger(tabs_constants::kIndexKey, 0);
181 tab_value->SetInteger(
182 tabs_constants::kWindowIdKey,
183 SessionTabHelper::IdForWindowContainingTab(web_contents));
184 tab_value->SetString(tabs_constants::kUrlKey, web_contents->GetURL().spec());
185 tab_value->SetString(
186 tabs_constants::kStatusKey,
187 ExtensionTabUtil::GetTabStatusText(web_contents->IsLoading()));
188 tab_value->SetBoolean(tabs_constants::kActiveKey,
189 app_window_->GetBaseWindow()->IsActive());
190 tab_value->SetBoolean(tabs_constants::kSelectedKey, true);
191 tab_value->SetBoolean(tabs_constants::kHighlightedKey, true);
192 tab_value->SetBoolean(tabs_constants::kPinnedKey, false);
193 tab_value->SetString(tabs_constants::kTitleKey, web_contents->GetTitle());
194 tab_value->SetBoolean(tabs_constants::kIncognitoKey,
195 app_window_->GetBaseWindow()->IsActive());
196
197 gfx::Rect bounds = app_window_->GetBaseWindow()->GetBounds();
198 tab_value->SetInteger(tabs_constants::kWidthKey, bounds.width());
199 tab_value->SetInteger(tabs_constants::kHeightKey, bounds.height());
200
201 std::string icon_str("chrome://favicon/");
202 icon_str.append(app_window_->GetExtension()->url().spec());
203 tab_value->SetString(tabs_constants::kFaviconUrlKey, icon_str);
204
205 return tab_value;
206 }
207
208 bool AppWindowController::CanClose(Reason* reason) const {
209 return true;
210 }
211
212 void AppWindowController::SetFullscreenMode(bool is_fullscreen,
213 const GURL& extension_url) const {
214 // TODO(llandwerlin): should we prevent changes in fullscreen mode
215 // when the fullscreen state is FULLSCREEN_TYPE_FORCED?
216 app_window_->SetFullscreen(AppWindow::FULLSCREEN_TYPE_WINDOW_API,
217 is_fullscreen);
218 }
219
220 Browser* AppWindowController::GetBrowser() const {
221 return nullptr;
222 }
223
224 bool AppWindowController::IsVisibleToExtension(
225 const Extension* extension) const {
226 if (extension->permissions_data()->HasAPIPermission(
227 APIPermission::kWindowsGlobal))
228 return true;
229 return extension->id() == app_window_->extension_id();
230 }
231
232 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698