| Index: chrome/browser/android/logo_bridge.cc
|
| diff --git a/chrome/browser/android/logo_bridge.cc b/chrome/browser/android/logo_bridge.cc
|
| index d2250b2232e067f2e334d15deb60ca23118d2b4c..764f6303133827cae5bd85796548540c52630c92 100644
|
| --- a/chrome/browser/android/logo_bridge.cc
|
| +++ b/chrome/browser/android/logo_bridge.cc
|
| @@ -7,19 +7,24 @@
|
| #include <jni.h>
|
|
|
| #include "base/android/jni_android.h"
|
| +#include "base/android/jni_array.h"
|
| #include "base/android/jni_string.h"
|
| #include "base/android/scoped_java_ref.h"
|
| -#include "base/bind.h"
|
| #include "chrome/browser/android/logo_service.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| #include "chrome/browser/profiles/profile_android.h"
|
| #include "components/search_provider_logos/logo_tracker.h"
|
| #include "jni/LogoBridge_jni.h"
|
| +#include "net/url_request/url_fetcher.h"
|
| +#include "net/url_request/url_request_context_getter.h"
|
| +#include "net/url_request/url_request_status.h"
|
| #include "third_party/skia/include/core/SkBitmap.h"
|
| #include "ui/gfx/android/java_bitmap.h"
|
|
|
| -using base::android::ScopedJavaLocalRef;
|
| +using base::android::ConvertJavaStringToUTF8;
|
| using base::android::ConvertUTF8ToJavaString;
|
| +using base::android::ScopedJavaLocalRef;
|
| +using base::android::ToJavaByteArray;
|
|
|
| namespace {
|
|
|
| @@ -40,8 +45,12 @@ ScopedJavaLocalRef<jobject> ConvertLogoToJavaObject(
|
| if (!logo->metadata.alt_text.empty())
|
| j_alt_text = ConvertUTF8ToJavaString(env, logo->metadata.alt_text);
|
|
|
| - return Java_LogoBridge_createLogo(
|
| - env, j_bitmap.obj(), j_on_click_url.obj(), j_alt_text.obj());
|
| + ScopedJavaLocalRef<jstring> j_animated_url;
|
| + if (!logo->metadata.animated_url.empty())
|
| + j_animated_url = ConvertUTF8ToJavaString(env, logo->metadata.animated_url);
|
| +
|
| + return Java_LogoBridge_createLogo(env, j_bitmap.obj(), j_on_click_url.obj(),
|
| + j_alt_text.obj(), j_animated_url.obj());
|
| }
|
|
|
| class LogoObserverAndroid : public search_provider_logos::LogoObserver {
|
| @@ -88,11 +97,15 @@ static jlong Init(JNIEnv* env,
|
|
|
| LogoBridge::LogoBridge(jobject j_profile) : weak_ptr_factory_(this) {
|
| Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile);
|
| - if (profile)
|
| + if (profile) {
|
| logo_service_ = LogoServiceFactory::GetForProfile(profile);
|
| + request_context_getter_ = profile->GetRequestContext();
|
| + }
|
| }
|
|
|
| -LogoBridge::~LogoBridge() {}
|
| +LogoBridge::~LogoBridge() {
|
| + ClearFetcher();
|
| +}
|
|
|
| void LogoBridge::Destroy(JNIEnv* env, jobject obj) {
|
| delete this;
|
| @@ -110,6 +123,49 @@ void LogoBridge::GetCurrentLogo(JNIEnv* env,
|
| logo_service_->GetLogo(observer);
|
| }
|
|
|
| +void LogoBridge::GetAnimatedLogo(JNIEnv* env,
|
| + jobject obj,
|
| + jobject j_callback,
|
| + jstring j_url) {
|
| + DCHECK(j_callback);
|
| + if (!logo_service_)
|
| + return;
|
| +
|
| + GURL url = GURL(ConvertJavaStringToUTF8(env, j_url));
|
| + if (fetcher_ && fetcher_->GetOriginalURL() == url)
|
| + return;
|
| +
|
| + j_callback_.Reset(env, j_callback);
|
| + fetcher_ = net::URLFetcher::Create(url, net::URLFetcher::GET, this);
|
| + fetcher_->SetRequestContext(request_context_getter_.get());
|
| + fetcher_->Start();
|
| +}
|
| +
|
| +void LogoBridge::OnURLFetchComplete(const net::URLFetcher* source) {
|
| + if (!source->GetStatus().is_success() || (source->GetResponseCode() != 200) ||
|
| + j_callback_.is_null()) {
|
| + ClearFetcher();
|
| + return;
|
| + }
|
| +
|
| + std::string response;
|
| + source->GetResponseAsString(&response);
|
| + JNIEnv* env = base::android::AttachCurrentThread();
|
| +
|
| + ScopedJavaLocalRef<jbyteArray> j_bytes = ToJavaByteArray(
|
| + env, reinterpret_cast<const uint8*>(response.data()), response.length());
|
| + ScopedJavaLocalRef<jobject> j_gif_image =
|
| + Java_LogoBridge_createGifImage(env, j_bytes.obj());
|
| + Java_AnimatedLogoCallback_onAnimatedLogoAvailable(env, j_callback_.obj(),
|
| + j_gif_image.obj());
|
| + ClearFetcher();
|
| +}
|
| +
|
| +void LogoBridge::ClearFetcher() {
|
| + fetcher_.reset();
|
| + j_callback_.Reset();
|
| +}
|
| +
|
| // static
|
| bool RegisterLogoBridge(JNIEnv* env) {
|
| return RegisterNativesImpl(env);
|
|
|