Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / infobars / insecure_content_infobar_delegate.cc
blob5b18054270a94390801ff3004f43fb949d280eb9
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/content_settings/content/common/content_settings_messages.h"
12 #include "components/google/core/browser/google_util.h"
13 #include "components/infobars/core/infobar.h"
14 #include "content/public/browser/render_frame_host.h"
15 #include "content/public/browser/render_view_host.h"
16 #include "content/public/browser/web_contents.h"
17 #include "grit/components_strings.h"
18 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/base/page_transition_types.h"
22 // static
23 void InsecureContentInfoBarDelegate::Create(InfoBarService* infobar_service) {
24 UMA_HISTOGRAM_ENUMERATION("InsecureContentInfoBarDelegateV2",
25 DISPLAY_INFOBAR_SHOWN, NUM_EVENTS);
27 scoped_ptr<infobars::InfoBar> new_infobar(
28 infobar_service->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>(
29 new InsecureContentInfoBarDelegate())));
31 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) {
32 infobars::InfoBar* old_infobar = infobar_service->infobar_at(i);
33 InsecureContentInfoBarDelegate* delegate =
34 old_infobar->delegate()->AsInsecureContentInfoBarDelegate();
35 if (delegate != nullptr) {
36 infobar_service->ReplaceInfoBar(old_infobar, new_infobar.Pass());
37 return;
41 infobar_service->AddInfoBar(new_infobar.Pass());
44 InsecureContentInfoBarDelegate::InsecureContentInfoBarDelegate()
45 : ConfirmInfoBarDelegate() {
48 InsecureContentInfoBarDelegate::~InsecureContentInfoBarDelegate() {
51 void InsecureContentInfoBarDelegate::InfoBarDismissed() {
52 UMA_HISTOGRAM_ENUMERATION("InsecureContentInfoBarDelegateV2",
53 DISPLAY_INFOBAR_DISMISSED, NUM_EVENTS);
54 ConfirmInfoBarDelegate::InfoBarDismissed();
57 InsecureContentInfoBarDelegate*
58 InsecureContentInfoBarDelegate::AsInsecureContentInfoBarDelegate() {
59 return this;
62 base::string16 InsecureContentInfoBarDelegate::GetMessageText() const {
63 return l10n_util::GetStringUTF16(IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT);
66 base::string16 InsecureContentInfoBarDelegate::GetButtonLabel(
67 InfoBarButton button) const {
68 return l10n_util::GetStringUTF16(button == BUTTON_OK ?
69 IDS_BLOCK_INSECURE_CONTENT_BUTTON : IDS_ALLOW_INSECURE_CONTENT_BUTTON);
72 // OK button is labelled "don't load". It triggers Accept(), but really
73 // means stay secure, so do nothing but count the event and dismiss.
74 bool InsecureContentInfoBarDelegate::Accept() {
75 UMA_HISTOGRAM_ENUMERATION("InsecureContentInfoBarDelegateV2",
76 DISPLAY_USER_DID_NOT_LOAD, NUM_EVENTS);
77 return true;
80 // Cancel button is labelled "load anyways". It triggers Cancel(), but really
81 // means become insecure, so do the work of reloading the page.
82 bool InsecureContentInfoBarDelegate::Cancel() {
83 UMA_HISTOGRAM_ENUMERATION("InsecureContentInfoBarDelegateV2",
84 DISPLAY_USER_OVERRIDE, NUM_EVENTS);
86 content::WebContents* web_contents =
87 InfoBarService::WebContentsFromInfoBar(infobar());
88 web_contents->SendToAllFrames(
89 new ChromeViewMsg_SetAllowDisplayingInsecureContent(
90 MSG_ROUTING_NONE, true));
91 web_contents->GetMainFrame()->Send(new ChromeViewMsg_ReloadFrame(
92 web_contents->GetMainFrame()->GetRoutingID()));
93 return true;
96 base::string16 InsecureContentInfoBarDelegate::GetLinkText() const {
97 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
100 bool InsecureContentInfoBarDelegate::LinkClicked(
101 WindowOpenDisposition disposition) {
102 InfoBarService::WebContentsFromInfoBar(infobar())->OpenURL(
103 content::OpenURLParams(
104 GURL("https://support.google.com/chrome/answer/1342714"),
105 content::Referrer(),
106 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition,
107 ui::PAGE_TRANSITION_LINK, false));
108 return false;