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/services/gcm/permission_bubble_request_impl.h" | 5 #include "chrome/browser/content_settings/permission_bubble_request_impl.h" |
6 | 6 |
7 #include "chrome/browser/services/gcm/permission_context_base.h" | 7 #include "chrome/browser/content_settings/permission_context_base.h" |
8 #include "grit/generated_resources.h" | 8 #include "grit/generated_resources.h" |
9 #include "grit/theme_resources.h" | 9 #include "grit/theme_resources.h" |
10 #include "net/base/net_util.h" | 10 #include "net/base/net_util.h" |
11 #include "ui/base/l10n/l10n_util.h" | 11 #include "ui/base/l10n/l10n_util.h" |
12 | 12 |
13 namespace gcm { | |
14 | |
15 PermissionBubbleRequestImpl::PermissionBubbleRequestImpl( | 13 PermissionBubbleRequestImpl::PermissionBubbleRequestImpl( |
16 const GURL& request_origin, | 14 const GURL& request_origin, |
17 bool user_gesture, | 15 bool user_gesture, |
18 ContentSettingsType type, | 16 ContentSettingsType type, |
19 const std::string& display_languages, | 17 const std::string& display_languages, |
20 const base::Callback<void(bool, bool)> permission_decided_callback, | 18 const base::Callback<void(bool, bool)> permission_decided_callback, |
21 const base::Closure delete_callback) | 19 const base::Closure delete_callback) |
22 : request_origin_(request_origin), | 20 : request_origin_(request_origin), |
23 user_gesture_(user_gesture), | 21 user_gesture_(user_gesture), |
24 type_(type), | 22 type_(type), |
25 display_languages_(display_languages), | 23 display_languages_(display_languages), |
26 permission_decided_callback_(permission_decided_callback), | 24 permission_decided_callback_(permission_decided_callback), |
27 delete_callback_(delete_callback), | 25 delete_callback_(delete_callback), |
28 is_finished_(false) {} | 26 is_finished_(false) { |
27 } | |
29 | 28 |
30 PermissionBubbleRequestImpl::~PermissionBubbleRequestImpl() { | 29 PermissionBubbleRequestImpl::~PermissionBubbleRequestImpl() { |
31 DCHECK(is_finished_); | 30 DCHECK(is_finished_); |
32 } | 31 } |
33 | 32 |
34 int PermissionBubbleRequestImpl::GetIconID() const { | 33 int PermissionBubbleRequestImpl::GetIconID() const { |
34 int icon_id; | |
35 switch (type_) { | 35 switch (type_) { |
36 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: | |
37 icon_id = IDR_ALLOWED_MIDI_SYSEX; | |
Bernhard Bauer
2014/07/04 10:24:13
Directly return the icon ID?
Miguel Garcia
2014/07/04 12:09:52
I did it this way to be consistent with the other
| |
38 break; | |
36 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING: | 39 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING: |
37 return IDR_INFOBAR_WARNING; | 40 icon_id = IDR_INFOBAR_WARNING; |
41 break; | |
38 default: | 42 default: |
39 NOTREACHED(); | 43 NOTREACHED(); |
44 return IDR_INFOBAR_WARNING; | |
40 } | 45 } |
41 return IDR_INFOBAR_WARNING; | 46 return icon_id; |
42 } | 47 } |
43 | 48 |
44 base::string16 PermissionBubbleRequestImpl::GetMessageText() const { | 49 base::string16 PermissionBubbleRequestImpl::GetMessageText() const { |
50 int message_id; | |
45 switch (type_) { | 51 switch (type_) { |
52 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: | |
53 message_id = IDS_MIDI_SYSEX_INFOBAR_QUESTION; | |
54 break; | |
46 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING: | 55 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING: |
47 return l10n_util::GetStringUTF16(IDS_PUSH_MESSAGES_BUBBLE_TEXT); | 56 message_id = IDS_PUSH_MESSAGES_PERMISSION_QUESTION; |
57 break; | |
48 default: | 58 default: |
49 NOTREACHED(); | 59 NOTREACHED(); |
60 return base::string16(); | |
50 } | 61 } |
51 return base::string16(); | 62 return l10n_util::GetStringFUTF16( |
63 message_id, | |
Bernhard Bauer
2014/07/04 10:24:13
Align four spaces.
Miguel Garcia
2014/07/04 12:09:52
Done.
| |
64 net::FormatUrl(request_origin_, display_languages_, | |
65 net::kFormatUrlOmitUsernamePassword | | |
66 net::kFormatUrlOmitTrailingSlashOnBareHostname, | |
67 net::UnescapeRule::SPACES, NULL, NULL, NULL)); | |
52 } | 68 } |
53 | 69 |
54 base::string16 PermissionBubbleRequestImpl::GetMessageTextFragment() const { | 70 base::string16 PermissionBubbleRequestImpl::GetMessageTextFragment() const { |
71 int message_id; | |
55 switch (type_) { | 72 switch (type_) { |
56 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING: | 73 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: |
57 return l10n_util::GetStringUTF16(IDS_PUSH_MESSAGES_BUBBLE_FRAGMENT); | 74 message_id = IDS_MIDI_SYSEX_PERMISSION_FRAGMENT; |
58 default: | 75 break; |
59 NOTREACHED(); | 76 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING: |
60 } | 77 message_id = IDS_PUSH_MESSAGES_BUBBLE_FRAGMENT; |
61 return base::string16(); | 78 break; |
79 default: | |
80 NOTREACHED(); | |
81 return base::string16(); | |
82 } | |
83 return l10n_util::GetStringUTF16(message_id); | |
62 } | 84 } |
63 | 85 |
64 bool PermissionBubbleRequestImpl::HasUserGesture() const { | 86 bool PermissionBubbleRequestImpl::HasUserGesture() const { |
65 return user_gesture_; | 87 return user_gesture_; |
66 } | 88 } |
67 | 89 |
68 GURL PermissionBubbleRequestImpl::GetRequestingHostname() const { | 90 GURL PermissionBubbleRequestImpl::GetRequestingHostname() const { |
69 return request_origin_; | 91 return request_origin_; |
70 } | 92 } |
71 | 93 |
72 void PermissionBubbleRequestImpl::PermissionGranted() { | 94 void PermissionBubbleRequestImpl::PermissionGranted() { |
73 permission_decided_callback_.Run(true, true); | 95 permission_decided_callback_.Run(true, true); |
74 } | 96 } |
75 | 97 |
76 void PermissionBubbleRequestImpl::PermissionDenied() { | 98 void PermissionBubbleRequestImpl::PermissionDenied() { |
77 permission_decided_callback_.Run(true, false); | 99 permission_decided_callback_.Run(true, false); |
78 } | 100 } |
79 | 101 |
80 void PermissionBubbleRequestImpl::Cancelled() { | 102 void PermissionBubbleRequestImpl::Cancelled() { |
81 permission_decided_callback_.Run(false, false); | 103 permission_decided_callback_.Run(false, false); |
82 } | 104 } |
83 | 105 |
84 void PermissionBubbleRequestImpl::RequestFinished() { | 106 void PermissionBubbleRequestImpl::RequestFinished() { |
85 is_finished_ = true; | 107 is_finished_ = true; |
86 delete_callback_.Run(); | 108 delete_callback_.Run(); |
87 } | 109 } |
88 | |
89 } // namespace gcm | |
OLD | NEW |