OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_android.h" | 5 #include "chrome/browser/android/tab_android.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 "base/android/jni_string.h" |
10 #include "base/base64.h" | |
10 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
11 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
12 #include "cc/layers/layer.h" | 13 #include "cc/layers/layer.h" |
13 #include "chrome/browser/android/chrome_web_contents_delegate_android.h" | 14 #include "chrome/browser/android/chrome_web_contents_delegate_android.h" |
14 #include "chrome/browser/android/compositor/tab_content_manager.h" | 15 #include "chrome/browser/android/compositor/tab_content_manager.h" |
15 #include "chrome/browser/android/metrics/uma_utils.h" | 16 #include "chrome/browser/android/metrics/uma_utils.h" |
16 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 17 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
17 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" | 18 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" |
18 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h" | 19 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h" |
19 #include "chrome/browser/browser_about_handler.h" | 20 #include "chrome/browser/browser_about_handler.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 #include "content/public/browser/web_contents.h" | 70 #include "content/public/browser/web_contents.h" |
70 #include "content/public/common/top_controls_state.h" | 71 #include "content/public/common/top_controls_state.h" |
71 #include "jni/Tab_jni.h" | 72 #include "jni/Tab_jni.h" |
72 #include "net/base/escape.h" | 73 #include "net/base/escape.h" |
73 #include "skia/ext/image_operations.h" | 74 #include "skia/ext/image_operations.h" |
74 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" | 75 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" |
75 #include "ui/base/resource/resource_bundle.h" | 76 #include "ui/base/resource/resource_bundle.h" |
76 #include "ui/base/window_open_disposition.h" | 77 #include "ui/base/window_open_disposition.h" |
77 #include "ui/gfx/android/device_display_info.h" | 78 #include "ui/gfx/android/device_display_info.h" |
78 #include "ui/gfx/android/java_bitmap.h" | 79 #include "ui/gfx/android/java_bitmap.h" |
80 #include "ui/gfx/codec/png_codec.h" | |
79 #include "ui/gfx/favicon_size.h" | 81 #include "ui/gfx/favicon_size.h" |
80 #include "ui/gfx/image/image_skia.h" | 82 #include "ui/gfx/image/image_skia.h" |
81 | 83 |
82 using base::android::AttachCurrentThread; | 84 using base::android::AttachCurrentThread; |
83 using base::android::ConvertUTF8ToJavaString; | 85 using base::android::ConvertUTF8ToJavaString; |
84 using base::android::ToJavaByteArray; | 86 using base::android::ToJavaByteArray; |
85 using content::BrowserThread; | 87 using content::BrowserThread; |
86 using content::GlobalRequestID; | 88 using content::GlobalRequestID; |
87 using content::NavigationController; | 89 using content::NavigationController; |
88 using content::WebContents; | 90 using content::WebContents; |
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
680 skia::ImageOperations::RESIZE_BEST, | 682 skia::ImageOperations::RESIZE_BEST, |
681 target_size_dip, | 683 target_size_dip, |
682 target_size_dip); | 684 target_size_dip); |
683 } | 685 } |
684 | 686 |
685 bitmap = gfx::ConvertToJavaBitmap(&favicon); | 687 bitmap = gfx::ConvertToJavaBitmap(&favicon); |
686 } | 688 } |
687 return bitmap; | 689 return bitmap; |
688 } | 690 } |
689 | 691 |
692 GURL TabAndroid::GetFaviconURL() { | |
693 JNIEnv* env = base::android::AttachCurrentThread(); | |
694 ScopedJavaLocalRef<jobject> javaBitmap = | |
695 Java_Tab_getFavicon(env, weak_java_tab_.get(env).obj()); | |
696 if (!javaBitmap.obj()) | |
697 return GURL(); | |
698 | |
699 SkBitmap bitmap = gfx::CreateSkBitmapFromJavaBitmap( | |
700 gfx::JavaBitmap(javaBitmap.obj())); | |
701 std::vector<unsigned char> data; | |
702 SkAutoLockPixels lock_image(bitmap); | |
703 bool encoded = gfx::PNGCodec::Encode( | |
704 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), | |
705 gfx::PNGCodec::FORMAT_SkBitmap, | |
706 gfx::Size(bitmap.width(), bitmap.height()), | |
707 bitmap.width() * bitmap.bytesPerPixel(), | |
708 false, std::vector<gfx::PNGCodec::Comment>(), &data); | |
709 if (!encoded) | |
710 return GURL(); | |
711 | |
712 std::string base_64_data; | |
713 base::Base64Encode( | |
714 base::StringPiece(reinterpret_cast<char*>(&data[0]), data.size()), | |
715 &base_64_data); | |
716 return GURL("data:image/png;base64," + base_64_data); | |
michaelbai
2015/05/08 15:25:42
Should the png and URL encoding be in dev_tools_di
vkuzkokov
2015/05/12 12:16:46
Moved.
| |
717 } | |
718 | |
690 prerender::PrerenderManager* TabAndroid::GetPrerenderManager() const { | 719 prerender::PrerenderManager* TabAndroid::GetPrerenderManager() const { |
691 Profile* profile = GetProfile(); | 720 Profile* profile = GetProfile(); |
692 if (!profile) | 721 if (!profile) |
693 return NULL; | 722 return NULL; |
694 return prerender::PrerenderManagerFactory::GetForProfile(profile); | 723 return prerender::PrerenderManagerFactory::GetForProfile(profile); |
695 } | 724 } |
696 | 725 |
697 // static | 726 // static |
698 void TabAndroid::CreateHistoricalTabFromContents(WebContents* web_contents) { | 727 void TabAndroid::CreateHistoricalTabFromContents(WebContents* web_contents) { |
699 DCHECK(web_contents); | 728 DCHECK(web_contents); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
870 // s^{n+1} / s^{n} = 2100 / 2000 | 899 // s^{n+1} / s^{n} = 2100 / 2000 |
871 // s = 1.05 | 900 // s = 1.05 |
872 // s^b = 60000 | 901 // s^b = 60000 |
873 // b = ln(60000) / ln(1.05) ~= 225 | 902 // b = ln(60000) / ln(1.05) ~= 225 |
874 UMA_HISTOGRAM_CUSTOM_TIMES("Startup.FirstCommitNavigationTime", | 903 UMA_HISTOGRAM_CUSTOM_TIMES("Startup.FirstCommitNavigationTime", |
875 base::Time::Now() - chrome::android::GetMainEntryPointTime(), | 904 base::Time::Now() - chrome::android::GetMainEntryPointTime(), |
876 base::TimeDelta::FromMilliseconds(1), | 905 base::TimeDelta::FromMilliseconds(1), |
877 base::TimeDelta::FromMinutes(1), | 906 base::TimeDelta::FromMinutes(1), |
878 225); | 907 225); |
879 } | 908 } |
OLD | NEW |