| 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/ui/extensions/shell_window.h" | 5 #include "chrome/browser/ui/extensions/shell_window.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/extensions/extension_process_manager.h" | 9 #include "chrome/browser/extensions/extension_process_manager.h" |
| 10 #include "chrome/browser/extensions/extension_system.h" | 10 #include "chrome/browser/extensions/extension_system.h" |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 | 242 |
| 243 ShellWindow::~ShellWindow() { | 243 ShellWindow::~ShellWindow() { |
| 244 // Unregister now to prevent getting NOTIFICATION_APP_TERMINATING if we're the | 244 // Unregister now to prevent getting NOTIFICATION_APP_TERMINATING if we're the |
| 245 // last window open. | 245 // last window open. |
| 246 registrar_.RemoveAll(); | 246 registrar_.RemoveAll(); |
| 247 | 247 |
| 248 // Remove shutdown prevention. | 248 // Remove shutdown prevention. |
| 249 chrome::EndKeepAlive(); | 249 chrome::EndKeepAlive(); |
| 250 } | 250 } |
| 251 | 251 |
| 252 void ShellWindow::Close() { |
| 253 extensions::ShellWindowRegistry::Get(profile_)->RemoveShellWindow(this); |
| 254 native_app_window_->Close(); |
| 255 } |
| 256 |
| 252 void ShellWindow::RequestMediaAccessPermission( | 257 void ShellWindow::RequestMediaAccessPermission( |
| 253 content::WebContents* web_contents, | 258 content::WebContents* web_contents, |
| 254 const content::MediaStreamRequest& request, | 259 const content::MediaStreamRequest& request, |
| 255 const content::MediaResponseCallback& callback) { | 260 const content::MediaResponseCallback& callback) { |
| 256 // Get the preferred default devices for the request. | 261 // Get the preferred default devices for the request. |
| 257 content::MediaStreamDevices devices; | 262 content::MediaStreamDevices devices; |
| 258 MediaCaptureDevicesDispatcher::GetInstance()->GetDefaultDevicesForProfile( | 263 MediaCaptureDevicesDispatcher::GetInstance()->GetDefaultDevicesForProfile( |
| 259 profile_, | 264 profile_, |
| 260 content::IsAudioMediaType(request.audio_type), | 265 content::IsAudioMediaType(request.audio_type), |
| 261 content::IsVideoMediaType(request.video_type), | 266 content::IsVideoMediaType(request.video_type), |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 bool last_unlocked_by_target) { | 346 bool last_unlocked_by_target) { |
| 342 bool has_permission = IsExtensionWithPermissionOrSuggestInConsole( | 347 bool has_permission = IsExtensionWithPermissionOrSuggestInConsole( |
| 343 APIPermission::kPointerLock, | 348 APIPermission::kPointerLock, |
| 344 extension_, | 349 extension_, |
| 345 web_contents->GetRenderViewHost()); | 350 web_contents->GetRenderViewHost()); |
| 346 | 351 |
| 347 web_contents->GotResponseToLockMouseRequest(has_permission); | 352 web_contents->GotResponseToLockMouseRequest(has_permission); |
| 348 } | 353 } |
| 349 | 354 |
| 350 void ShellWindow::OnNativeClose() { | 355 void ShellWindow::OnNativeClose() { |
| 356 // This method is shared between the path for the user clicking the close |
| 357 // button and the path where a close is triggered by code (e.g. by the |
| 358 // extension being unloaded). In the latter case, this RemoveShellWindow is |
| 359 // superfluous, since it will already have been removed, but the call is |
| 360 // idempotent so it's harmless the second time. |
| 351 extensions::ShellWindowRegistry::Get(profile_)->RemoveShellWindow(this); | 361 extensions::ShellWindowRegistry::Get(profile_)->RemoveShellWindow(this); |
| 352 content::RenderViewHost* rvh = web_contents_->GetRenderViewHost(); | 362 if (extension_) { |
| 353 rvh->Send(new ExtensionMsg_AppWindowClosed(rvh->GetRoutingID())); | 363 content::RenderViewHost* rvh = web_contents_->GetRenderViewHost(); |
| 364 rvh->Send(new ExtensionMsg_AppWindowClosed(rvh->GetRoutingID())); |
| 365 } |
| 354 delete this; | 366 delete this; |
| 355 } | 367 } |
| 356 | 368 |
| 357 void ShellWindow::OnNativeWindowChanged() { | 369 void ShellWindow::OnNativeWindowChanged() { |
| 358 SaveWindowPosition(); | 370 SaveWindowPosition(); |
| 359 if (!native_app_window_ || !web_contents_) | 371 if (!native_app_window_ || !web_contents_) |
| 360 return; | 372 return; |
| 361 ListValue args; | 373 ListValue args; |
| 362 DictionaryValue* dictionary = new DictionaryValue(); | 374 DictionaryValue* dictionary = new DictionaryValue(); |
| 363 args.Append(dictionary); | 375 args.Append(dictionary); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 extension(), | 497 extension(), |
| 486 extension()->GetIconResource(kPreferredIconSize, | 498 extension()->GetIconResource(kPreferredIconSize, |
| 487 ExtensionIconSet::MATCH_BIGGER), | 499 ExtensionIconSet::MATCH_BIGGER), |
| 488 gfx::Size(kPreferredIconSize, kPreferredIconSize), | 500 gfx::Size(kPreferredIconSize, kPreferredIconSize), |
| 489 base::Bind(&ShellWindow::OnImageLoaded, | 501 base::Bind(&ShellWindow::OnImageLoaded, |
| 490 image_loader_ptr_factory_.GetWeakPtr())); | 502 image_loader_ptr_factory_.GetWeakPtr())); |
| 491 } | 503 } |
| 492 | 504 |
| 493 void ShellWindow::CloseContents(WebContents* contents) { | 505 void ShellWindow::CloseContents(WebContents* contents) { |
| 494 DCHECK(contents == web_contents_); | 506 DCHECK(contents == web_contents_); |
| 495 native_app_window_->Close(); | 507 Close(); |
| 496 } | 508 } |
| 497 | 509 |
| 498 bool ShellWindow::ShouldSuppressDialogs() { | 510 bool ShellWindow::ShouldSuppressDialogs() { |
| 499 return true; | 511 return true; |
| 500 } | 512 } |
| 501 | 513 |
| 502 void ShellWindow::WebIntentDispatch( | 514 void ShellWindow::WebIntentDispatch( |
| 503 content::WebContents* web_contents, | 515 content::WebContents* web_contents, |
| 504 content::WebIntentsDispatcher* intents_dispatcher) { | 516 content::WebIntentsDispatcher* intents_dispatcher) { |
| 505 #if defined(ENABLE_WEB_INTENTS) | 517 #if defined(ENABLE_WEB_INTENTS) |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 // TODO(jianli): once http://crbug.com/123007 is fixed, we'll no longer | 578 // TODO(jianli): once http://crbug.com/123007 is fixed, we'll no longer |
| 567 // need to make the native window (ShellWindowViews specially) update | 579 // need to make the native window (ShellWindowViews specially) update |
| 568 // the clickthrough region for the new RVH. | 580 // the clickthrough region for the new RVH. |
| 569 native_app_window_->RenderViewHostChanged(); | 581 native_app_window_->RenderViewHostChanged(); |
| 570 break; | 582 break; |
| 571 } | 583 } |
| 572 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { | 584 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
| 573 const extensions::Extension* unloaded_extension = | 585 const extensions::Extension* unloaded_extension = |
| 574 content::Details<extensions::UnloadedExtensionInfo>( | 586 content::Details<extensions::UnloadedExtensionInfo>( |
| 575 details)->extension; | 587 details)->extension; |
| 576 if (extension_ == unloaded_extension) | 588 if (extension_ == unloaded_extension) { |
| 577 native_app_window_->Close(); | 589 Close(); |
| 590 // After this notification finishes processing, the Extension will be |
| 591 // deleted, so we null out our reference to avoid bad access. |
| 592 extension_ = NULL; |
| 593 } |
| 578 break; | 594 break; |
| 579 } | 595 } |
| 580 case chrome::NOTIFICATION_APP_TERMINATING: | 596 case chrome::NOTIFICATION_APP_TERMINATING: |
| 581 native_app_window_->Close(); | 597 Close(); |
| 582 break; | 598 break; |
| 583 default: | 599 default: |
| 584 NOTREACHED() << "Received unexpected notification"; | 600 NOTREACHED() << "Received unexpected notification"; |
| 585 } | 601 } |
| 586 } | 602 } |
| 587 | 603 |
| 588 extensions::WindowController* | 604 extensions::WindowController* |
| 589 ShellWindow::GetExtensionWindowController() const { | 605 ShellWindow::GetExtensionWindowController() const { |
| 590 return NULL; | 606 return NULL; |
| 591 } | 607 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 const extensions::DraggableRegion& region = *iter; | 652 const extensions::DraggableRegion& region = *iter; |
| 637 sk_region->op( | 653 sk_region->op( |
| 638 region.bounds.x(), | 654 region.bounds.x(), |
| 639 region.bounds.y(), | 655 region.bounds.y(), |
| 640 region.bounds.right(), | 656 region.bounds.right(), |
| 641 region.bounds.bottom(), | 657 region.bounds.bottom(), |
| 642 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); | 658 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); |
| 643 } | 659 } |
| 644 return sk_region; | 660 return sk_region; |
| 645 } | 661 } |
| OLD | NEW |