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 3 // found in the LICENSE file. 4 5 #include "chrome/browser/ui/fullscreen/fullscreen_exit_bubble_type.h" 6 7 #include "base/strings/utf_string_conversions.h" 8 #include "chrome/browser/extensions/extension_service.h" 9 #include "chrome/common/url_constants.h" 10 #include "extensions/common/constants.h" 11 #include "extensions/common/extension.h" 12 #include "extensions/common/extension_set.h" 13 #include "grit/generated_resources.h" 14 #include "ui/base/l10n/l10n_util.h" 15 16 namespace fullscreen_bubble { 17 18 base::string16 GetLabelTextForType(FullscreenExitBubbleType type, 19 const GURL& url, 20 ExtensionService* extension_service) { 21 base::string16 host(base::UTF8ToUTF16(url.host())); 22 if (extension_service) { 23 const extensions::ExtensionSet* extensions = 24 extension_service->extensions(); 25 DCHECK(extensions); 26 const extensions::Extension* extension = 27 extensions->GetExtensionOrAppByURL(url); 28 if (extension) { 29 host = base::UTF8ToUTF16(extension->name()); 30 } else if (url.SchemeIs(extensions::kExtensionScheme)) { 31 // In this case, |host| is set to an extension ID. 32 // We are not going to show it because it's human-unreadable. 33 host.clear(); 34 } 35 } 36 if (host.empty()) { 37 switch (type) { 38 case FEB_TYPE_FULLSCREEN_BUTTONS: 39 case FEB_TYPE_FULLSCREEN_EXIT_INSTRUCTION: 40 return l10n_util::GetStringUTF16(IDS_FULLSCREEN_ENTERED_FULLSCREEN); 41 case FEB_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS: 42 return l10n_util::GetStringUTF16( 43 IDS_FULLSCREEN_REQUEST_FULLSCREEN_MOUSELOCK); 44 case FEB_TYPE_MOUSELOCK_BUTTONS: 45 return l10n_util::GetStringUTF16(IDS_FULLSCREEN_REQUEST_MOUSELOCK); 46 case FEB_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION: 47 return l10n_util::GetStringUTF16( 48 IDS_FULLSCREEN_ENTERED_FULLSCREEN_MOUSELOCK); 49 case FEB_TYPE_MOUSELOCK_EXIT_INSTRUCTION: 50 return l10n_util::GetStringUTF16( 51 IDS_FULLSCREEN_ENTERED_MOUSELOCK); 52 case FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION: 53 return l10n_util::GetStringUTF16( 54 IDS_FULLSCREEN_USER_ENTERED_FULLSCREEN); 55 case FEB_TYPE_BROWSER_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION: 56 return l10n_util::GetStringUTF16( 57 IDS_FULLSCREEN_UNKNOWN_EXTENSION_TRIGGERED_FULLSCREEN); 58 default: 59 NOTREACHED(); 60 return base::string16(); 61 } 62 } 63 switch (type) { 64 case FEB_TYPE_FULLSCREEN_BUTTONS: 65 return l10n_util::GetStringFUTF16( 66 IDS_FULLSCREEN_SITE_ENTERED_FULLSCREEN, host); 67 case FEB_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS: 68 return l10n_util::GetStringFUTF16( 69 IDS_FULLSCREEN_SITE_REQUEST_FULLSCREEN_MOUSELOCK, host); 70 case FEB_TYPE_MOUSELOCK_BUTTONS: 71 return l10n_util::GetStringFUTF16( 72 IDS_FULLSCREEN_SITE_REQUEST_MOUSELOCK, host); 73 case FEB_TYPE_FULLSCREEN_EXIT_INSTRUCTION: 74 return l10n_util::GetStringFUTF16( 75 IDS_FULLSCREEN_SITE_ENTERED_FULLSCREEN, host); 76 case FEB_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION: 77 return l10n_util::GetStringFUTF16( 78 IDS_FULLSCREEN_SITE_ENTERED_FULLSCREEN_MOUSELOCK, host); 79 case FEB_TYPE_MOUSELOCK_EXIT_INSTRUCTION: 80 return l10n_util::GetStringFUTF16( 81 IDS_FULLSCREEN_SITE_ENTERED_MOUSELOCK, host); 82 case FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION: 83 return l10n_util::GetStringUTF16( 84 IDS_FULLSCREEN_USER_ENTERED_FULLSCREEN); 85 case FEB_TYPE_BROWSER_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION: 86 return l10n_util::GetStringFUTF16( 87 IDS_FULLSCREEN_EXTENSION_TRIGGERED_FULLSCREEN, host); 88 default: 89 NOTREACHED(); 90 return base::string16(); 91 } 92 } 93 94 base::string16 GetDenyButtonTextForType(FullscreenExitBubbleType type) { 95 switch (type) { 96 case FEB_TYPE_FULLSCREEN_BUTTONS: 97 return l10n_util::GetStringUTF16(IDS_FULLSCREEN_EXIT_FULLSCREEN); 98 case FEB_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS: 99 return l10n_util::GetStringUTF16(IDS_FULLSCREEN_EXIT); 100 case FEB_TYPE_MOUSELOCK_BUTTONS: 101 return l10n_util::GetStringUTF16(IDS_FULLSCREEN_DENY); 102 case FEB_TYPE_FULLSCREEN_EXIT_INSTRUCTION: 103 case FEB_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION: 104 case FEB_TYPE_MOUSELOCK_EXIT_INSTRUCTION: 105 case FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION: 106 case FEB_TYPE_BROWSER_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION: 107 NOTREACHED(); // No button in this case. 108 return base::string16(); 109 default: 110 NOTREACHED(); 111 return base::string16(); 112 } 113 } 114 115 bool ShowButtonsForType(FullscreenExitBubbleType type) { 116 return type == FEB_TYPE_FULLSCREEN_BUTTONS || 117 type == FEB_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS || 118 type == FEB_TYPE_MOUSELOCK_BUTTONS; 119 } 120 121 void PermissionRequestedByType(FullscreenExitBubbleType type, 122 bool* tab_fullscreen, 123 bool* mouse_lock) { 124 if (tab_fullscreen) { 125 *tab_fullscreen = type == FEB_TYPE_FULLSCREEN_BUTTONS || 126 type == FEB_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS; 127 } 128 if (mouse_lock) { 129 *mouse_lock = type == FEB_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS || 130 type == FEB_TYPE_MOUSELOCK_BUTTONS; 131 } 132 } 133 134 } // namespace fullscreen_bubble 135