| 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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 | 237 |
| 238 ShellWindow::~ShellWindow() { | 238 ShellWindow::~ShellWindow() { |
| 239 // Unregister now to prevent getting NOTIFICATION_APP_TERMINATING if we're the | 239 // Unregister now to prevent getting NOTIFICATION_APP_TERMINATING if we're the |
| 240 // last window open. | 240 // last window open. |
| 241 registrar_.RemoveAll(); | 241 registrar_.RemoveAll(); |
| 242 | 242 |
| 243 // Remove shutdown prevention. | 243 // Remove shutdown prevention. |
| 244 chrome::EndKeepAlive(); | 244 chrome::EndKeepAlive(); |
| 245 } | 245 } |
| 246 | 246 |
| 247 void ShellWindow::Close() { | |
| 248 extensions::ShellWindowRegistry::Get(profile_)->RemoveShellWindow(this); | |
| 249 native_app_window_->Close(); | |
| 250 } | |
| 251 | |
| 252 void ShellWindow::RequestMediaAccessPermission( | 247 void ShellWindow::RequestMediaAccessPermission( |
| 253 content::WebContents* web_contents, | 248 content::WebContents* web_contents, |
| 254 const content::MediaStreamRequest& request, | 249 const content::MediaStreamRequest& request, |
| 255 const content::MediaResponseCallback& callback) { | 250 const content::MediaResponseCallback& callback) { |
| 256 // Get the preferred default devices for the request. | 251 // Get the preferred default devices for the request. |
| 257 content::MediaStreamDevices devices; | 252 content::MediaStreamDevices devices; |
| 258 MediaCaptureDevicesDispatcher::GetInstance()->GetDefaultDevicesForProfile( | 253 MediaCaptureDevicesDispatcher::GetInstance()->GetDefaultDevicesForProfile( |
| 259 profile_, | 254 profile_, |
| 260 content::IsAudioMediaType(request.audio_type), | 255 content::IsAudioMediaType(request.audio_type), |
| 261 content::IsVideoMediaType(request.video_type), | 256 content::IsVideoMediaType(request.video_type), |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 bool last_unlocked_by_target) { | 336 bool last_unlocked_by_target) { |
| 342 bool has_permission = IsExtensionWithPermissionOrSuggestInConsole( | 337 bool has_permission = IsExtensionWithPermissionOrSuggestInConsole( |
| 343 APIPermission::kPointerLock, | 338 APIPermission::kPointerLock, |
| 344 extension_, | 339 extension_, |
| 345 web_contents->GetRenderViewHost()); | 340 web_contents->GetRenderViewHost()); |
| 346 | 341 |
| 347 web_contents->GotResponseToLockMouseRequest(has_permission); | 342 web_contents->GotResponseToLockMouseRequest(has_permission); |
| 348 } | 343 } |
| 349 | 344 |
| 350 void ShellWindow::OnNativeClose() { | 345 void ShellWindow::OnNativeClose() { |
| 351 // This method is shared between the path for the user clicking the close | |
| 352 // button and the path where a close is triggered by code (e.g. by the | |
| 353 // extension being unloaded). In the latter case, this RemoveShellWindow is | |
| 354 // superfluous, since it will already have been removed, but the call is | |
| 355 // idempotent so it's harmless the second time. | |
| 356 extensions::ShellWindowRegistry::Get(profile_)->RemoveShellWindow(this); | 346 extensions::ShellWindowRegistry::Get(profile_)->RemoveShellWindow(this); |
| 357 if (extension_) { | 347 content::RenderViewHost* rvh = web_contents_->GetRenderViewHost(); |
| 358 content::RenderViewHost* rvh = web_contents_->GetRenderViewHost(); | 348 rvh->Send(new ExtensionMsg_AppWindowClosed(rvh->GetRoutingID())); |
| 359 rvh->Send(new ExtensionMsg_AppWindowClosed(rvh->GetRoutingID())); | |
| 360 } | |
| 361 delete this; | 349 delete this; |
| 362 } | 350 } |
| 363 | 351 |
| 364 void ShellWindow::OnNativeWindowChanged() { | 352 void ShellWindow::OnNativeWindowChanged() { |
| 365 SaveWindowPosition(); | 353 SaveWindowPosition(); |
| 366 if (!native_app_window_ || !web_contents_) | 354 if (!native_app_window_ || !web_contents_) |
| 367 return; | 355 return; |
| 368 ListValue args; | 356 ListValue args; |
| 369 DictionaryValue* dictionary = new DictionaryValue(); | 357 DictionaryValue* dictionary = new DictionaryValue(); |
| 370 args.Append(dictionary); | 358 args.Append(dictionary); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 extension(), | 480 extension(), |
| 493 extension()->GetIconResource(kPreferredIconSize, | 481 extension()->GetIconResource(kPreferredIconSize, |
| 494 ExtensionIconSet::MATCH_BIGGER), | 482 ExtensionIconSet::MATCH_BIGGER), |
| 495 gfx::Size(kPreferredIconSize, kPreferredIconSize), | 483 gfx::Size(kPreferredIconSize, kPreferredIconSize), |
| 496 base::Bind(&ShellWindow::OnImageLoaded, | 484 base::Bind(&ShellWindow::OnImageLoaded, |
| 497 image_loader_ptr_factory_.GetWeakPtr())); | 485 image_loader_ptr_factory_.GetWeakPtr())); |
| 498 } | 486 } |
| 499 | 487 |
| 500 void ShellWindow::CloseContents(WebContents* contents) { | 488 void ShellWindow::CloseContents(WebContents* contents) { |
| 501 DCHECK(contents == web_contents_); | 489 DCHECK(contents == web_contents_); |
| 502 Close(); | 490 native_app_window_->Close(); |
| 503 } | 491 } |
| 504 | 492 |
| 505 bool ShellWindow::ShouldSuppressDialogs() { | 493 bool ShellWindow::ShouldSuppressDialogs() { |
| 506 return true; | 494 return true; |
| 507 } | 495 } |
| 508 | 496 |
| 509 void ShellWindow::RunFileChooser(WebContents* tab, | 497 void ShellWindow::RunFileChooser(WebContents* tab, |
| 510 const content::FileChooserParams& params) { | 498 const content::FileChooserParams& params) { |
| 511 FileSelectHelper::RunFileChooser(tab, params); | 499 FileSelectHelper::RunFileChooser(tab, params); |
| 512 } | 500 } |
| (...skipping 53 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 | 554 // TODO(jianli): once http://crbug.com/123007 is fixed, we'll no longer |
| 567 // need to make the native window (ShellWindowViews specially) update | 555 // need to make the native window (ShellWindowViews specially) update |
| 568 // the clickthrough region for the new RVH. | 556 // the clickthrough region for the new RVH. |
| 569 native_app_window_->RenderViewHostChanged(); | 557 native_app_window_->RenderViewHostChanged(); |
| 570 break; | 558 break; |
| 571 } | 559 } |
| 572 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { | 560 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
| 573 const extensions::Extension* unloaded_extension = | 561 const extensions::Extension* unloaded_extension = |
| 574 content::Details<extensions::UnloadedExtensionInfo>( | 562 content::Details<extensions::UnloadedExtensionInfo>( |
| 575 details)->extension; | 563 details)->extension; |
| 576 if (extension_ == unloaded_extension) { | 564 if (extension_ == unloaded_extension) |
| 577 Close(); | 565 native_app_window_->Close(); |
| 578 // After this notification finishes processing, the Extension will be | |
| 579 // deleted, so we null out our reference to avoid bad access. | |
| 580 extension_ = NULL; | |
| 581 } | |
| 582 break; | 566 break; |
| 583 } | 567 } |
| 584 case chrome::NOTIFICATION_APP_TERMINATING: | 568 case chrome::NOTIFICATION_APP_TERMINATING: |
| 585 Close(); | 569 native_app_window_->Close(); |
| 586 break; | 570 break; |
| 587 default: | 571 default: |
| 588 NOTREACHED() << "Received unexpected notification"; | 572 NOTREACHED() << "Received unexpected notification"; |
| 589 } | 573 } |
| 590 } | 574 } |
| 591 | 575 |
| 592 extensions::WindowController* | 576 extensions::WindowController* |
| 593 ShellWindow::GetExtensionWindowController() const { | 577 ShellWindow::GetExtensionWindowController() const { |
| 594 return NULL; | 578 return NULL; |
| 595 } | 579 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 const extensions::DraggableRegion& region = *iter; | 624 const extensions::DraggableRegion& region = *iter; |
| 641 sk_region->op( | 625 sk_region->op( |
| 642 region.bounds.x(), | 626 region.bounds.x(), |
| 643 region.bounds.y(), | 627 region.bounds.y(), |
| 644 region.bounds.right(), | 628 region.bounds.right(), |
| 645 region.bounds.bottom(), | 629 region.bounds.bottom(), |
| 646 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); | 630 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); |
| 647 } | 631 } |
| 648 return sk_region; | 632 return sk_region; |
| 649 } | 633 } |
| OLD | NEW |