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/tab/thumbnail_tab_helper_android.h" | 5 #include "chrome/browser/android/tab/thumbnail_tab_helper_android.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "chrome/browser/history/top_sites_factory.h" | 10 #include "chrome/browser/history/top_sites_factory.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "ui/gfx/color_utils.h" | 21 #include "ui/gfx/color_utils.h" |
22 #include "ui/gfx/image/image_skia.h" | 22 #include "ui/gfx/image/image_skia.h" |
23 #include "url/gurl.h" | 23 #include "url/gurl.h" |
24 | 24 |
25 // static | 25 // static |
26 bool RegisterThumbnailTabHelperAndroid(JNIEnv* env) { | 26 bool RegisterThumbnailTabHelperAndroid(JNIEnv* env) { |
27 return RegisterNativesImpl(env); | 27 return RegisterNativesImpl(env); |
28 } | 28 } |
29 | 29 |
30 static void InitThumbnailHelper(JNIEnv* env, | 30 static void InitThumbnailHelper(JNIEnv* env, |
31 jclass clazz, | 31 const JavaParamRef<jclass>& clazz, |
32 jobject jweb_contents) { | 32 const JavaParamRef<jobject>& jweb_contents) { |
33 content::WebContents* web_contents = | 33 content::WebContents* web_contents = |
34 content::WebContents::FromJavaWebContents(jweb_contents); | 34 content::WebContents::FromJavaWebContents(jweb_contents); |
35 DCHECK(web_contents); | 35 DCHECK(web_contents); |
36 | 36 |
37 // Don't allow ThumbnailTabHelper to take thumbnail snapshots. | 37 // Don't allow ThumbnailTabHelper to take thumbnail snapshots. |
38 // Currently the process is driven from Tab, but long term will | 38 // Currently the process is driven from Tab, but long term will |
39 // move into a Android specific tab helper. | 39 // move into a Android specific tab helper. |
40 // Bug: crbug.com/157431 | 40 // Bug: crbug.com/157431 |
41 ThumbnailTabHelper* thumbnail_tab_helper = | 41 ThumbnailTabHelper* thumbnail_tab_helper = |
42 ThumbnailTabHelper::FromWebContents(web_contents); | 42 ThumbnailTabHelper::FromWebContents(web_contents); |
43 if (thumbnail_tab_helper) | 43 if (thumbnail_tab_helper) |
44 thumbnail_tab_helper->set_enabled(false); | 44 thumbnail_tab_helper->set_enabled(false); |
45 } | 45 } |
46 | 46 |
47 static jboolean ShouldUpdateThumbnail( | 47 static jboolean ShouldUpdateThumbnail(JNIEnv* env, |
48 JNIEnv* env, jclass clazz, jobject jprofile, jstring jurl) { | 48 const JavaParamRef<jclass>& clazz, |
| 49 const JavaParamRef<jobject>& jprofile, |
| 50 const JavaParamRef<jstring>& jurl) { |
49 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); | 51 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); |
50 | 52 |
51 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); | 53 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); |
52 scoped_refptr<thumbnails::ThumbnailService> thumbnail_service = | 54 scoped_refptr<thumbnails::ThumbnailService> thumbnail_service = |
53 ThumbnailServiceFactory::GetForProfile(profile); | 55 ThumbnailServiceFactory::GetForProfile(profile); |
54 return (thumbnail_service.get() != NULL && | 56 return (thumbnail_service.get() != NULL && |
55 thumbnail_service->ShouldAcquirePageThumbnail(url)); | 57 thumbnail_service->ShouldAcquirePageThumbnail(url)); |
56 } | 58 } |
57 | 59 |
58 static void UpdateThumbnail(JNIEnv* env, | 60 static void UpdateThumbnail(JNIEnv* env, |
59 jclass clazz, | 61 const JavaParamRef<jclass>& clazz, |
60 jobject jweb_contents, | 62 const JavaParamRef<jobject>& jweb_contents, |
61 jobject bitmap, | 63 const JavaParamRef<jobject>& bitmap, |
62 jboolean jat_top) { | 64 jboolean jat_top) { |
63 content::WebContents* web_contents = | 65 content::WebContents* web_contents = |
64 content::WebContents::FromJavaWebContents(jweb_contents); | 66 content::WebContents::FromJavaWebContents(jweb_contents); |
65 DCHECK(web_contents); | 67 DCHECK(web_contents); |
66 | 68 |
67 Profile* profile = Profile::FromBrowserContext( | 69 Profile* profile = Profile::FromBrowserContext( |
68 web_contents->GetBrowserContext()); | 70 web_contents->GetBrowserContext()); |
69 | 71 |
70 gfx::JavaBitmap bitmap_lock(bitmap); | 72 gfx::JavaBitmap bitmap_lock(bitmap); |
71 SkBitmap sk_bitmap; | 73 SkBitmap sk_bitmap; |
(...skipping 17 matching lines...) Expand all Loading... |
89 ThumbnailScore score; | 91 ThumbnailScore score; |
90 score.at_top = jat_top; | 92 score.at_top = jat_top; |
91 score.boring_score = color_utils::CalculateBoringScore(sk_bitmap); | 93 score.boring_score = color_utils::CalculateBoringScore(sk_bitmap); |
92 score.good_clipping = true; | 94 score.good_clipping = true; |
93 score.load_completed = !web_contents->IsLoading(); | 95 score.load_completed = !web_contents->IsLoading(); |
94 | 96 |
95 gfx::Image image = gfx::Image::CreateFrom1xBitmap(sk_bitmap); | 97 gfx::Image image = gfx::Image::CreateFrom1xBitmap(sk_bitmap); |
96 const GURL& url = web_contents->GetURL(); | 98 const GURL& url = web_contents->GetURL(); |
97 ts->SetPageThumbnail(url, image, score); | 99 ts->SetPageThumbnail(url, image, score); |
98 } | 100 } |
OLD | NEW |