OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "apps/shell_window.h" | 5 #include "apps/shell_window.h" |
6 | 6 |
7 #include "apps/shell_window_geometry_cache.h" | 7 #include "apps/shell_window_geometry_cache.h" |
8 #include "apps/shell_window_registry.h" | 8 #include "apps/shell_window_registry.h" |
9 #include "apps/ui/native_app_window.h" | 9 #include "apps/ui/native_app_window.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
15 #include "chrome/browser/extensions/extension_web_contents_observer.h" | 15 #include "chrome/browser/extensions/extension_web_contents_observer.h" |
16 #include "chrome/browser/extensions/suggest_permission_util.h" | 16 #include "chrome/browser/extensions/suggest_permission_util.h" |
17 #include "chrome/browser/lifetime/application_lifetime.h" | 17 #include "chrome/browser/lifetime/application_lifetime.h" |
| 18 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/common/extensions/extension_messages.h" | 20 #include "chrome/common/extensions/extension_messages.h" |
20 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" | 21 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" |
21 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 22 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
22 #include "content/public/browser/browser_context.h" | |
23 #include "content/public/browser/invalidate_type.h" | 23 #include "content/public/browser/invalidate_type.h" |
24 #include "content/public/browser/navigation_entry.h" | 24 #include "content/public/browser/navigation_entry.h" |
25 #include "content/public/browser/notification_details.h" | 25 #include "content/public/browser/notification_details.h" |
26 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
27 #include "content/public/browser/notification_source.h" | 27 #include "content/public/browser/notification_source.h" |
28 #include "content/public/browser/notification_types.h" | 28 #include "content/public/browser/notification_types.h" |
29 #include "content/public/browser/render_view_host.h" | 29 #include "content/public/browser/render_view_host.h" |
30 #include "content/public/browser/resource_dispatcher_host.h" | 30 #include "content/public/browser/resource_dispatcher_host.h" |
31 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
32 #include "content/public/browser/web_contents_view.h" | 32 #include "content/public/browser/web_contents_view.h" |
33 #include "content/public/common/media_stream_request.h" | 33 #include "content/public/common/media_stream_request.h" |
34 #include "extensions/browser/extension_system.h" | 34 #include "extensions/browser/extension_system.h" |
35 #include "extensions/browser/extensions_browser_client.h" | |
36 #include "extensions/browser/process_manager.h" | 35 #include "extensions/browser/process_manager.h" |
37 #include "extensions/browser/view_type_utils.h" | 36 #include "extensions/browser/view_type_utils.h" |
38 #include "extensions/common/extension.h" | 37 #include "extensions/common/extension.h" |
39 #include "third_party/skia/include/core/SkRegion.h" | 38 #include "third_party/skia/include/core/SkRegion.h" |
40 #include "ui/gfx/screen.h" | 39 #include "ui/gfx/screen.h" |
41 | 40 |
42 #if !defined(OS_MACOSX) | 41 #if !defined(OS_MACOSX) |
43 #include "apps/pref_names.h" | 42 #include "apps/pref_names.h" |
44 #include "base/prefs/pref_service.h" | 43 #include "base/prefs/pref_service.h" |
45 #endif | 44 #endif |
46 | 45 |
47 using content::BrowserContext; | |
48 using content::ConsoleMessageLevel; | 46 using content::ConsoleMessageLevel; |
49 using content::WebContents; | 47 using content::WebContents; |
50 using extensions::APIPermission; | 48 using extensions::APIPermission; |
51 using web_modal::WebContentsModalDialogHost; | 49 using web_modal::WebContentsModalDialogHost; |
52 using web_modal::WebContentsModalDialogManager; | 50 using web_modal::WebContentsModalDialogManager; |
53 | 51 |
54 namespace { | 52 namespace { |
55 | 53 |
56 const int kDefaultWidth = 512; | 54 const int kDefaultWidth = 512; |
57 const int kDefaultHeight = 384; | 55 const int kDefaultHeight = 384; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 state(ui::SHOW_STATE_DEFAULT), | 130 state(ui::SHOW_STATE_DEFAULT), |
133 hidden(false), | 131 hidden(false), |
134 resizable(true), | 132 resizable(true), |
135 focused(true), | 133 focused(true), |
136 always_on_top(false) {} | 134 always_on_top(false) {} |
137 | 135 |
138 ShellWindow::CreateParams::~CreateParams() {} | 136 ShellWindow::CreateParams::~CreateParams() {} |
139 | 137 |
140 ShellWindow::Delegate::~Delegate() {} | 138 ShellWindow::Delegate::~Delegate() {} |
141 | 139 |
142 ShellWindow::ShellWindow(BrowserContext* context, | 140 ShellWindow::ShellWindow(Profile* profile, |
143 Delegate* delegate, | 141 Delegate* delegate, |
144 const extensions::Extension* extension) | 142 const extensions::Extension* extension) |
145 : browser_context_(context), | 143 : profile_(profile), |
146 extension_(extension), | 144 extension_(extension), |
147 extension_id_(extension->id()), | 145 extension_id_(extension->id()), |
148 window_type_(WINDOW_TYPE_DEFAULT), | 146 window_type_(WINDOW_TYPE_DEFAULT), |
149 delegate_(delegate), | 147 delegate_(delegate), |
150 image_loader_ptr_factory_(this), | 148 image_loader_ptr_factory_(this), |
151 fullscreen_types_(FULLSCREEN_TYPE_NONE), | 149 fullscreen_types_(FULLSCREEN_TYPE_NONE), |
152 show_on_first_paint_(false), | 150 show_on_first_paint_(false), |
153 first_paint_complete_(false), | 151 first_paint_complete_(false), |
154 cached_always_on_top_(false) { | 152 cached_always_on_top_(false) { |
155 extensions::ExtensionsBrowserClient* client = | 153 CHECK(!profile->IsGuestSession() || profile->IsOffTheRecord()) |
156 extensions::ExtensionsBrowserClient::Get(); | |
157 CHECK(!client->IsGuestSession(context) || context->IsOffTheRecord()) | |
158 << "Only off the record window may be opened in the guest mode."; | 154 << "Only off the record window may be opened in the guest mode."; |
159 } | 155 } |
160 | 156 |
161 void ShellWindow::Init(const GURL& url, | 157 void ShellWindow::Init(const GURL& url, |
162 ShellWindowContents* shell_window_contents, | 158 ShellWindowContents* shell_window_contents, |
163 const CreateParams& params) { | 159 const CreateParams& params) { |
164 // Initialize the render interface and web contents | 160 // Initialize the render interface and web contents |
165 shell_window_contents_.reset(shell_window_contents); | 161 shell_window_contents_.reset(shell_window_contents); |
166 shell_window_contents_->Initialize(browser_context(), url); | 162 shell_window_contents_->Initialize(profile(), url); |
167 WebContents* web_contents = shell_window_contents_->GetWebContents(); | 163 WebContents* web_contents = shell_window_contents_->GetWebContents(); |
168 if (CommandLine::ForCurrentProcess()->HasSwitch( | 164 if (CommandLine::ForCurrentProcess()->HasSwitch( |
169 switches::kEnableAppsShowOnFirstPaint)) { | 165 switches::kEnableAppsShowOnFirstPaint)) { |
170 content::WebContentsObserver::Observe(web_contents); | 166 content::WebContentsObserver::Observe(web_contents); |
171 } | 167 } |
172 delegate_->InitWebContents(web_contents); | 168 delegate_->InitWebContents(web_contents); |
173 WebContentsModalDialogManager::CreateForWebContents(web_contents); | 169 WebContentsModalDialogManager::CreateForWebContents(web_contents); |
174 extensions::ExtensionWebContentsObserver::CreateForWebContents(web_contents); | 170 extensions::ExtensionWebContentsObserver::CreateForWebContents(web_contents); |
175 | 171 |
176 web_contents->SetDelegate(this); | 172 web_contents->SetDelegate(this); |
(...skipping 27 matching lines...) Expand all Loading... |
204 Maximize(); | 200 Maximize(); |
205 else if (new_params.state == ui::SHOW_STATE_MINIMIZED) | 201 else if (new_params.state == ui::SHOW_STATE_MINIMIZED) |
206 Minimize(); | 202 Minimize(); |
207 | 203 |
208 OnNativeWindowChanged(); | 204 OnNativeWindowChanged(); |
209 | 205 |
210 // When the render view host is changed, the native window needs to know | 206 // When the render view host is changed, the native window needs to know |
211 // about it in case it has any setup to do to make the renderer appear | 207 // about it in case it has any setup to do to make the renderer appear |
212 // properly. In particular, on Windows, the view's clickthrough region needs | 208 // properly. In particular, on Windows, the view's clickthrough region needs |
213 // to be set. | 209 // to be set. |
214 extensions::ExtensionsBrowserClient* client = | 210 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
215 extensions::ExtensionsBrowserClient::Get(); | 211 content::Source<Profile>(profile_->GetOriginalProfile())); |
216 registrar_.Add(this, | |
217 chrome::NOTIFICATION_EXTENSION_UNLOADED, | |
218 content::Source<content::BrowserContext>( | |
219 client->GetOriginalContext(browser_context_))); | |
220 // Close when the browser process is exiting. | 212 // Close when the browser process is exiting. |
221 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, | 213 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, |
222 content::NotificationService::AllSources()); | 214 content::NotificationService::AllSources()); |
223 | 215 |
224 shell_window_contents_->LoadContents(new_params.creator_process_id); | 216 shell_window_contents_->LoadContents(new_params.creator_process_id); |
225 | 217 |
226 if (CommandLine::ForCurrentProcess()->HasSwitch( | 218 if (CommandLine::ForCurrentProcess()->HasSwitch( |
227 switches::kEnableAppsShowOnFirstPaint)) { | 219 switches::kEnableAppsShowOnFirstPaint)) { |
228 // We want to show the window only when the content has been painted. For | 220 // We want to show the window only when the content has been painted. For |
229 // that to happen, we need to define a size for the content, otherwise the | 221 // that to happen, we need to define a size for the content, otherwise the |
230 // layout will happen in a 0x0 area. | 222 // layout will happen in a 0x0 area. |
231 // Note: WebContents::GetView() is guaranteed to be non-null. | 223 // Note: WebContents::GetView() is guaranteed to be non-null. |
232 web_contents->GetView()->SizeContents(new_params.bounds.size()); | 224 web_contents->GetView()->SizeContents(new_params.bounds.size()); |
233 } | 225 } |
234 | 226 |
235 // Prevent the browser process from shutting down while this window is open. | 227 // Prevent the browser process from shutting down while this window is open. |
236 chrome::StartKeepAlive(); | 228 chrome::StartKeepAlive(); |
237 | 229 |
238 UpdateExtensionAppIcon(); | 230 UpdateExtensionAppIcon(); |
239 | 231 |
240 ShellWindowRegistry::Get(browser_context_)->AddShellWindow(this); | 232 ShellWindowRegistry::Get(profile_)->AddShellWindow(this); |
241 } | 233 } |
242 | 234 |
243 ShellWindow::~ShellWindow() { | 235 ShellWindow::~ShellWindow() { |
244 // Unregister now to prevent getting NOTIFICATION_APP_TERMINATING if we're the | 236 // Unregister now to prevent getting NOTIFICATION_APP_TERMINATING if we're the |
245 // last window open. | 237 // last window open. |
246 registrar_.RemoveAll(); | 238 registrar_.RemoveAll(); |
247 | 239 |
248 // Remove shutdown prevention. | 240 // Remove shutdown prevention. |
249 chrome::EndKeepAlive(); | 241 chrome::EndKeepAlive(); |
250 } | 242 } |
(...skipping 22 matching lines...) Expand all Loading... |
273 params.url.spec().c_str())); | 265 params.url.spec().c_str())); |
274 return NULL; | 266 return NULL; |
275 } | 267 } |
276 | 268 |
277 // These dispositions aren't really navigations. | 269 // These dispositions aren't really navigations. |
278 if (disposition == SUPPRESS_OPEN || disposition == SAVE_TO_DISK || | 270 if (disposition == SUPPRESS_OPEN || disposition == SAVE_TO_DISK || |
279 disposition == IGNORE_ACTION) { | 271 disposition == IGNORE_ACTION) { |
280 return NULL; | 272 return NULL; |
281 } | 273 } |
282 | 274 |
283 WebContents* contents = | 275 WebContents* contents = delegate_->OpenURLFromTab(profile_, source, |
284 delegate_->OpenURLFromTab(browser_context_, source, params); | 276 params); |
285 if (!contents) { | 277 if (!contents) { |
286 AddMessageToDevToolsConsole( | 278 AddMessageToDevToolsConsole( |
287 content::CONSOLE_MESSAGE_LEVEL_ERROR, | 279 content::CONSOLE_MESSAGE_LEVEL_ERROR, |
288 base::StringPrintf( | 280 base::StringPrintf( |
289 "Can't navigate to \"%s\"; apps do not support navigation.", | 281 "Can't navigate to \"%s\"; apps do not support navigation.", |
290 params.url.spec().c_str())); | 282 params.url.spec().c_str())); |
291 } | 283 } |
292 | 284 |
293 return contents; | 285 return contents; |
294 } | 286 } |
295 | 287 |
296 void ShellWindow::AddNewContents(WebContents* source, | 288 void ShellWindow::AddNewContents(WebContents* source, |
297 WebContents* new_contents, | 289 WebContents* new_contents, |
298 WindowOpenDisposition disposition, | 290 WindowOpenDisposition disposition, |
299 const gfx::Rect& initial_pos, | 291 const gfx::Rect& initial_pos, |
300 bool user_gesture, | 292 bool user_gesture, |
301 bool* was_blocked) { | 293 bool* was_blocked) { |
302 DCHECK(new_contents->GetBrowserContext() == browser_context_); | 294 DCHECK(Profile::FromBrowserContext(new_contents->GetBrowserContext()) == |
303 delegate_->AddNewContents(browser_context_, | 295 profile_); |
304 new_contents, | 296 delegate_->AddNewContents(profile_, new_contents, disposition, |
305 disposition, | 297 initial_pos, user_gesture, was_blocked); |
306 initial_pos, | |
307 user_gesture, | |
308 was_blocked); | |
309 } | 298 } |
310 | 299 |
311 bool ShellWindow::PreHandleKeyboardEvent( | 300 bool ShellWindow::PreHandleKeyboardEvent( |
312 content::WebContents* source, | 301 content::WebContents* source, |
313 const content::NativeWebKeyboardEvent& event, | 302 const content::NativeWebKeyboardEvent& event, |
314 bool* is_keyboard_shortcut) { | 303 bool* is_keyboard_shortcut) { |
315 // Here, we can handle a key event before the content gets it. When we are | 304 // Here, we can handle a key event before the content gets it. When we are |
316 // fullscreen and it is not forced, we want to allow the user to leave | 305 // fullscreen and it is not forced, we want to allow the user to leave |
317 // when ESC is pressed. | 306 // when ESC is pressed. |
318 // However, if the application has the "overrideEscFullscreen" permission, we | 307 // However, if the application has the "overrideEscFullscreen" permission, we |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 void ShellWindow::DidFirstVisuallyNonEmptyPaint(int32 page_id) { | 359 void ShellWindow::DidFirstVisuallyNonEmptyPaint(int32 page_id) { |
371 first_paint_complete_ = true; | 360 first_paint_complete_ = true; |
372 if (show_on_first_paint_) { | 361 if (show_on_first_paint_) { |
373 DCHECK(delayed_show_type_ == SHOW_ACTIVE || | 362 DCHECK(delayed_show_type_ == SHOW_ACTIVE || |
374 delayed_show_type_ == SHOW_INACTIVE); | 363 delayed_show_type_ == SHOW_INACTIVE); |
375 Show(delayed_show_type_); | 364 Show(delayed_show_type_); |
376 } | 365 } |
377 } | 366 } |
378 | 367 |
379 void ShellWindow::OnNativeClose() { | 368 void ShellWindow::OnNativeClose() { |
380 ShellWindowRegistry::Get(browser_context_)->RemoveShellWindow(this); | 369 ShellWindowRegistry::Get(profile_)->RemoveShellWindow(this); |
381 if (shell_window_contents_) { | 370 if (shell_window_contents_) { |
382 WebContents* web_contents = shell_window_contents_->GetWebContents(); | 371 WebContents* web_contents = shell_window_contents_->GetWebContents(); |
383 WebContentsModalDialogManager::FromWebContents(web_contents)-> | 372 WebContentsModalDialogManager::FromWebContents(web_contents)-> |
384 SetDelegate(NULL); | 373 SetDelegate(NULL); |
385 shell_window_contents_->NativeWindowClosed(); | 374 shell_window_contents_->NativeWindowClosed(); |
386 } | 375 } |
387 delete this; | 376 delete this; |
388 } | 377 } |
389 | 378 |
390 void ShellWindow::OnNativeWindowChanged() { | 379 void ShellWindow::OnNativeWindowChanged() { |
391 SaveWindowPosition(); | 380 SaveWindowPosition(); |
392 | 381 |
393 #if defined(OS_WIN) | 382 #if defined(OS_WIN) |
394 if (native_app_window_ && | 383 if (native_app_window_ && |
395 cached_always_on_top_ && | 384 cached_always_on_top_ && |
396 !IsFullscreen(fullscreen_types_) && | 385 !IsFullscreen(fullscreen_types_) && |
397 !native_app_window_->IsMaximized() && | 386 !native_app_window_->IsMaximized() && |
398 !native_app_window_->IsMinimized()) { | 387 !native_app_window_->IsMinimized()) { |
399 UpdateNativeAlwaysOnTop(); | 388 UpdateNativeAlwaysOnTop(); |
400 } | 389 } |
401 #endif | 390 #endif |
402 | 391 |
403 if (shell_window_contents_ && native_app_window_) | 392 if (shell_window_contents_ && native_app_window_) |
404 shell_window_contents_->NativeWindowChanged(native_app_window_.get()); | 393 shell_window_contents_->NativeWindowChanged(native_app_window_.get()); |
405 } | 394 } |
406 | 395 |
407 void ShellWindow::OnNativeWindowActivated() { | 396 void ShellWindow::OnNativeWindowActivated() { |
408 ShellWindowRegistry::Get(browser_context_)->ShellWindowActivated(this); | 397 ShellWindowRegistry::Get(profile_)->ShellWindowActivated(this); |
409 } | 398 } |
410 | 399 |
411 content::WebContents* ShellWindow::web_contents() const { | 400 content::WebContents* ShellWindow::web_contents() const { |
412 return shell_window_contents_->GetWebContents(); | 401 return shell_window_contents_->GetWebContents(); |
413 } | 402 } |
414 | 403 |
415 NativeAppWindow* ShellWindow::GetBaseWindow() { | 404 NativeAppWindow* ShellWindow::GetBaseWindow() { |
416 return native_app_window_.get(); | 405 return native_app_window_.get(); |
417 } | 406 } |
418 | 407 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 void ShellWindow::UpdateDraggableRegions( | 481 void ShellWindow::UpdateDraggableRegions( |
493 const std::vector<extensions::DraggableRegion>& regions) { | 482 const std::vector<extensions::DraggableRegion>& regions) { |
494 native_app_window_->UpdateDraggableRegions(regions); | 483 native_app_window_->UpdateDraggableRegions(regions); |
495 } | 484 } |
496 | 485 |
497 void ShellWindow::UpdateAppIcon(const gfx::Image& image) { | 486 void ShellWindow::UpdateAppIcon(const gfx::Image& image) { |
498 if (image.IsEmpty()) | 487 if (image.IsEmpty()) |
499 return; | 488 return; |
500 app_icon_ = image; | 489 app_icon_ = image; |
501 native_app_window_->UpdateWindowIcon(); | 490 native_app_window_->UpdateWindowIcon(); |
502 ShellWindowRegistry::Get(browser_context_)->ShellWindowIconChanged(this); | 491 ShellWindowRegistry::Get(profile_)->ShellWindowIconChanged(this); |
503 } | 492 } |
504 | 493 |
505 void ShellWindow::Fullscreen() { | 494 void ShellWindow::Fullscreen() { |
506 #if !defined(OS_MACOSX) | 495 #if !defined(OS_MACOSX) |
507 // Do not enter fullscreen mode if disallowed by pref. | 496 // Do not enter fullscreen mode if disallowed by pref. |
508 PrefService* prefs = | 497 if (!profile()->GetPrefs()->GetBoolean(prefs::kAppFullscreenAllowed)) |
509 extensions::ExtensionsBrowserClient::Get()->GetPrefServiceForContext( | |
510 browser_context()); | |
511 if (!prefs->GetBoolean(prefs::kAppFullscreenAllowed)) | |
512 return; | 498 return; |
513 #endif | 499 #endif |
514 fullscreen_types_ |= FULLSCREEN_TYPE_WINDOW_API; | 500 fullscreen_types_ |= FULLSCREEN_TYPE_WINDOW_API; |
515 SetNativeWindowFullscreen(); | 501 SetNativeWindowFullscreen(); |
516 } | 502 } |
517 | 503 |
518 void ShellWindow::Maximize() { | 504 void ShellWindow::Maximize() { |
519 GetBaseWindow()->Maximize(); | 505 GetBaseWindow()->Maximize(); |
520 } | 506 } |
521 | 507 |
522 void ShellWindow::Minimize() { | 508 void ShellWindow::Minimize() { |
523 GetBaseWindow()->Minimize(); | 509 GetBaseWindow()->Minimize(); |
524 } | 510 } |
525 | 511 |
526 void ShellWindow::Restore() { | 512 void ShellWindow::Restore() { |
527 if (IsFullscreen(fullscreen_types_)) { | 513 if (IsFullscreen(fullscreen_types_)) { |
528 fullscreen_types_ = FULLSCREEN_TYPE_NONE; | 514 fullscreen_types_ = FULLSCREEN_TYPE_NONE; |
529 SetNativeWindowFullscreen(); | 515 SetNativeWindowFullscreen(); |
530 } else { | 516 } else { |
531 GetBaseWindow()->Restore(); | 517 GetBaseWindow()->Restore(); |
532 } | 518 } |
533 } | 519 } |
534 | 520 |
535 void ShellWindow::OSFullscreen() { | 521 void ShellWindow::OSFullscreen() { |
536 #if !defined(OS_MACOSX) | 522 #if !defined(OS_MACOSX) |
537 // Do not enter fullscreen mode if disallowed by pref. | 523 // Do not enter fullscreen mode if disallowed by pref. |
538 PrefService* prefs = | 524 if (!profile()->GetPrefs()->GetBoolean(prefs::kAppFullscreenAllowed)) |
539 extensions::ExtensionsBrowserClient::Get()->GetPrefServiceForContext( | |
540 browser_context()); | |
541 if (!prefs->GetBoolean(prefs::kAppFullscreenAllowed)) | |
542 return; | 525 return; |
543 #endif | 526 #endif |
544 fullscreen_types_ |= FULLSCREEN_TYPE_OS; | 527 fullscreen_types_ |= FULLSCREEN_TYPE_OS; |
545 SetNativeWindowFullscreen(); | 528 SetNativeWindowFullscreen(); |
546 } | 529 } |
547 | 530 |
548 void ShellWindow::ForcedFullscreen() { | 531 void ShellWindow::ForcedFullscreen() { |
549 fullscreen_types_ |= FULLSCREEN_TYPE_FORCED; | 532 fullscreen_types_ |= FULLSCREEN_TYPE_FORCED; |
550 SetNativeWindowFullscreen(); | 533 SetNativeWindowFullscreen(); |
551 } | 534 } |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 void ShellWindow::OnExtensionIconImageChanged(extensions::IconImage* image) { | 660 void ShellWindow::OnExtensionIconImageChanged(extensions::IconImage* image) { |
678 DCHECK_EQ(app_icon_image_.get(), image); | 661 DCHECK_EQ(app_icon_image_.get(), image); |
679 | 662 |
680 UpdateAppIcon(gfx::Image(app_icon_image_->image_skia())); | 663 UpdateAppIcon(gfx::Image(app_icon_image_->image_skia())); |
681 } | 664 } |
682 | 665 |
683 void ShellWindow::UpdateExtensionAppIcon() { | 666 void ShellWindow::UpdateExtensionAppIcon() { |
684 // Avoid using any previous app icons were being downloaded. | 667 // Avoid using any previous app icons were being downloaded. |
685 image_loader_ptr_factory_.InvalidateWeakPtrs(); | 668 image_loader_ptr_factory_.InvalidateWeakPtrs(); |
686 | 669 |
687 app_icon_image_.reset( | 670 app_icon_image_.reset(new extensions::IconImage( |
688 new extensions::IconImage(browser_context(), | 671 profile(), |
689 extension(), | 672 extension(), |
690 extensions::IconsInfo::GetIcons(extension()), | 673 extensions::IconsInfo::GetIcons(extension()), |
691 delegate_->PreferredIconSize(), | 674 delegate_->PreferredIconSize(), |
692 extensions::IconsInfo::GetDefaultAppIcon(), | 675 extensions::IconsInfo::GetDefaultAppIcon(), |
693 this)); | 676 this)); |
694 | 677 |
695 // Triggers actual image loading with 1x resources. The 2x resource will | 678 // Triggers actual image loading with 1x resources. The 2x resource will |
696 // be handled by IconImage class when requested. | 679 // be handled by IconImage class when requested. |
697 app_icon_image_->image_skia().GetRepresentation(1.0f); | 680 app_icon_image_->image_skia().GetRepresentation(1.0f); |
698 } | 681 } |
699 | 682 |
700 void ShellWindow::OnSizeConstraintsChanged() { | 683 void ShellWindow::OnSizeConstraintsChanged() { |
701 native_app_window_->UpdateWindowMinMaxSize(); | 684 native_app_window_->UpdateWindowMinMaxSize(); |
702 gfx::Rect bounds = GetClientBounds(); | 685 gfx::Rect bounds = GetClientBounds(); |
703 gfx::Size constrained_size = size_constraints_.ClampSize(bounds.size()); | 686 gfx::Size constrained_size = size_constraints_.ClampSize(bounds.size()); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 else if (changed_flags & content::INVALIDATE_TYPE_TAB) | 779 else if (changed_flags & content::INVALIDATE_TYPE_TAB) |
797 native_app_window_->UpdateWindowIcon(); | 780 native_app_window_->UpdateWindowIcon(); |
798 } | 781 } |
799 | 782 |
800 void ShellWindow::ToggleFullscreenModeForTab(content::WebContents* source, | 783 void ShellWindow::ToggleFullscreenModeForTab(content::WebContents* source, |
801 bool enter_fullscreen) { | 784 bool enter_fullscreen) { |
802 #if !defined(OS_MACOSX) | 785 #if !defined(OS_MACOSX) |
803 // Do not enter fullscreen mode if disallowed by pref. | 786 // Do not enter fullscreen mode if disallowed by pref. |
804 // TODO(bartfab): Add a test once it becomes possible to simulate a user | 787 // TODO(bartfab): Add a test once it becomes possible to simulate a user |
805 // gesture. http://crbug.com/174178 | 788 // gesture. http://crbug.com/174178 |
806 PrefService* prefs = | 789 if (enter_fullscreen && |
807 extensions::ExtensionsBrowserClient::Get()->GetPrefServiceForContext( | 790 !profile()->GetPrefs()->GetBoolean(prefs::kAppFullscreenAllowed)) { |
808 browser_context()); | |
809 if (enter_fullscreen && !prefs->GetBoolean(prefs::kAppFullscreenAllowed)) { | |
810 return; | 791 return; |
811 } | 792 } |
812 #endif | 793 #endif |
813 | 794 |
814 if (!IsExtensionWithPermissionOrSuggestInConsole( | 795 if (!IsExtensionWithPermissionOrSuggestInConsole( |
815 APIPermission::kFullscreen, | 796 APIPermission::kFullscreen, |
816 extension_, | 797 extension_, |
817 source->GetRenderViewHost())) { | 798 source->GetRenderViewHost())) { |
818 return; | 799 return; |
819 } | 800 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 rvh->Send(new ExtensionMsg_AddMessageToConsole( | 856 rvh->Send(new ExtensionMsg_AddMessageToConsole( |
876 rvh->GetRoutingID(), level, message)); | 857 rvh->GetRoutingID(), level, message)); |
877 } | 858 } |
878 | 859 |
879 void ShellWindow::SaveWindowPosition() { | 860 void ShellWindow::SaveWindowPosition() { |
880 if (window_key_.empty()) | 861 if (window_key_.empty()) |
881 return; | 862 return; |
882 if (!native_app_window_) | 863 if (!native_app_window_) |
883 return; | 864 return; |
884 | 865 |
885 ShellWindowGeometryCache* cache = | 866 ShellWindowGeometryCache* cache = ShellWindowGeometryCache::Get(profile()); |
886 ShellWindowGeometryCache::Get(browser_context()); | |
887 | 867 |
888 gfx::Rect bounds = native_app_window_->GetRestoredBounds(); | 868 gfx::Rect bounds = native_app_window_->GetRestoredBounds(); |
889 bounds.Inset(native_app_window_->GetFrameInsets()); | 869 bounds.Inset(native_app_window_->GetFrameInsets()); |
890 gfx::Rect screen_bounds = | 870 gfx::Rect screen_bounds = |
891 gfx::Screen::GetNativeScreen()->GetDisplayMatching(bounds).work_area(); | 871 gfx::Screen::GetNativeScreen()->GetDisplayMatching(bounds).work_area(); |
892 ui::WindowShowState window_state = native_app_window_->GetRestoredState(); | 872 ui::WindowShowState window_state = native_app_window_->GetRestoredState(); |
893 cache->SaveGeometry(extension()->id(), | 873 cache->SaveGeometry(extension()->id(), |
894 window_key_, | 874 window_key_, |
895 bounds, | 875 bounds, |
896 screen_bounds, | 876 screen_bounds, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
932 if (params.bounds.width() == 0) | 912 if (params.bounds.width() == 0) |
933 params.bounds.set_width(kDefaultWidth); | 913 params.bounds.set_width(kDefaultWidth); |
934 if (params.bounds.height() == 0) | 914 if (params.bounds.height() == 0) |
935 params.bounds.set_height(kDefaultHeight); | 915 params.bounds.set_height(kDefaultHeight); |
936 | 916 |
937 // If left and top are left undefined, the native shell window will center | 917 // If left and top are left undefined, the native shell window will center |
938 // the window on the main screen in a platform-defined manner. | 918 // the window on the main screen in a platform-defined manner. |
939 | 919 |
940 // Load cached state if it exists. | 920 // Load cached state if it exists. |
941 if (!params.window_key.empty()) { | 921 if (!params.window_key.empty()) { |
942 ShellWindowGeometryCache* cache = | 922 ShellWindowGeometryCache* cache = ShellWindowGeometryCache::Get(profile()); |
943 ShellWindowGeometryCache::Get(browser_context()); | |
944 | 923 |
945 gfx::Rect cached_bounds; | 924 gfx::Rect cached_bounds; |
946 gfx::Rect cached_screen_bounds; | 925 gfx::Rect cached_screen_bounds; |
947 ui::WindowShowState cached_state = ui::SHOW_STATE_DEFAULT; | 926 ui::WindowShowState cached_state = ui::SHOW_STATE_DEFAULT; |
948 if (cache->GetGeometry(extension()->id(), params.window_key, | 927 if (cache->GetGeometry(extension()->id(), params.window_key, |
949 &cached_bounds, &cached_screen_bounds, | 928 &cached_bounds, &cached_screen_bounds, |
950 &cached_state)) { | 929 &cached_state)) { |
951 // App window has cached screen bounds, make sure it fits on screen in | 930 // App window has cached screen bounds, make sure it fits on screen in |
952 // case the screen resolution changed. | 931 // case the screen resolution changed. |
953 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); | 932 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); |
(...skipping 28 matching lines...) Expand all Loading... |
982 region.bounds.x(), | 961 region.bounds.x(), |
983 region.bounds.y(), | 962 region.bounds.y(), |
984 region.bounds.right(), | 963 region.bounds.right(), |
985 region.bounds.bottom(), | 964 region.bounds.bottom(), |
986 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); | 965 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); |
987 } | 966 } |
988 return sk_region; | 967 return sk_region; |
989 } | 968 } |
990 | 969 |
991 } // namespace apps | 970 } // namespace apps |
OLD | NEW |