summaryrefslogtreecommitdiffstats
path: root/chrome/browser/content_settings/permission_bubble_request_impl.cc
blob: 3767de224fc4decfd91b4e4458a22b0b2f448c1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/content_settings/permission_bubble_request_impl.h"

#include "chrome/browser/content_settings/permission_context_base.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "net/base/net_util.h"
#include "ui/base/l10n/l10n_util.h"

PermissionBubbleRequestImpl::PermissionBubbleRequestImpl(
    const GURL& request_origin,
    bool user_gesture,
    ContentSettingsType type,
    const std::string& display_languages,
    const base::Callback<void(bool, bool)> permission_decided_callback,
    const base::Closure delete_callback)
    : request_origin_(request_origin),
      user_gesture_(user_gesture),
      type_(type),
      display_languages_(display_languages),
      permission_decided_callback_(permission_decided_callback),
      delete_callback_(delete_callback),
      is_finished_(false) {
}

PermissionBubbleRequestImpl::~PermissionBubbleRequestImpl() {
  DCHECK(is_finished_);
}

int PermissionBubbleRequestImpl::GetIconID() const {
  int icon_id;
  switch (type_) {
    case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
      icon_id = IDR_ALLOWED_MIDI_SYSEX;
      break;
    case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING:
      icon_id = IDR_INFOBAR_WARNING;
      break;
    default:
      NOTREACHED();
      return IDR_INFOBAR_WARNING;
  }
  return icon_id;
}

base::string16 PermissionBubbleRequestImpl::GetMessageText() const {
  int message_id;
  switch (type_) {
      case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
        message_id = IDS_MIDI_SYSEX_INFOBAR_QUESTION;
        break;
      case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING:
        message_id = IDS_PUSH_MESSAGES_PERMISSION_QUESTION;
        break;
      default:
        NOTREACHED();
        return base::string16();
    }
  return l10n_util::GetStringFUTF16(
      message_id,
      net::FormatUrl(request_origin_, display_languages_,
                     net::kFormatUrlOmitUsernamePassword |
                     net::kFormatUrlOmitTrailingSlashOnBareHostname,
                     net::UnescapeRule::SPACES, NULL, NULL, NULL));
}

base::string16 PermissionBubbleRequestImpl::GetMessageTextFragment() const {
  int message_id;
  switch (type_) {
    case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
      message_id = IDS_MIDI_SYSEX_PERMISSION_FRAGMENT;
      break;
    case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING:
      message_id = IDS_PUSH_MESSAGES_BUBBLE_FRAGMENT;
      break;
    default:
      NOTREACHED();
      return base::string16();
  }
  return l10n_util::GetStringUTF16(message_id);
}

bool PermissionBubbleRequestImpl::HasUserGesture() const {
  return user_gesture_;
}

GURL PermissionBubbleRequestImpl::GetRequestingHostname() const {
  return request_origin_;
}

void PermissionBubbleRequestImpl::PermissionGranted() {
  permission_decided_callback_.Run(true, true);
}

void PermissionBubbleRequestImpl::PermissionDenied() {
  permission_decided_callback_.Run(true, false);
}

void PermissionBubbleRequestImpl::Cancelled() {
  permission_decided_callback_.Run(false, false);
}

void PermissionBubbleRequestImpl::RequestFinished() {
  is_finished_ = true;
  delete_callback_.Run();
}