Index: chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_api.cc |
diff --git a/chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_api.cc b/chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_api.cc |
index 6021e28fa026c304e7e85f335715e7399b3b2bd8..4a863f3fec00662abc16a304215218936a29f5ae 100644 |
--- a/chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_api.cc |
+++ b/chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_api.cc |
@@ -9,6 +9,7 @@ |
#include "base/bind.h" |
#include "base/lazy_instance.h" |
#include "base/memory/linked_ptr.h" |
+#include "base/numerics/safe_conversions.h" |
#include "base/strings/utf_string_conversions.h" |
#include "base/values.h" |
#include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_crypto_delegate.h" |
@@ -20,13 +21,17 @@ |
#include "chrome/grit/generated_resources.h" |
#include "components/proximity_auth/bluetooth_util.h" |
#include "content/public/browser/browser_thread.h" |
+#include "content/public/browser/web_contents.h" |
#include "extensions/browser/browser_context_keyed_api_factory.h" |
#include "ui/base/l10n/l10n_util.h" |
+#include "ui/gfx/geometry/rect.h" |
+#include "ui/gfx/range/range.h" |
#if defined(OS_CHROMEOS) |
#include "chrome/browser/chromeos/chromeos_utils.h" |
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager.h" |
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_factory.h" |
+#include "chrome/browser/ui/proximity_auth/proximity_auth_error_bubble.h" |
#include "chrome/browser/ui/webui/options/chromeos/user_image_source.h" |
#include "components/user_manager/user.h" |
#include "components/user_manager/user_manager.h" |
@@ -710,5 +715,48 @@ bool EasyUnlockPrivateGetUserImageFunction::RunSync() { |
return true; |
} |
+EasyUnlockPrivateShowErrorBubbleFunction:: |
+ EasyUnlockPrivateShowErrorBubbleFunction() { |
+} |
+ |
+EasyUnlockPrivateShowErrorBubbleFunction:: |
+ ~EasyUnlockPrivateShowErrorBubbleFunction() { |
+} |
+ |
+bool EasyUnlockPrivateShowErrorBubbleFunction::RunSync() { |
+ content::WebContents* web_contents = GetAssociatedWebContents(); |
+ if (!web_contents) { |
+ SetError("A foreground app window is required."); |
+ return true; |
+ } |
+ |
+ scoped_ptr<easy_unlock_private::ShowErrorBubble::Params> params( |
+ easy_unlock_private::ShowErrorBubble::Params::Create(*args_)); |
+ EXTENSION_FUNCTION_VALIDATE(params.get()); |
+ |
+ if (params->link_range.start < 0 || |
+ params->link_range.end < 0 || |
+ 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.
|
+ params->message.size()) { |
+ SetError("Invalid link range."); |
+ return true; |
+ } |
+ |
+#if defined(OS_CHROMEOS) |
+ gfx::Rect anchor_rect( |
+ params->anchor_rect.left, params->anchor_rect.top, |
+ params->anchor_rect.width, params->anchor_rect.height); |
+ anchor_rect += |
+ web_contents->GetContainerBounds().OffsetFromOrigin(); |
+ ProximityAuthErrorBubble::ShowErrorBubble( |
+ base::UTF8ToUTF16(params->message), |
+ gfx::Range(params->link_range.start, params->link_range.end), |
+ GURL(params->link_target), anchor_rect, web_contents); |
+#else |
+ SetError("Not supported on non-ChromeOS platforms."); |
+#endif |
+ return true; |
+} |
+ |
} // namespace api |
} // namespace extensions |