1// Copyright 2014 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/net/spdyproxy/data_reduction_proxy_infobar_delegate.h" 6 7#include "base/memory/scoped_ptr.h" 8#include "chrome/browser/infobars/infobar_service.h" 9#include "components/infobars/core/infobar.h" 10#include "components/infobars/core/infobar_delegate.h" 11#include "content/public/browser/web_contents.h" 12#include "grit/components_strings.h" 13#include "ui/base/l10n/l10n_util.h" 14#include "url/gurl.h" 15 16// static 17void DataReductionProxyInfoBarDelegate::Create( 18 content::WebContents* web_contents, const std::string& link_url) { 19 InfoBarService::FromWebContents(web_contents)->AddInfoBar( 20 DataReductionProxyInfoBarDelegate::CreateInfoBar( 21 scoped_ptr<DataReductionProxyInfoBarDelegate>( 22 new DataReductionProxyInfoBarDelegate(link_url)))); 23} 24 25#if !defined(OS_ANDROID) 26// This infobar currently only supports Android. 27 28// static 29scoped_ptr<infobars::InfoBar> DataReductionProxyInfoBarDelegate::CreateInfoBar( 30 scoped_ptr<DataReductionProxyInfoBarDelegate> delegate) { 31 return ConfirmInfoBarDelegate::CreateInfoBar( 32 delegate.PassAs<ConfirmInfoBarDelegate>()); 33} 34#endif 35 36DataReductionProxyInfoBarDelegate::~DataReductionProxyInfoBarDelegate() { 37} 38 39DataReductionProxyInfoBarDelegate::DataReductionProxyInfoBarDelegate( 40 const std::string& link_url) 41 : ConfirmInfoBarDelegate(), 42 link_url_(link_url) { 43} 44 45bool DataReductionProxyInfoBarDelegate::ShouldExpire( 46 const NavigationDetails& details) const { 47 return false; 48} 49 50base::string16 DataReductionProxyInfoBarDelegate::GetMessageText() const { 51 return base::string16(); 52} 53 54int DataReductionProxyInfoBarDelegate::GetButtons() const { 55 return BUTTON_NONE; 56} 57 58bool DataReductionProxyInfoBarDelegate::LinkClicked( 59 WindowOpenDisposition disposition) { 60 InfoBarService::WebContentsFromInfoBar(infobar())->OpenURL( 61 content::OpenURLParams( 62 GURL(link_url_), 63 content::Referrer(), 64 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, 65 ui::PAGE_TRANSITION_LINK, false)); 66 return true; 67} 68