Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(882)

Side by Side Diff: chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_api.cc

Issue 843023002: [Smart Lock] Add a private API to show an error bubble anchored to the Smart Lock app window. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update StyledLabel to specify a preferred size Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/command_line.h" 10 #include "base/command_line.h"
11 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "base/memory/linked_ptr.h" 12 #include "base/memory/linked_ptr.h"
13 #include "base/numerics/safe_conversions.h"
13 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
14 #include "base/values.h" 15 #include "base/values.h"
15 #include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_ crypto_delegate.h" 16 #include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_ crypto_delegate.h"
16 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" 18 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h"
18 #include "chrome/browser/signin/easy_unlock_service.h" 19 #include "chrome/browser/signin/easy_unlock_service.h"
19 #include "chrome/browser/signin/screenlock_bridge.h" 20 #include "chrome/browser/signin/screenlock_bridge.h"
21 #include "chrome/browser/ui/proximity_auth/proximity_auth_error_bubble.h"
20 #include "chrome/common/extensions/api/easy_unlock_private.h" 22 #include "chrome/common/extensions/api/easy_unlock_private.h"
21 #include "chrome/grit/generated_resources.h" 23 #include "chrome/grit/generated_resources.h"
22 #include "components/proximity_auth/bluetooth_util.h" 24 #include "components/proximity_auth/bluetooth_util.h"
23 #include "components/proximity_auth/switches.h" 25 #include "components/proximity_auth/switches.h"
24 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/web_contents.h"
25 #include "extensions/browser/browser_context_keyed_api_factory.h" 28 #include "extensions/browser/browser_context_keyed_api_factory.h"
26 #include "ui/base/l10n/l10n_util.h" 29 #include "ui/base/l10n/l10n_util.h"
30 #include "ui/gfx/geometry/rect.h"
31 #include "ui/gfx/range/range.h"
27 32
28 #if defined(OS_CHROMEOS) 33 #if defined(OS_CHROMEOS)
29 #include "chrome/browser/chromeos/chromeos_utils.h" 34 #include "chrome/browser/chromeos/chromeos_utils.h"
30 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager. h" 35 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager. h"
31 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_ factory.h" 36 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_ factory.h"
32 #include "chrome/browser/ui/webui/options/chromeos/user_image_source.h" 37 #include "chrome/browser/ui/webui/options/chromeos/user_image_source.h"
33 #include "components/user_manager/user.h" 38 #include "components/user_manager/user.h"
34 #include "components/user_manager/user_manager.h" 39 #include "components/user_manager/user_manager.h"
35 #endif 40 #endif
36 41
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 "setupErrorBluetoothUnavailable", 298 "setupErrorBluetoothUnavailable",
294 l10n_util::GetStringFUTF16( 299 l10n_util::GetStringFUTF16(
295 IDS_EASY_UNLOCK_SETUP_ERROR_BLUETOOTH_UNAVAILBLE, device_type)); 300 IDS_EASY_UNLOCK_SETUP_ERROR_BLUETOOTH_UNAVAILBLE, device_type));
296 strings->SetString( 301 strings->SetString(
297 "setupErrorOffline", 302 "setupErrorOffline",
298 l10n_util::GetStringFUTF16( 303 l10n_util::GetStringFUTF16(
299 IDS_EASY_UNLOCK_SETUP_ERROR_OFFLINE, device_type)); 304 IDS_EASY_UNLOCK_SETUP_ERROR_OFFLINE, device_type));
300 strings->SetString( 305 strings->SetString(
301 "setupErrorFindingPhone", 306 "setupErrorFindingPhone",
302 l10n_util::GetStringUTF16(IDS_EASY_UNLOCK_SETUP_ERROR_FINDING_PHONE)); 307 l10n_util::GetStringUTF16(IDS_EASY_UNLOCK_SETUP_ERROR_FINDING_PHONE));
308 // TODO(isherman): Remove the setupErrorBluetoothConnectionFailed string; it
309 // is unused.
303 strings->SetString( 310 strings->SetString(
304 "setupErrorBluetoothConnectionFailed", 311 "setupErrorBluetoothConnectionFailed",
305 l10n_util::GetStringFUTF16( 312 l10n_util::GetStringFUTF16(
306 IDS_EASY_UNLOCK_SETUP_ERROR_BLUETOOTH_CONNECTION_FAILED, 313 IDS_EASY_UNLOCK_SETUP_ERROR_BLUETOOTH_CONNECTION_FAILED,
307 device_type)); 314 device_type));
315 // TODO(isherman): Remove the setupErrorConnectionToPhoneTimeout string; it is
316 // identical to the setupErrorConnectingToPhone string, and hence obsolete.
308 strings->SetString( 317 strings->SetString(
309 "setupErrorConnectionToPhoneTimeout", 318 "setupErrorConnectionToPhoneTimeout",
310 l10n_util::GetStringFUTF16( 319 l10n_util::GetStringFUTF16(
311 IDS_EASY_UNLOCK_SETUP_ERROR_CONNECT_TO_PHONE_TIMEOUT, 320 IDS_EASY_UNLOCK_SETUP_ERROR_CONNECT_TO_PHONE_TIMEOUT,
312 device_type)); 321 device_type));
313 strings->SetString( 322 strings->SetString(
314 "setupErrorSyncPhoneState", 323 "setupErrorSyncPhoneState",
315 l10n_util::GetStringUTF16( 324 l10n_util::GetStringUTF16(
316 IDS_EASY_UNLOCK_SETUP_ERROR_SYNC_PHONE_STATE_FAILED)); 325 IDS_EASY_UNLOCK_SETUP_ERROR_SYNC_PHONE_STATE_FAILED));
317 strings->SetString( 326 strings->SetString(
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 void EasyUnlockPrivateGetConnectionInfoFunction::OnConnectionInfo( 770 void EasyUnlockPrivateGetConnectionInfoFunction::OnConnectionInfo(
762 const device::BluetoothDevice::ConnectionInfo& connection_info) { 771 const device::BluetoothDevice::ConnectionInfo& connection_info) {
763 scoped_ptr<base::ListValue> results(new base::ListValue()); 772 scoped_ptr<base::ListValue> results(new base::ListValue());
764 results->AppendInteger(connection_info.rssi); 773 results->AppendInteger(connection_info.rssi);
765 results->AppendInteger(connection_info.transmit_power); 774 results->AppendInteger(connection_info.transmit_power);
766 results->AppendInteger(connection_info.max_transmit_power); 775 results->AppendInteger(connection_info.max_transmit_power);
767 SetResultList(results.Pass()); 776 SetResultList(results.Pass());
768 SendResponse(true); 777 SendResponse(true);
769 } 778 }
770 779
780 EasyUnlockPrivateShowErrorBubbleFunction::
781 EasyUnlockPrivateShowErrorBubbleFunction() {
782 }
783
784 EasyUnlockPrivateShowErrorBubbleFunction::
785 ~EasyUnlockPrivateShowErrorBubbleFunction() {
786 }
787
788 bool EasyUnlockPrivateShowErrorBubbleFunction::RunSync() {
789 content::WebContents* web_contents = GetAssociatedWebContents();
790 if (!web_contents) {
791 SetError("A foreground app window is required.");
792 return true;
793 }
794
795 scoped_ptr<easy_unlock_private::ShowErrorBubble::Params> params(
796 easy_unlock_private::ShowErrorBubble::Params::Create(*args_));
797 EXTENSION_FUNCTION_VALIDATE(params.get());
798
799 if (params->link_range.start < 0 ||
800 params->link_range.end < 0 ||
801 base::saturated_cast<size_t>(params->link_range.end) >
802 params->message.size()) {
803 SetError("Invalid link range.");
804 return true;
805 }
806
807 #if defined(TOOLKIT_VIEWS)
808 gfx::Rect anchor_rect(
809 params->anchor_rect.left, params->anchor_rect.top,
810 params->anchor_rect.width, params->anchor_rect.height);
811 anchor_rect +=
812 web_contents->GetContainerBounds().OffsetFromOrigin();
813 ProximityAuthErrorBubble::ShowErrorBubble(
814 base::UTF8ToUTF16(params->message),
815 gfx::Range(params->link_range.start, params->link_range.end),
816 GURL(params->link_target), anchor_rect, web_contents);
817 #else
818 SetError("Not supported on non-Views platforms.");
819 #endif
820 return true;
821 }
822
771 } // namespace api 823 } // namespace api
772 } // namespace extensions 824 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698