Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / infobars / insecure_content_infobar_delegate.cc
blobcb35acc1ea832cf768194494beafb0c755417fab
1 // Copyright (c) 2011 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.
5 #include "chrome/browser/infobars/insecure_content_infobar_delegate.h"
7 #include "base/metrics/histogram.h"
8 #include "chrome/browser/infobars/infobar_service.h"
9 #include "chrome/common/render_messages.h"
10 #include "chrome/grit/generated_resources.h"
11 #include "components/google/core/browser/google_util.h"
12 #include "components/infobars/core/infobar.h"
13 #include "content/public/browser/render_frame_host.h"
14 #include "content/public/browser/render_view_host.h"
15 #include "content/public/browser/web_contents.h"
16 #include "grit/components_strings.h"
17 #include "ui/base/l10n/l10n_util.h"
18 #include "ui/base/page_transition_types.h"
21 // static
22 void InsecureContentInfoBarDelegate::Create(InfoBarService* infobar_service) {
23 UMA_HISTOGRAM_ENUMERATION("InsecureContentInfoBarDelegateV2",
24 DISPLAY_INFOBAR_SHOWN, NUM_EVENTS);
26 scoped_ptr<infobars::InfoBar> new_infobar(
27 infobar_service->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>(
28 new InsecureContentInfoBarDelegate())));
30 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) {
31 infobars::InfoBar* old_infobar = infobar_service->infobar_at(i);
32 InsecureContentInfoBarDelegate* delegate =
33 old_infobar->delegate()->AsInsecureContentInfoBarDelegate();
34 if (delegate != nullptr) {
35 infobar_service->ReplaceInfoBar(old_infobar, new_infobar.Pass());
36 return;
40 infobar_service->AddInfoBar(new_infobar.Pass());
43 InsecureContentInfoBarDelegate::InsecureContentInfoBarDelegate()
44 : ConfirmInfoBarDelegate() {
47 InsecureContentInfoBarDelegate::~InsecureContentInfoBarDelegate() {
50 void InsecureContentInfoBarDelegate::InfoBarDismissed() {
51 UMA_HISTOGRAM_ENUMERATION("InsecureContentInfoBarDelegateV2",
52 DISPLAY_INFOBAR_DISMISSED, NUM_EVENTS);
53 ConfirmInfoBarDelegate::InfoBarDismissed();
56 InsecureContentInfoBarDelegate*
57 InsecureContentInfoBarDelegate::AsInsecureContentInfoBarDelegate() {
58 return this;
61 base::string16 InsecureContentInfoBarDelegate::GetMessageText() const {
62 return l10n_util::GetStringUTF16(IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT);
65 base::string16 InsecureContentInfoBarDelegate::GetButtonLabel(
66 InfoBarButton button) const {
67 return l10n_util::GetStringUTF16(button == BUTTON_OK ?
68 IDS_BLOCK_INSECURE_CONTENT_BUTTON : IDS_ALLOW_INSECURE_CONTENT_BUTTON);
71 // OK button is labelled "don't load". It triggers Accept(), but really
72 // means stay secure, so do nothing but count the event and dismiss.
73 bool InsecureContentInfoBarDelegate::Accept() {
74 UMA_HISTOGRAM_ENUMERATION("InsecureContentInfoBarDelegateV2",
75 DISPLAY_USER_DID_NOT_LOAD, NUM_EVENTS);
76 return true;
79 // Cancel button is labelled "load anyways". It triggers Cancel(), but really
80 // means become insecure, so do the work of reloading the page.
81 bool InsecureContentInfoBarDelegate::Cancel() {
82 UMA_HISTOGRAM_ENUMERATION("InsecureContentInfoBarDelegateV2",
83 DISPLAY_USER_OVERRIDE, NUM_EVENTS);
85 content::WebContents* web_contents =
86 InfoBarService::WebContentsFromInfoBar(infobar());
87 web_contents->SendToAllFrames(
88 new ChromeViewMsg_SetAllowDisplayingInsecureContent(
89 MSG_ROUTING_NONE, true));
90 web_contents->GetMainFrame()->Send(new ChromeViewMsg_ReloadFrame(
91 web_contents->GetMainFrame()->GetRoutingID()));
92 return true;
95 base::string16 InsecureContentInfoBarDelegate::GetLinkText() const {
96 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
99 bool InsecureContentInfoBarDelegate::LinkClicked(
100 WindowOpenDisposition disposition) {
101 InfoBarService::WebContentsFromInfoBar(infobar())->OpenURL(
102 content::OpenURLParams(
103 GURL("https://www.google.com/"
104 "support/chrome/bin/answer.py?answer=1342714"),
105 content::Referrer(),
106 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition,
107 ui::PAGE_TRANSITION_LINK, false));
108 return false;