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