| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "chrome/browser/infobars/insecure_content_infobar_delegate.h" | |
| 6 | |
| 7 #include <stddef.h> | |
| 8 #include <utility> | |
| 9 | |
| 10 #include "base/metrics/histogram.h" | |
| 11 #include "chrome/browser/infobars/infobar_service.h" | |
| 12 #include "chrome/common/render_messages.h" | |
| 13 #include "chrome/grit/generated_resources.h" | |
| 14 #include "components/content_settings/content/common/content_settings_messages.h
" | |
| 15 #include "components/google/core/browser/google_util.h" | |
| 16 #include "components/infobars/core/infobar.h" | |
| 17 #include "content/public/browser/render_frame_host.h" | |
| 18 #include "content/public/browser/render_view_host.h" | |
| 19 #include "content/public/browser/web_contents.h" | |
| 20 #include "grit/components_strings.h" | |
| 21 #include "ui/base/l10n/l10n_util.h" | |
| 22 #include "ui/base/page_transition_types.h" | |
| 23 | |
| 24 | |
| 25 // static | |
| 26 void InsecureContentInfoBarDelegate::Create(InfoBarService* infobar_service) { | |
| 27 UMA_HISTOGRAM_ENUMERATION("InsecureContentInfoBarDelegateV2", | |
| 28 DISPLAY_INFOBAR_SHOWN, NUM_EVENTS); | |
| 29 | |
| 30 std::unique_ptr<infobars::InfoBar> new_infobar( | |
| 31 infobar_service->CreateConfirmInfoBar( | |
| 32 std::unique_ptr<ConfirmInfoBarDelegate>( | |
| 33 new InsecureContentInfoBarDelegate()))); | |
| 34 | |
| 35 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { | |
| 36 infobars::InfoBar* old_infobar = infobar_service->infobar_at(i); | |
| 37 InsecureContentInfoBarDelegate* delegate = | |
| 38 old_infobar->delegate()->AsInsecureContentInfoBarDelegate(); | |
| 39 if (delegate != nullptr) { | |
| 40 infobar_service->ReplaceInfoBar(old_infobar, std::move(new_infobar)); | |
| 41 return; | |
| 42 } | |
| 43 } | |
| 44 | |
| 45 infobar_service->AddInfoBar(std::move(new_infobar)); | |
| 46 } | |
| 47 | |
| 48 InsecureContentInfoBarDelegate::InsecureContentInfoBarDelegate() | |
| 49 : ConfirmInfoBarDelegate() { | |
| 50 } | |
| 51 | |
| 52 InsecureContentInfoBarDelegate::~InsecureContentInfoBarDelegate() { | |
| 53 } | |
| 54 | |
| 55 infobars::InfoBarDelegate::InfoBarIdentifier | |
| 56 InsecureContentInfoBarDelegate::GetIdentifier() const { | |
| 57 return INSECURE_CONTENT_INFOBAR_DELEGATE; | |
| 58 } | |
| 59 | |
| 60 void InsecureContentInfoBarDelegate::InfoBarDismissed() { | |
| 61 UMA_HISTOGRAM_ENUMERATION("InsecureContentInfoBarDelegateV2", | |
| 62 DISPLAY_INFOBAR_DISMISSED, NUM_EVENTS); | |
| 63 ConfirmInfoBarDelegate::InfoBarDismissed(); | |
| 64 } | |
| 65 | |
| 66 InsecureContentInfoBarDelegate* | |
| 67 InsecureContentInfoBarDelegate::AsInsecureContentInfoBarDelegate() { | |
| 68 return this; | |
| 69 } | |
| 70 | |
| 71 base::string16 InsecureContentInfoBarDelegate::GetMessageText() const { | |
| 72 return l10n_util::GetStringUTF16(IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT); | |
| 73 } | |
| 74 | |
| 75 base::string16 InsecureContentInfoBarDelegate::GetButtonLabel( | |
| 76 InfoBarButton button) const { | |
| 77 return l10n_util::GetStringUTF16(button == BUTTON_OK ? | |
| 78 IDS_BLOCK_INSECURE_CONTENT_BUTTON : IDS_ALLOW_INSECURE_CONTENT_BUTTON); | |
| 79 } | |
| 80 | |
| 81 // OK button is labelled "don't load". It triggers Accept(), but really | |
| 82 // means stay secure, so do nothing but count the event and dismiss. | |
| 83 bool InsecureContentInfoBarDelegate::Accept() { | |
| 84 UMA_HISTOGRAM_ENUMERATION("InsecureContentInfoBarDelegateV2", | |
| 85 DISPLAY_USER_DID_NOT_LOAD, NUM_EVENTS); | |
| 86 return true; | |
| 87 } | |
| 88 | |
| 89 // Cancel button is labelled "load anyways". It triggers Cancel(), but really | |
| 90 // means become insecure, so do the work of reloading the page. | |
| 91 bool InsecureContentInfoBarDelegate::Cancel() { | |
| 92 UMA_HISTOGRAM_ENUMERATION("InsecureContentInfoBarDelegateV2", | |
| 93 DISPLAY_USER_OVERRIDE, NUM_EVENTS); | |
| 94 | |
| 95 content::WebContents* web_contents = | |
| 96 InfoBarService::WebContentsFromInfoBar(infobar()); | |
| 97 web_contents->SendToAllFrames( | |
| 98 new ChromeViewMsg_SetAllowDisplayingInsecureContent( | |
| 99 MSG_ROUTING_NONE, true)); | |
| 100 web_contents->GetMainFrame()->Send(new ChromeViewMsg_ReloadFrame( | |
| 101 web_contents->GetMainFrame()->GetRoutingID())); | |
| 102 return true; | |
| 103 } | |
| 104 | |
| 105 base::string16 InsecureContentInfoBarDelegate::GetLinkText() const { | |
| 106 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | |
| 107 } | |
| 108 | |
| 109 GURL InsecureContentInfoBarDelegate::GetLinkURL() const { | |
| 110 return GURL("https://support.google.com/chrome/answer/1342714"); | |
| 111 } | |
| OLD | NEW |