1// Copyright 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#ifndef CHROME_BROWSER_GEOLOCATION_GEOLOCATION_INFOBAR_DELEGATE_H_
6#define CHROME_BROWSER_GEOLOCATION_GEOLOCATION_INFOBAR_DELEGATE_H_
7
8#include <string>
9
10#include "components/content_settings/core/common/permission_request_id.h"
11#include "components/infobars/core/confirm_infobar_delegate.h"
12#include "url/gurl.h"
13
14class PermissionQueueController;
15class InfoBarService;
16
17// GeolocationInfoBarDelegates are created by the
18// GeolocationInfoBarQueueController to control the display
19// and handling of geolocation permission infobars to the user.
20class GeolocationInfoBarDelegate : public ConfirmInfoBarDelegate {
21 public:
22  // Creates a geolocation infobar and delegate and adds the infobar to
23  // |infobar_service|.  Returns the infobar if it was successfully added.
24  static infobars::InfoBar* Create(InfoBarService* infobar_service,
25                                   PermissionQueueController* controller,
26                                   const PermissionRequestID& id,
27                                   const GURL& requesting_frame,
28                                   const std::string& display_languages);
29
30 private:
31  GeolocationInfoBarDelegate(PermissionQueueController* controller,
32                             const PermissionRequestID& id,
33                             const GURL& requesting_frame,
34                             int contents_unique_id,
35                             const std::string& display_languages);
36  virtual ~GeolocationInfoBarDelegate();
37
38  // ConfirmInfoBarDelegate:
39  virtual bool Accept() OVERRIDE;
40  virtual void InfoBarDismissed() OVERRIDE;
41  virtual int GetIconID() const OVERRIDE;
42  virtual Type GetInfoBarType() const OVERRIDE;
43  virtual bool ShouldExpireInternal(
44      const NavigationDetails& details) const OVERRIDE;
45  virtual base::string16 GetMessageText() const OVERRIDE;
46  virtual base::string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
47  virtual bool Cancel() OVERRIDE;
48
49
50  // Call back to the controller, to inform of the user's decision.
51  void SetPermission(bool update_content_setting, bool allowed);
52
53  // Marks a flag internally to indicate that the user has interacted with the
54  // bar. This makes it possible to log from the destructor when the bar has not
55  // been used, i.e. it has been ignored by the user.
56  void set_user_has_interacted() {
57    user_has_interacted_ = true;
58  }
59
60  PermissionQueueController* controller_;
61  const PermissionRequestID id_;
62  GURL requesting_frame_;
63  int contents_unique_id_;
64  std::string display_languages_;
65
66  // Whether the user has interacted with the geolocation infobar.
67  bool user_has_interacted_;
68
69  DISALLOW_COPY_AND_ASSIGN(GeolocationInfoBarDelegate);
70};
71
72#endif  // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_INFOBAR_DELEGATE_H_
73