Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / geolocation / geolocation_infobar_delegate.cc
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 #include "chrome/browser/geolocation/geolocation_infobar_delegate.h"
6
7 #include "base/metrics/histogram.h"
8 #include "chrome/browser/content_settings/permission_queue_controller.h"
9 #include "chrome/browser/infobars/infobar_service.h"
10 #include "chrome/grit/generated_resources.h"
11 #include "chrome/grit/locale_settings.h"
12 #include "components/google/core/browser/google_util.h"
13 #include "components/infobars/core/infobar.h"
14 #include "content/public/browser/navigation_details.h"
15 #include "content/public/browser/navigation_entry.h"
16 #include "content/public/browser/web_contents.h"
17 #include "grit/generated_resources.h"
18 #include "grit/locale_settings.h"
19 #include "grit/theme_resources.h"
20 #include "net/base/net_util.h"
21 #include "ui/base/l10n/l10n_util.h"
22
23
24 // static
25 infobars::InfoBar* GeolocationInfoBarDelegate::Create(
26     InfoBarService* infobar_service,
27     PermissionQueueController* controller,
28     const PermissionRequestID& id,
29     const GURL& requesting_frame,
30     const std::string& display_languages) {
31   const content::NavigationEntry* committed_entry =
32       infobar_service->web_contents()->GetController().GetLastCommittedEntry();
33   GeolocationInfoBarDelegate* const delegate = new GeolocationInfoBarDelegate(
34           controller, id, requesting_frame,
35           committed_entry ? committed_entry->GetUniqueID() : 0,
36           display_languages);
37
38   infobars::InfoBar* infobar = ConfirmInfoBarDelegate::CreateInfoBar(
39       scoped_ptr<ConfirmInfoBarDelegate>(delegate)).release();
40   return infobar_service->AddInfoBar(scoped_ptr<infobars::InfoBar>(infobar));
41 }
42
43 GeolocationInfoBarDelegate::GeolocationInfoBarDelegate(
44     PermissionQueueController* controller,
45     const PermissionRequestID& id,
46     const GURL& requesting_frame,
47     int contents_unique_id,
48     const std::string& display_languages)
49     : PermissionInfobarDelegate(controller, id, requesting_frame,
50                                 CONTENT_SETTINGS_TYPE_GEOLOCATION),
51       requesting_frame_(requesting_frame),
52       display_languages_(display_languages) {
53 }
54
55 GeolocationInfoBarDelegate::~GeolocationInfoBarDelegate() {
56 }
57
58 int GeolocationInfoBarDelegate::GetIconID() const {
59   return IDR_INFOBAR_GEOLOCATION;
60 }
61
62 base::string16 GeolocationInfoBarDelegate::GetMessageText() const {
63   return l10n_util::GetStringFUTF16(IDS_GEOLOCATION_INFOBAR_QUESTION,
64       net::FormatUrl(requesting_frame_, display_languages_,
65                      net::kFormatUrlOmitUsernamePassword |
66                      net::kFormatUrlOmitTrailingSlashOnBareHostname,
67                      net::UnescapeRule::SPACES, NULL, NULL, NULL));
68 }