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/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
11 #include "chrome/browser/android/chrome_web_contents_delegate_android.h" | 11 #include "chrome/browser/android/chrome_web_contents_delegate_android.h" |
12 #include "chrome/browser/browser_about_handler.h" | 12 #include "chrome/browser/browser_about_handler.h" |
13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
14 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 14 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
15 #include "chrome/browser/favicon/favicon_tab_helper.h" | |
15 #include "chrome/browser/google/google_url_tracker_factory.h" | 16 #include "chrome/browser/google/google_url_tracker_factory.h" |
16 #include "chrome/browser/infobars/infobar_service.h" | 17 #include "chrome/browser/infobars/infobar_service.h" |
17 #include "chrome/browser/prerender/prerender_contents.h" | 18 #include "chrome/browser/prerender/prerender_contents.h" |
18 #include "chrome/browser/prerender/prerender_manager.h" | 19 #include "chrome/browser/prerender/prerender_manager.h" |
19 #include "chrome/browser/prerender/prerender_manager_factory.h" | 20 #include "chrome/browser/prerender/prerender_manager_factory.h" |
20 #include "chrome/browser/printing/print_view_manager_basic.h" | 21 #include "chrome/browser/printing/print_view_manager_basic.h" |
21 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/browser/profiles/profile_android.h" | 23 #include "chrome/browser/profiles/profile_android.h" |
23 #include "chrome/browser/search/search.h" | 24 #include "chrome/browser/search/search.h" |
24 #include "chrome/browser/sessions/session_tab_helper.h" | 25 #include "chrome/browser/sessions/session_tab_helper.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
39 #include "components/google/core/browser/google_url_tracker.h" | 40 #include "components/google/core/browser/google_url_tracker.h" |
40 #include "components/google/core/browser/google_util.h" | 41 #include "components/google/core/browser/google_util.h" |
41 #include "components/infobars/core/infobar_container.h" | 42 #include "components/infobars/core/infobar_container.h" |
42 #include "components/url_fixer/url_fixer.h" | 43 #include "components/url_fixer/url_fixer.h" |
43 #include "content/public/browser/android/content_view_core.h" | 44 #include "content/public/browser/android/content_view_core.h" |
44 #include "content/public/browser/navigation_entry.h" | 45 #include "content/public/browser/navigation_entry.h" |
45 #include "content/public/browser/notification_service.h" | 46 #include "content/public/browser/notification_service.h" |
46 #include "content/public/browser/user_metrics.h" | 47 #include "content/public/browser/user_metrics.h" |
47 #include "content/public/browser/web_contents.h" | 48 #include "content/public/browser/web_contents.h" |
48 #include "jni/Tab_jni.h" | 49 #include "jni/Tab_jni.h" |
50 #include "skia/ext/image_operations.h" | |
49 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" | 51 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" |
52 #include "ui/base/resource/resource_bundle.h" | |
53 #include "ui/gfx/android/device_display_info.h" | |
54 #include "ui/gfx/android/java_bitmap.h" | |
55 #include "ui/gfx/favicon_size.h" | |
56 #include "ui/gfx/image/image_skia.h" | |
50 | 57 |
51 TabAndroid* TabAndroid::FromWebContents(content::WebContents* web_contents) { | 58 TabAndroid* TabAndroid::FromWebContents(content::WebContents* web_contents) { |
52 CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(web_contents); | 59 CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(web_contents); |
53 if (!core_tab_helper) | 60 if (!core_tab_helper) |
54 return NULL; | 61 return NULL; |
55 | 62 |
56 CoreTabHelperDelegate* core_delegate = core_tab_helper->delegate(); | 63 CoreTabHelperDelegate* core_delegate = core_tab_helper->delegate(); |
57 if (!core_delegate) | 64 if (!core_delegate) |
58 return NULL; | 65 return NULL; |
59 | 66 |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
504 printing::PrintViewManagerBasic::CreateForWebContents(web_contents()); | 511 printing::PrintViewManagerBasic::CreateForWebContents(web_contents()); |
505 printing::PrintViewManagerBasic* print_view_manager = | 512 printing::PrintViewManagerBasic* print_view_manager = |
506 printing::PrintViewManagerBasic::FromWebContents(web_contents()); | 513 printing::PrintViewManagerBasic::FromWebContents(web_contents()); |
507 if (print_view_manager == NULL) | 514 if (print_view_manager == NULL) |
508 return false; | 515 return false; |
509 | 516 |
510 print_view_manager->PrintNow(); | 517 print_view_manager->PrintNow(); |
511 return true; | 518 return true; |
512 } | 519 } |
513 | 520 |
521 ScopedJavaLocalRef<jobject> TabAndroid::GetFavicon(JNIEnv* env, jobject obj) { | |
522 ScopedJavaLocalRef<jobject> bitmap; | |
523 FaviconTabHelper* favicon_tab_helper = | |
524 FaviconTabHelper::FromWebContents(web_contents_.get()); | |
525 if (!favicon_tab_helper) | |
526 return bitmap; | |
527 if (!favicon_tab_helper->FaviconIsValid()) | |
528 return bitmap; | |
529 | |
530 SkBitmap favicon = | |
531 favicon_tab_helper->GetFavicon() | |
532 .AsImageSkia() | |
533 .GetRepresentation( | |
534 ResourceBundle::GetSharedInstance().GetMaxScaleFactor()) | |
535 .sk_bitmap(); | |
536 | |
537 if (!favicon.isNull()) { | |
538 gfx::DeviceDisplayInfo device_info; | |
539 const float device_scale_factor = device_info.GetDIPScale(); | |
540 int target_size_dip = device_scale_factor * gfx::kFaviconSize; | |
541 if (favicon.width() != target_size_dip || | |
542 favicon.height() != target_size_dip) { | |
543 favicon = | |
544 skia::ImageOperations::Resize(favicon, | |
545 skia::ImageOperations::RESIZE_BEST, | |
546 target_size_dip, | |
547 target_size_dip); | |
548 } | |
549 | |
550 } else { | |
551 gfx::Image image; | |
552 favicon = image.AsBitmap(); | |
David Trainor- moved to gerrit
2014/07/30 17:51:23
This is still an empty bitmap :(. We should be do
| |
553 } | |
554 bitmap = gfx::ConvertToJavaBitmap(&favicon); | |
555 return bitmap; | |
556 } | |
557 | |
514 prerender::PrerenderManager* TabAndroid::GetPrerenderManager() const { | 558 prerender::PrerenderManager* TabAndroid::GetPrerenderManager() const { |
515 Profile* profile = GetProfile(); | 559 Profile* profile = GetProfile(); |
516 if (!profile) | 560 if (!profile) |
517 return NULL; | 561 return NULL; |
518 return prerender::PrerenderManagerFactory::GetForProfile(profile); | 562 return prerender::PrerenderManagerFactory::GetForProfile(profile); |
519 } | 563 } |
520 | 564 |
521 static void Init(JNIEnv* env, jobject obj) { | 565 static void Init(JNIEnv* env, jobject obj) { |
522 TRACE_EVENT0("native", "TabAndroid::Init"); | 566 TRACE_EVENT0("native", "TabAndroid::Init"); |
523 // This will automatically bind to the Java object and pass ownership there. | 567 // This will automatically bind to the Java object and pass ownership there. |
524 new TabAndroid(env, obj); | 568 new TabAndroid(env, obj); |
525 } | 569 } |
526 | 570 |
527 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { | 571 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { |
528 return RegisterNativesImpl(env); | 572 return RegisterNativesImpl(env); |
529 } | 573 } |
OLD | NEW |