Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/android/compositor/scene_layer/contextual_search_scene_ layer.h" | 5 #include "chrome/browser/android/compositor/scene_layer/contextual_search_scene_ layer.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
| 9 #include "base/android/jni_string.h" | |
| 9 #include "cc/layers/solid_color_layer.h" | 10 #include "cc/layers/solid_color_layer.h" |
| 10 #include "chrome/browser/android/compositor/layer/contextual_search_layer.h" | 11 #include "chrome/browser/android/compositor/layer/contextual_search_layer.h" |
| 12 #include "chrome/browser/profiles/profile.h" | |
| 13 #include "chrome/browser/profiles/profile_android.h" | |
| 11 #include "content/public/browser/android/compositor.h" | 14 #include "content/public/browser/android/compositor.h" |
| 12 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 13 #include "jni/ContextualSearchSceneLayer_jni.h" | 16 #include "jni/ContextualSearchSceneLayer_jni.h" |
| 17 #include "net/base/load_flags.h" | |
| 18 #include "net/url_request/url_request_context_getter.h" | |
| 14 #include "ui/android/resources/resource_manager_impl.h" | 19 #include "ui/android/resources/resource_manager_impl.h" |
| 15 #include "ui/android/view_android.h" | 20 #include "ui/android/view_android.h" |
| 16 #include "ui/gfx/android/java_bitmap.h" | 21 #include "ui/gfx/android/java_bitmap.h" |
| 17 | 22 |
| 18 using base::android::JavaParamRef; | 23 using base::android::JavaParamRef; |
| 19 | 24 |
| 20 namespace chrome { | 25 namespace chrome { |
| 21 namespace android { | 26 namespace android { |
| 22 | 27 |
| 23 ContextualSearchSceneLayer::ContextualSearchSceneLayer(JNIEnv* env, | 28 ContextualSearchSceneLayer::ContextualSearchSceneLayer(JNIEnv* env, |
| 24 jobject jobj) | 29 jobject jobj) |
| 25 : SceneLayer(env, jobj), | 30 : SceneLayer(env, jobj), |
| 31 env_(env), | |
| 32 object_(env, jobj), | |
| 26 base_page_brightness_(1.0f), | 33 base_page_brightness_(1.0f), |
| 27 content_container_(cc::Layer::Create()) { | 34 content_container_(cc::Layer::Create()) { |
| 28 // Responsible for moving the base page without modifying the layer itself. | 35 // Responsible for moving the base page without modifying the layer itself. |
| 29 content_container_->SetIsDrawable(true); | 36 content_container_->SetIsDrawable(true); |
| 30 content_container_->SetPosition(gfx::PointF(0.0f, 0.0f)); | 37 content_container_->SetPosition(gfx::PointF(0.0f, 0.0f)); |
| 31 layer()->AddChild(content_container_); | 38 layer()->AddChild(content_container_); |
| 32 } | 39 } |
| 33 | 40 |
| 34 void ContextualSearchSceneLayer::CreateContextualSearchLayer( | 41 void ContextualSearchSceneLayer::CreateContextualSearchLayer( |
| 35 JNIEnv* env, | 42 JNIEnv* env, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 jfloat search_context_opacity, | 94 jfloat search_context_opacity, |
| 88 jfloat search_term_opacity, | 95 jfloat search_term_opacity, |
| 89 jfloat search_caption_animation_percentage, | 96 jfloat search_caption_animation_percentage, |
| 90 jboolean search_caption_visible, | 97 jboolean search_caption_visible, |
| 91 jboolean search_bar_border_visible, | 98 jboolean search_bar_border_visible, |
| 92 jfloat search_bar_border_height, | 99 jfloat search_bar_border_height, |
| 93 jboolean search_bar_shadow_visible, | 100 jboolean search_bar_shadow_visible, |
| 94 jfloat search_bar_shadow_opacity, | 101 jfloat search_bar_shadow_opacity, |
| 95 jboolean search_provider_icon_sprite_visible, | 102 jboolean search_provider_icon_sprite_visible, |
| 96 jfloat search_provider_icon_sprite_completion_percentage, | 103 jfloat search_provider_icon_sprite_completion_percentage, |
| 104 jboolean thumbnail_visible, | |
| 105 jint thumbnail_size, | |
| 106 jstring j_thumbnail_url, | |
| 97 jfloat arrow_icon_opacity, | 107 jfloat arrow_icon_opacity, |
| 98 jfloat arrow_icon_rotation, | 108 jfloat arrow_icon_rotation, |
| 99 jfloat close_icon_opacity, | 109 jfloat close_icon_opacity, |
| 100 jboolean progress_bar_visible, | 110 jboolean progress_bar_visible, |
| 101 jfloat progress_bar_height, | 111 jfloat progress_bar_height, |
| 102 jfloat progress_bar_opacity, | 112 jfloat progress_bar_opacity, |
| 103 jint progress_bar_completion) { | 113 jint progress_bar_completion, |
| 114 jobject j_profile) { | |
| 115 | |
| 116 // Load the thumbnail if necessary. | |
| 117 std::string thumbnail_url = | |
| 118 base::android::ConvertJavaStringToUTF8(env, j_thumbnail_url); | |
| 119 if (thumbnail_url.compare(thumbnail_url_) != 0) { | |
| 120 thumbnail_url_ = thumbnail_url; | |
| 121 FetchThumbnail(j_profile); | |
| 122 } | |
| 123 | |
| 104 // NOTE(pedrosimonetti): The WebContents might not exist at this time if | 124 // NOTE(pedrosimonetti): The WebContents might not exist at this time if |
| 105 // the Contextual Search Result has not been requested yet. In this case, | 125 // the Contextual Search Result has not been requested yet. In this case, |
| 106 // we'll pass NULL to Contextual Search's Layer Tree. | 126 // we'll pass NULL to Contextual Search's Layer Tree. |
| 107 content::WebContents* web_contents = | 127 content::WebContents* web_contents = |
| 108 content::WebContents::FromJavaWebContents(jweb_contents); | 128 content::WebContents::FromJavaWebContents(jweb_contents); |
| 109 | 129 |
| 110 scoped_refptr<cc::Layer> content_layer = | 130 scoped_refptr<cc::Layer> content_layer = |
| 111 web_contents ? web_contents->GetNativeView()->GetLayer() : nullptr; | 131 web_contents ? web_contents->GetNativeView()->GetLayer() : nullptr; |
| 112 | 132 |
| 113 // Fade the base page out. | 133 // Fade the base page out. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 search_context_opacity, | 179 search_context_opacity, |
| 160 search_term_opacity, | 180 search_term_opacity, |
| 161 search_caption_animation_percentage, | 181 search_caption_animation_percentage, |
| 162 search_caption_visible, | 182 search_caption_visible, |
| 163 search_bar_border_visible, | 183 search_bar_border_visible, |
| 164 search_bar_border_height, | 184 search_bar_border_height, |
| 165 search_bar_shadow_visible, | 185 search_bar_shadow_visible, |
| 166 search_bar_shadow_opacity, | 186 search_bar_shadow_opacity, |
| 167 search_provider_icon_sprite_visible, | 187 search_provider_icon_sprite_visible, |
| 168 search_provider_icon_sprite_completion_percentage, | 188 search_provider_icon_sprite_completion_percentage, |
| 189 thumbnail_visible, | |
| 190 thumbnail_size, | |
| 169 arrow_icon_opacity, | 191 arrow_icon_opacity, |
| 170 arrow_icon_rotation, | 192 arrow_icon_rotation, |
| 171 close_icon_opacity, | 193 close_icon_opacity, |
| 172 progress_bar_visible, | 194 progress_bar_visible, |
| 173 progress_bar_height, | 195 progress_bar_height, |
| 174 progress_bar_opacity, | 196 progress_bar_opacity, |
| 175 progress_bar_completion); | 197 progress_bar_completion); |
| 176 | 198 |
| 177 // Make the layer visible if it is not already. | 199 // Make the layer visible if it is not already. |
| 178 contextual_search_layer_->layer()->SetHideLayerAndSubtree(false); | 200 contextual_search_layer_->layer()->SetHideLayerAndSubtree(false); |
| 179 } | 201 } |
| 180 | 202 |
| 203 void ContextualSearchSceneLayer::FetchThumbnail(jobject j_profile) { | |
| 204 if (thumbnail_url_.compare("") == 0) return; | |
| 205 | |
| 206 GURL* gurl = new GURL(thumbnail_url_); | |
| 207 Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile); | |
| 208 chrome::BitmapFetcher* fetcher = new chrome::BitmapFetcher(*gurl, this); | |
|
mdjones
2016/09/08 17:14:21
Does BitmapFetcher delete itself when it is done?
Theresa
2016/09/08 20:18:23
I don't think so. Add an explicit call to the dest
| |
| 209 fetcher->Init( | |
| 210 profile->GetRequestContext(), | |
| 211 std::string(), | |
| 212 net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, | |
| 213 net::LOAD_NORMAL); | |
| 214 fetcher->Start(); | |
| 215 } | |
| 216 | |
| 217 void ContextualSearchSceneLayer::OnFetchComplete(const GURL& url, | |
| 218 const SkBitmap* bitmap) { | |
| 219 bool success = bitmap != NULL && !bitmap->drawsNothing(); | |
| 220 Java_ContextualSearchSceneLayer_onThumbnailFetched(env_, | |
| 221 object_.obj(), | |
| 222 success); | |
| 223 | |
| 224 contextual_search_layer_->SetThumbnail(bitmap); | |
|
Donn Denman
2016/09/08 18:13:39
Should this line be conditional on success?
Theresa
2016/09/08 20:18:23
Yes, done.
| |
| 225 } | |
| 226 | |
| 181 void ContextualSearchSceneLayer::SetContentTree( | 227 void ContextualSearchSceneLayer::SetContentTree( |
| 182 JNIEnv* env, | 228 JNIEnv* env, |
| 183 const JavaParamRef<jobject>& jobj, | 229 const JavaParamRef<jobject>& jobj, |
| 184 const JavaParamRef<jobject>& jcontent_tree) { | 230 const JavaParamRef<jobject>& jcontent_tree) { |
| 185 SceneLayer* content_tree = FromJavaObject(env, jcontent_tree); | 231 SceneLayer* content_tree = FromJavaObject(env, jcontent_tree); |
| 186 if (!content_tree || !content_tree->layer()) return; | 232 if (!content_tree || !content_tree->layer()) return; |
| 187 | 233 |
| 188 if (!content_tree->layer()->parent() | 234 if (!content_tree->layer()->parent() |
| 189 || (content_tree->layer()->parent()->id() != content_container_->id())) { | 235 || (content_tree->layer()->parent()->id() != content_container_->id())) { |
| 190 content_container_->AddChild(content_tree->layer()); | 236 content_container_->AddChild(content_tree->layer()); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 211 new ContextualSearchSceneLayer(env, jobj); | 257 new ContextualSearchSceneLayer(env, jobj); |
| 212 return reinterpret_cast<intptr_t>(tree_provider); | 258 return reinterpret_cast<intptr_t>(tree_provider); |
| 213 } | 259 } |
| 214 | 260 |
| 215 bool RegisterContextualSearchSceneLayer(JNIEnv* env) { | 261 bool RegisterContextualSearchSceneLayer(JNIEnv* env) { |
| 216 return RegisterNativesImpl(env); | 262 return RegisterNativesImpl(env); |
| 217 } | 263 } |
| 218 | 264 |
| 219 } // namespace android | 265 } // namespace android |
| 220 } // namespace chrome | 266 } // namespace chrome |
| OLD | NEW |