OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/extensions/api/app_window/app_window_api.h" | 5 #include "chrome/browser/extensions/api/app_window/app_window_api.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/time.h" | 8 #include "base/time.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/app_mode/app_mode_utils.h" | 10 #include "chrome/browser/app_mode/app_mode_utils.h" |
11 #include "chrome/browser/devtools/devtools_window.h" | 11 #include "chrome/browser/devtools/devtools_window.h" |
12 #include "chrome/browser/extensions/shell_window_registry.h" | 12 #include "chrome/browser/extensions/shell_window_registry.h" |
13 #include "chrome/browser/extensions/window_controller.h" | 13 #include "chrome/browser/extensions/window_controller.h" |
14 #include "chrome/browser/ui/extensions/native_app_window.h" | 14 #include "chrome/browser/ui/extensions/native_app_window.h" |
15 #include "chrome/browser/ui/extensions/shell_window.h" | 15 #include "chrome/browser/ui/extensions/shell_window.h" |
16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/common/extensions/api/app_window.h" | 17 #include "chrome/common/extensions/api/app_window.h" |
18 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
19 #include "content/public/browser/notification_types.h" | 19 #include "content/public/browser/notification_types.h" |
20 #include "content/public/browser/render_process_host.h" | 20 #include "content/public/browser/render_process_host.h" |
21 #include "content/public/browser/render_view_host.h" | 21 #include "content/public/browser/render_view_host.h" |
22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
23 #include "content/public/common/url_constants.h" | 23 #include "content/public/common/url_constants.h" |
24 #include "googleurl/src/gurl.h" | 24 #include "googleurl/src/gurl.h" |
25 #include "ui/base/ui_base_types.h" | |
25 #include "ui/gfx/rect.h" | 26 #include "ui/gfx/rect.h" |
26 | 27 |
27 #if defined(USE_ASH) | 28 #if defined(USE_ASH) |
28 #include "ash/shell.h" | 29 #include "ash/shell.h" |
29 #include "ash/wm/property_util.h" | 30 #include "ash/wm/property_util.h" |
30 #include "ui/aura/root_window.h" | 31 #include "ui/aura/root_window.h" |
31 #include "ui/aura/window.h" | 32 #include "ui/aura/window.h" |
32 #endif | 33 #endif |
33 | 34 |
34 namespace app_window = extensions::api::app_window; | 35 namespace app_window = extensions::api::app_window; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 DCHECK(type == content::NOTIFICATION_LOAD_STOP); | 76 DCHECK(type == content::NOTIFICATION_LOAD_STOP); |
76 delayed_create_function_->SendDelayedResponse(); | 77 delayed_create_function_->SendDelayedResponse(); |
77 delete this; | 78 delete this; |
78 } | 79 } |
79 | 80 |
80 private: | 81 private: |
81 scoped_refptr<AppWindowCreateFunction> delayed_create_function_; | 82 scoped_refptr<AppWindowCreateFunction> delayed_create_function_; |
82 content::NotificationRegistrar registrar_; | 83 content::NotificationRegistrar registrar_; |
83 }; | 84 }; |
84 | 85 |
86 void SetCreateResultFromShellWindow(ShellWindow* window, | |
87 base::DictionaryValue* result) { | |
88 result->SetBoolean("fullscreen", window->GetBaseWindow()->IsFullscreen()); | |
89 result->SetBoolean("minimized", window->GetBaseWindow()->IsMinimized()); | |
90 result->SetBoolean("maximized", window->GetBaseWindow()->IsMaximized()); | |
91 DictionaryValue* boundsValue = new DictionaryValue(); | |
92 gfx::Rect bounds = window->GetClientBounds(); | |
93 boundsValue->SetInteger("left", bounds.x()); | |
94 boundsValue->SetInteger("top", bounds.y()); | |
95 boundsValue->SetInteger("width", bounds.width()); | |
96 boundsValue->SetInteger("height", bounds.height()); | |
97 result->Set("bounds", boundsValue); | |
98 } | |
99 | |
85 } // namespace | 100 } // namespace |
86 | 101 |
87 void AppWindowCreateFunction::SendDelayedResponse() { | 102 void AppWindowCreateFunction::SendDelayedResponse() { |
88 SendResponse(true); | 103 SendResponse(true); |
89 } | 104 } |
90 | 105 |
91 bool AppWindowCreateFunction::RunImpl() { | 106 bool AppWindowCreateFunction::RunImpl() { |
92 scoped_ptr<Create::Params> params(Create::Params::Create(*args_)); | 107 scoped_ptr<Create::Params> params(Create::Params::Create(*args_)); |
93 EXTENSION_FUNCTION_VALIDATE(params.get()); | 108 EXTENSION_FUNCTION_VALIDATE(params.get()); |
94 | 109 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 window->web_contents()->GetRenderViewHost(); | 148 window->web_contents()->GetRenderViewHost(); |
134 int view_id = MSG_ROUTING_NONE; | 149 int view_id = MSG_ROUTING_NONE; |
135 if (render_view_host_->GetProcess()->GetID() == | 150 if (render_view_host_->GetProcess()->GetID() == |
136 created_view->GetProcess()->GetID()) { | 151 created_view->GetProcess()->GetID()) { |
137 view_id = created_view->GetRoutingID(); | 152 view_id = created_view->GetRoutingID(); |
138 } | 153 } |
139 | 154 |
140 window->GetBaseWindow()->Show(); | 155 window->GetBaseWindow()->Show(); |
141 base::DictionaryValue* result = new base::DictionaryValue; | 156 base::DictionaryValue* result = new base::DictionaryValue; |
142 result->Set("viewId", base::Value::CreateIntegerValue(view_id)); | 157 result->Set("viewId", base::Value::CreateIntegerValue(view_id)); |
158 SetCreateResultFromShellWindow(window, result); | |
benwells
2013/05/03 08:52:03
Why is this now being done here?
(Wow this is a l
stevenjb
2013/05/03 17:41:14
This code path occurs if we call app.window.create
| |
143 result->SetBoolean("existingWindow", true); | 159 result->SetBoolean("existingWindow", true); |
144 result->SetBoolean("injectTitlebar", false); | 160 result->SetBoolean("injectTitlebar", false); |
145 SetResult(result); | 161 SetResult(result); |
146 SendResponse(true); | 162 SendResponse(true); |
147 return true; | 163 return true; |
148 } | 164 } |
149 } | 165 } |
150 } | 166 } |
151 | 167 |
152 // TODO(jeremya): remove these, since they do the same thing as | 168 // TODO(jeremya): remove these, since they do the same thing as |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 | 239 |
224 if (options->resizable.get()) | 240 if (options->resizable.get()) |
225 create_params.resizable = *options->resizable.get(); | 241 create_params.resizable = *options->resizable.get(); |
226 | 242 |
227 if (options->type != extensions::api::app_window::WINDOW_TYPE_PANEL) { | 243 if (options->type != extensions::api::app_window::WINDOW_TYPE_PANEL) { |
228 switch (options->state) { | 244 switch (options->state) { |
229 case extensions::api::app_window::STATE_NONE: | 245 case extensions::api::app_window::STATE_NONE: |
230 case extensions::api::app_window::STATE_NORMAL: | 246 case extensions::api::app_window::STATE_NORMAL: |
231 break; | 247 break; |
232 case extensions::api::app_window::STATE_FULLSCREEN: | 248 case extensions::api::app_window::STATE_FULLSCREEN: |
233 create_params.state = ShellWindow::CreateParams::STATE_FULLSCREEN; | 249 create_params.state = ui::SHOW_STATE_FULLSCREEN; |
234 break; | 250 break; |
235 case extensions::api::app_window::STATE_MAXIMIZED: | 251 case extensions::api::app_window::STATE_MAXIMIZED: |
236 create_params.state = ShellWindow::CreateParams::STATE_MAXIMIZED; | 252 create_params.state = ui::SHOW_STATE_MAXIMIZED; |
237 break; | 253 break; |
238 case extensions::api::app_window::STATE_MINIMIZED: | 254 case extensions::api::app_window::STATE_MINIMIZED: |
239 create_params.state = ShellWindow::CreateParams::STATE_MINIMIZED; | 255 create_params.state = ui::SHOW_STATE_MINIMIZED; |
240 break; | 256 break; |
241 } | 257 } |
242 } else { | 258 } else { |
243 force_maximize = false; | 259 force_maximize = false; |
244 } | 260 } |
245 } | 261 } |
246 | 262 |
247 create_params.creator_process_id = | 263 create_params.creator_process_id = |
248 render_view_host_->GetProcess()->GetID(); | 264 render_view_host_->GetProcess()->GetID(); |
249 | 265 |
250 // Rather then maximizing the window after it was created, we maximize it | 266 // Rather then maximizing the window after it was created, we maximize it |
251 // immediately - that way the initial presentation is much smoother (no odd | 267 // immediately - that way the initial presentation is much smoother (no odd |
252 // rectangles are shown temporarily in the added space). Note that suppressing | 268 // rectangles are shown temporarily in the added space). Note that suppressing |
253 // animations does not help to remove the shown artifacts. | 269 // animations does not help to remove the shown artifacts. |
254 #if USE_ASH | 270 #if USE_ASH |
255 if (force_maximize && !create_params.maximum_size.IsEmpty()) { | 271 if (force_maximize && !create_params.maximum_size.IsEmpty()) { |
256 // Check that the application is able to fill the monitor - if not don't | 272 // Check that the application is able to fill the monitor - if not don't |
257 // maximize. | 273 // maximize. |
258 // TODO(skuhne): In case of multi monitor usage we should find out in | 274 // TODO(skuhne): In case of multi monitor usage we should find out in |
259 // advance on which monitor the window will be displayed (or be happy with | 275 // advance on which monitor the window will be displayed (or be happy with |
260 // a temporary bad frame upon creation). | 276 // a temporary bad frame upon creation). |
261 gfx::Size size = ash::Shell::GetPrimaryRootWindow()->bounds().size(); | 277 gfx::Size size = ash::Shell::GetPrimaryRootWindow()->bounds().size(); |
262 if (size.width() > create_params.maximum_size.width() || | 278 if (size.width() > create_params.maximum_size.width() || |
263 size.height() > create_params.maximum_size.height()) | 279 size.height() > create_params.maximum_size.height()) |
264 force_maximize = false; | 280 force_maximize = false; |
265 } | 281 } |
266 #endif | 282 #endif |
267 | 283 |
268 if (force_maximize) | 284 if (force_maximize) |
269 create_params.state = ShellWindow::CreateParams::STATE_MAXIMIZED; | 285 create_params.state = ui::SHOW_STATE_MINIMIZED; |
benwells
2013/05/03 08:52:03
Why is this changing? Seems counter intuitive. May
stevenjb
2013/05/03 17:41:14
typo. Thanks for catching.
| |
270 | 286 |
271 ShellWindow* shell_window = | 287 ShellWindow* shell_window = |
272 ShellWindow::Create(profile(), GetExtension(), url, create_params); | 288 ShellWindow::Create(profile(), GetExtension(), url, create_params); |
273 | 289 |
274 if (chrome::ShouldForceFullscreenApp()) | 290 if (chrome::ShouldForceFullscreenApp()) |
275 shell_window->Fullscreen(); | 291 shell_window->Fullscreen(); |
276 | 292 |
277 content::RenderViewHost* created_view = | 293 content::RenderViewHost* created_view = |
278 shell_window->web_contents()->GetRenderViewHost(); | 294 shell_window->web_contents()->GetRenderViewHost(); |
279 int view_id = MSG_ROUTING_NONE; | 295 int view_id = MSG_ROUTING_NONE; |
280 if (create_params.creator_process_id == created_view->GetProcess()->GetID()) | 296 if (create_params.creator_process_id == created_view->GetProcess()->GetID()) |
281 view_id = created_view->GetRoutingID(); | 297 view_id = created_view->GetRoutingID(); |
282 | 298 |
283 base::DictionaryValue* result = new base::DictionaryValue; | 299 base::DictionaryValue* result = new base::DictionaryValue; |
284 result->Set("viewId", base::Value::CreateIntegerValue(view_id)); | 300 result->Set("viewId", base::Value::CreateIntegerValue(view_id)); |
285 result->Set("injectTitlebar", | 301 result->Set("injectTitlebar", |
286 base::Value::CreateBooleanValue(inject_html_titlebar)); | 302 base::Value::CreateBooleanValue(inject_html_titlebar)); |
287 result->Set("id", base::Value::CreateStringValue(shell_window->window_key())); | 303 result->Set("id", base::Value::CreateStringValue(shell_window->window_key())); |
288 DictionaryValue* boundsValue = new DictionaryValue(); | 304 SetCreateResultFromShellWindow(shell_window, result); |
289 gfx::Rect bounds = shell_window->GetClientBounds(); | |
290 boundsValue->SetInteger("left", bounds.x()); | |
291 boundsValue->SetInteger("top", bounds.y()); | |
292 boundsValue->SetInteger("width", bounds.width()); | |
293 boundsValue->SetInteger("height", bounds.height()); | |
294 result->Set("bounds", boundsValue); | |
295 SetResult(result); | 305 SetResult(result); |
296 | 306 |
297 if (ShellWindowRegistry::Get(profile())->HadDevToolsAttached(created_view)) { | 307 if (ShellWindowRegistry::Get(profile())->HadDevToolsAttached(created_view)) { |
298 new DevToolsRestorer(this, created_view); | 308 new DevToolsRestorer(this, created_view); |
299 return true; | 309 return true; |
300 } | 310 } |
301 | 311 |
302 SendResponse(true); | 312 SendResponse(true); |
303 return true; | 313 return true; |
304 } | 314 } |
305 | 315 |
306 } // namespace extensions | 316 } // namespace extensions |
OLD | NEW |