15f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 25f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// found in the LICENSE file. 45f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 55f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "chrome/browser/ui/android/infobars/data_reduction_proxy_infobar.h" 65f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 75f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "base/android/jni_android.h" 85f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "base/android/jni_string.h" 95f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "base/logging.h" 105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "chrome/browser/android/resource_mapper.h" 115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "chrome/browser/net/spdyproxy/data_reduction_proxy_infobar_delegate.h" 125f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "content/public/browser/web_contents.h" 135f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "jni/DataReductionProxyInfoBarDelegate_jni.h" 145f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 155f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// DataReductionProxyInfoBar: 165f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 175f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// static 185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)void DataReductionProxyInfoBar::Launch( 191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci JNIEnv* env, jclass, jobject jweb_contents, jstring jlink_url) { 205f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) content::WebContents* web_contents = 215f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) content::WebContents::FromJavaWebContents(jweb_contents); 225f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) DCHECK(web_contents); 231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci DataReductionProxyInfoBarDelegate::Create( 241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci web_contents, base::android::ConvertJavaStringToUTF8(env, jlink_url)); 255f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 275f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// static 285f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)bool DataReductionProxyInfoBar::Register(JNIEnv* env) { 295f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) return RegisterNativesImpl(env); 305f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 315f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 325f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)DataReductionProxyInfoBar::DataReductionProxyInfoBar( 335f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) scoped_ptr<DataReductionProxyInfoBarDelegate> delegate) 345f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) : ConfirmInfoBar(delegate.PassAs<ConfirmInfoBarDelegate>()), 355f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) java_data_reduction_proxy_delegate_() { 365f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 385f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)DataReductionProxyInfoBar::~DataReductionProxyInfoBar() { 395f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 405f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 415f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)base::android::ScopedJavaLocalRef<jobject> 425f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)DataReductionProxyInfoBar::CreateRenderInfoBar(JNIEnv* env) { 435f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) java_data_reduction_proxy_delegate_.Reset( 445f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) Java_DataReductionProxyInfoBarDelegate_create(env)); 455f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 465f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) return Java_DataReductionProxyInfoBarDelegate_showDataReductionProxyInfoBar( 475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) env, 485f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) java_data_reduction_proxy_delegate_.obj(), 495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) reinterpret_cast<intptr_t>(this), 505f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) GetEnumeratedIconId()); 515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 525f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 535f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)DataReductionProxyInfoBarDelegate* DataReductionProxyInfoBar::GetDelegate() { 545f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) return static_cast<DataReductionProxyInfoBarDelegate*>(delegate()); 555f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 565f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 575f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 585f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// DataReductionProxyInfoBarDelegate: 595f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 605f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// static 615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)scoped_ptr<infobars::InfoBar> DataReductionProxyInfoBarDelegate::CreateInfoBar( 625f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) scoped_ptr<DataReductionProxyInfoBarDelegate> delegate) { 635f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) return scoped_ptr<infobars::InfoBar>( 645f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) new DataReductionProxyInfoBar(delegate.Pass())); 655f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 665f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// JNI for DataReductionProxyInfoBarDelegate. 691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccivoid 701320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciLaunch(JNIEnv* env, jclass clazz, jobject jweb_contents, jstring jlink_url) { 711320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci DataReductionProxyInfoBar::Launch(env, clazz, jweb_contents, jlink_url); 725f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 73