Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/easy_unlock_private/easy_unlock_private_ api.h" | 5 #include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_ api.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/memory/linked_ptr.h" | 11 #include "base/memory/linked_ptr.h" |
| 12 #include "base/numerics/safe_conversions.h" | |
| 12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/values.h" | 14 #include "base/values.h" |
| 14 #include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_ crypto_delegate.h" | 15 #include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_ crypto_delegate.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" | 17 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" |
| 17 #include "chrome/browser/signin/easy_unlock_service.h" | 18 #include "chrome/browser/signin/easy_unlock_service.h" |
| 18 #include "chrome/browser/signin/screenlock_bridge.h" | 19 #include "chrome/browser/signin/screenlock_bridge.h" |
| 19 #include "chrome/common/extensions/api/easy_unlock_private.h" | 20 #include "chrome/common/extensions/api/easy_unlock_private.h" |
| 20 #include "chrome/grit/generated_resources.h" | 21 #include "chrome/grit/generated_resources.h" |
| 21 #include "components/proximity_auth/bluetooth_util.h" | 22 #include "components/proximity_auth/bluetooth_util.h" |
| 22 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 24 #include "content/public/browser/web_contents.h" | |
| 23 #include "extensions/browser/browser_context_keyed_api_factory.h" | 25 #include "extensions/browser/browser_context_keyed_api_factory.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 27 #include "ui/gfx/geometry/rect.h" | |
| 28 #include "ui/gfx/range/range.h" | |
| 25 | 29 |
| 26 #if defined(OS_CHROMEOS) | 30 #if defined(OS_CHROMEOS) |
| 27 #include "chrome/browser/chromeos/chromeos_utils.h" | 31 #include "chrome/browser/chromeos/chromeos_utils.h" |
| 28 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager. h" | 32 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager. h" |
| 29 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_ factory.h" | 33 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_ factory.h" |
| 34 #include "chrome/browser/ui/proximity_auth/proximity_auth_error_bubble.h" | |
| 30 #include "chrome/browser/ui/webui/options/chromeos/user_image_source.h" | 35 #include "chrome/browser/ui/webui/options/chromeos/user_image_source.h" |
| 31 #include "components/user_manager/user.h" | 36 #include "components/user_manager/user.h" |
| 32 #include "components/user_manager/user_manager.h" | 37 #include "components/user_manager/user_manager.h" |
| 33 #endif | 38 #endif |
| 34 | 39 |
| 35 namespace extensions { | 40 namespace extensions { |
| 36 namespace api { | 41 namespace api { |
| 37 | 42 |
| 38 namespace { | 43 namespace { |
| 39 | 44 |
| (...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 703 reinterpret_cast<const char*>(user_image->front()), user_image->size())); | 708 reinterpret_cast<const char*>(user_image->front()), user_image->size())); |
| 704 #else | 709 #else |
| 705 // TODO(tengs): Find a way to get the profile picture for non-ChromeOS | 710 // TODO(tengs): Find a way to get the profile picture for non-ChromeOS |
| 706 // devices. | 711 // devices. |
| 707 results_ = easy_unlock_private::GetUserImage::Results::Create(""); | 712 results_ = easy_unlock_private::GetUserImage::Results::Create(""); |
| 708 SetError("Not supported on non-ChromeOS platforms."); | 713 SetError("Not supported on non-ChromeOS platforms."); |
| 709 #endif | 714 #endif |
| 710 return true; | 715 return true; |
| 711 } | 716 } |
| 712 | 717 |
| 718 EasyUnlockPrivateShowErrorBubbleFunction:: | |
| 719 EasyUnlockPrivateShowErrorBubbleFunction() { | |
| 720 } | |
| 721 | |
| 722 EasyUnlockPrivateShowErrorBubbleFunction:: | |
| 723 ~EasyUnlockPrivateShowErrorBubbleFunction() { | |
| 724 } | |
| 725 | |
| 726 bool EasyUnlockPrivateShowErrorBubbleFunction::RunSync() { | |
| 727 content::WebContents* web_contents = GetAssociatedWebContents(); | |
| 728 if (!web_contents) { | |
| 729 SetError("A foreground app window is required."); | |
| 730 return true; | |
| 731 } | |
| 732 | |
| 733 scoped_ptr<easy_unlock_private::ShowErrorBubble::Params> params( | |
| 734 easy_unlock_private::ShowErrorBubble::Params::Create(*args_)); | |
| 735 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
| 736 | |
| 737 if (params->link_range.start < 0 || | |
| 738 params->link_range.end < 0 || | |
| 739 base::checked_cast<size_t>(params->link_range.end) > | |
|
Tim Song
2015/01/15 19:29:24
Wouldn't saturated_cast be a bit safer in case siz
Ilya Sherman
2015/01/16 05:39:42
I'm pretty sure that size_t is guaranteed to be no
Tim Song
2015/01/16 22:50:36
My concern is that |link_range.end| is generated a
Ilya Sherman
2015/01/17 01:03:42
Done.
| |
| 740 params->message.size()) { | |
| 741 SetError("Invalid link range."); | |
| 742 return true; | |
| 743 } | |
| 744 | |
| 745 #if defined(OS_CHROMEOS) | |
| 746 gfx::Rect anchor_rect( | |
| 747 params->anchor_rect.left, params->anchor_rect.top, | |
| 748 params->anchor_rect.width, params->anchor_rect.height); | |
| 749 anchor_rect += | |
| 750 web_contents->GetContainerBounds().OffsetFromOrigin(); | |
| 751 ProximityAuthErrorBubble::ShowErrorBubble( | |
| 752 base::UTF8ToUTF16(params->message), | |
| 753 gfx::Range(params->link_range.start, params->link_range.end), | |
| 754 GURL(params->link_target), anchor_rect, web_contents); | |
| 755 #else | |
| 756 SetError("Not supported on non-ChromeOS platforms."); | |
| 757 #endif | |
| 758 return true; | |
| 759 } | |
| 760 | |
| 713 } // namespace api | 761 } // namespace api |
| 714 } // namespace extensions | 762 } // namespace extensions |
| OLD | NEW |