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 "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 bool last_unlocked_by_target) { | 273 bool last_unlocked_by_target) { |
274 bool has_permission = IsExtensionWithPermissionOrSuggestInConsole( | 274 bool has_permission = IsExtensionWithPermissionOrSuggestInConsole( |
275 APIPermission::kPointerLock, | 275 APIPermission::kPointerLock, |
276 extension_, | 276 extension_, |
277 web_contents->GetRenderViewHost()); | 277 web_contents->GetRenderViewHost()); |
278 | 278 |
279 web_contents->GotResponseToLockMouseRequest(has_permission); | 279 web_contents->GotResponseToLockMouseRequest(has_permission); |
280 } | 280 } |
281 | 281 |
282 void ShellWindow::OnNativeClose() { | 282 void ShellWindow::OnNativeClose() { |
283 extensions::ShellWindowRegistry::Get(profile_)->RemoveShellWindow(this); | 283 if (extension_) { |
284 if (shell_window_contents_) | 284 // If |extension_| is NULL here, it is because the extension has been |
285 shell_window_contents_->NativeWindowClosed(); | 285 // unloaded. In this case, the window will have already been removed from |
| 286 // the ShellWindowRegistry, and the app can not be informed of the window |
| 287 // closing as it has gone. |
| 288 extensions::ShellWindowRegistry::Get(profile_)->RemoveShellWindow(this); |
| 289 if (shell_window_contents_) |
| 290 shell_window_contents_->NativeWindowClosed(); |
| 291 } |
286 delete this; | 292 delete this; |
287 } | 293 } |
288 | 294 |
289 void ShellWindow::OnNativeWindowChanged() { | 295 void ShellWindow::OnNativeWindowChanged() { |
290 SaveWindowPosition(); | 296 SaveWindowPosition(); |
291 if (shell_window_contents_ && native_app_window_) | 297 if (shell_window_contents_ && native_app_window_) |
292 shell_window_contents_->NativeWindowChanged(native_app_window_.get()); | 298 shell_window_contents_->NativeWindowChanged(native_app_window_.get()); |
293 } | 299 } |
294 | 300 |
295 void ShellWindow::OnNativeWindowActivated() { | 301 void ShellWindow::OnNativeWindowActivated() { |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 delegate_->PreferredIconSize(), | 446 delegate_->PreferredIconSize(), |
441 extensions::IconsInfo::GetDefaultAppIcon(), | 447 extensions::IconsInfo::GetDefaultAppIcon(), |
442 this)); | 448 this)); |
443 | 449 |
444 // Triggers actual image loading with 1x resources. The 2x resource will | 450 // Triggers actual image loading with 1x resources. The 2x resource will |
445 // be handled by IconImage class when requested. | 451 // be handled by IconImage class when requested. |
446 app_icon_image_->image_skia().GetRepresentation(ui::SCALE_FACTOR_100P); | 452 app_icon_image_->image_skia().GetRepresentation(ui::SCALE_FACTOR_100P); |
447 } | 453 } |
448 | 454 |
449 void ShellWindow::CloseContents(WebContents* contents) { | 455 void ShellWindow::CloseContents(WebContents* contents) { |
450 native_app_window_->Close(); | 456 Close(); |
451 } | 457 } |
452 | 458 |
453 bool ShellWindow::ShouldSuppressDialogs() { | 459 bool ShellWindow::ShouldSuppressDialogs() { |
454 return true; | 460 return true; |
455 } | 461 } |
456 | 462 |
457 content::ColorChooser* ShellWindow::OpenColorChooser(WebContents* web_contents, | 463 content::ColorChooser* ShellWindow::OpenColorChooser(WebContents* web_contents, |
458 SkColor initial_color) { | 464 SkColor initial_color) { |
459 return delegate_->ShowColorChooser(web_contents, initial_color); | 465 return delegate_->ShowColorChooser(web_contents, initial_color); |
460 } | 466 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 // TODO(jianli): once http://crbug.com/123007 is fixed, we'll no longer | 525 // TODO(jianli): once http://crbug.com/123007 is fixed, we'll no longer |
520 // need to make the native window (ShellWindowViews specially) update | 526 // need to make the native window (ShellWindowViews specially) update |
521 // the clickthrough region for the new RVH. | 527 // the clickthrough region for the new RVH. |
522 native_app_window_->RenderViewHostChanged(); | 528 native_app_window_->RenderViewHostChanged(); |
523 break; | 529 break; |
524 } | 530 } |
525 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { | 531 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
526 const extensions::Extension* unloaded_extension = | 532 const extensions::Extension* unloaded_extension = |
527 content::Details<extensions::UnloadedExtensionInfo>( | 533 content::Details<extensions::UnloadedExtensionInfo>( |
528 details)->extension; | 534 details)->extension; |
529 if (extension_ == unloaded_extension) | 535 if (extension_ == unloaded_extension) { |
530 native_app_window_->Close(); | 536 Close(); |
| 537 // After this notification finishes processing, the Extension will be |
| 538 // deleted, so we null out our reference to avoid bad access. |
| 539 extension_ = NULL; |
| 540 } |
531 break; | 541 break; |
532 } | 542 } |
533 case chrome::NOTIFICATION_APP_TERMINATING: | 543 case chrome::NOTIFICATION_APP_TERMINATING: |
534 native_app_window_->Close(); | 544 Close(); |
535 break; | 545 break; |
536 default: | 546 default: |
537 NOTREACHED() << "Received unexpected notification"; | 547 NOTREACHED() << "Received unexpected notification"; |
538 } | 548 } |
539 } | 549 } |
540 | 550 |
541 void ShellWindow::SetWebContentsBlocked(content::WebContents* web_contents, | 551 void ShellWindow::SetWebContentsBlocked(content::WebContents* web_contents, |
542 bool blocked) { | 552 bool blocked) { |
543 delegate_->SetWebContentsBlocked(web_contents, blocked); | 553 delegate_->SetWebContentsBlocked(web_contents, blocked); |
544 } | 554 } |
545 | 555 |
546 bool ShellWindow::IsWebContentsVisible(content::WebContents* web_contents) { | 556 bool ShellWindow::IsWebContentsVisible(content::WebContents* web_contents) { |
547 return delegate_->IsWebContentsVisible(web_contents); | 557 return delegate_->IsWebContentsVisible(web_contents); |
548 } | 558 } |
549 | 559 |
550 extensions::ActiveTabPermissionGranter* | 560 extensions::ActiveTabPermissionGranter* |
551 ShellWindow::GetActiveTabPermissionGranter() { | 561 ShellWindow::GetActiveTabPermissionGranter() { |
552 // Shell windows don't support the activeTab permission. | 562 // Shell windows don't support the activeTab permission. |
553 return NULL; | 563 return NULL; |
554 } | 564 } |
555 | 565 |
556 WebContentsModalDialogHost* ShellWindow::GetWebContentsModalDialogHost() { | 566 WebContentsModalDialogHost* ShellWindow::GetWebContentsModalDialogHost() { |
557 return native_app_window_.get(); | 567 return native_app_window_.get(); |
558 } | 568 } |
559 | 569 |
| 570 void ShellWindow::Close() { |
| 571 extensions::ShellWindowRegistry::Get(profile_)->RemoveShellWindow(this); |
| 572 native_app_window_->Close(); |
| 573 } |
| 574 |
560 void ShellWindow::AddMessageToDevToolsConsole(ConsoleMessageLevel level, | 575 void ShellWindow::AddMessageToDevToolsConsole(ConsoleMessageLevel level, |
561 const std::string& message) { | 576 const std::string& message) { |
562 content::RenderViewHost* rvh = web_contents()->GetRenderViewHost(); | 577 content::RenderViewHost* rvh = web_contents()->GetRenderViewHost(); |
563 rvh->Send(new ExtensionMsg_AddMessageToConsole( | 578 rvh->Send(new ExtensionMsg_AddMessageToConsole( |
564 rvh->GetRoutingID(), level, message)); | 579 rvh->GetRoutingID(), level, message)); |
565 } | 580 } |
566 | 581 |
567 void ShellWindow::SaveWindowPosition() { | 582 void ShellWindow::SaveWindowPosition() { |
568 if (window_key_.empty()) | 583 if (window_key_.empty()) |
569 return; | 584 return; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 region.bounds.x(), | 641 region.bounds.x(), |
627 region.bounds.y(), | 642 region.bounds.y(), |
628 region.bounds.right(), | 643 region.bounds.right(), |
629 region.bounds.bottom(), | 644 region.bounds.bottom(), |
630 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); | 645 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); |
631 } | 646 } |
632 return sk_region; | 647 return sk_region; |
633 } | 648 } |
634 | 649 |
635 } // namespace apps | 650 } // namespace apps |
OLD | NEW |