Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(956)

Side by Side Diff: chrome/browser/android/tab_android.cc

Issue 364793005: Implementation of GetFavicon for current tab. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changed as per suggested Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/android/tab_android.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 15 matching lines...) Expand all
40 #include "components/google/core/browser/google_url_tracker.h" 41 #include "components/google/core/browser/google_url_tracker.h"
41 #include "components/google/core/browser/google_util.h" 42 #include "components/google/core/browser/google_util.h"
42 #include "components/infobars/core/infobar_container.h" 43 #include "components/infobars/core/infobar_container.h"
43 #include "components/url_fixer/url_fixer.h" 44 #include "components/url_fixer/url_fixer.h"
44 #include "content/public/browser/android/content_view_core.h" 45 #include "content/public/browser/android/content_view_core.h"
45 #include "content/public/browser/navigation_entry.h" 46 #include "content/public/browser/navigation_entry.h"
46 #include "content/public/browser/notification_service.h" 47 #include "content/public/browser/notification_service.h"
47 #include "content/public/browser/user_metrics.h" 48 #include "content/public/browser/user_metrics.h"
48 #include "content/public/browser/web_contents.h" 49 #include "content/public/browser/web_contents.h"
49 #include "jni/Tab_jni.h" 50 #include "jni/Tab_jni.h"
51 #include "skia/ext/image_operations.h"
50 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" 52 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
53 #include "ui/base/resource/resource_bundle.h"
51 #include "ui/base/window_open_disposition.h" 54 #include "ui/base/window_open_disposition.h"
55 #include "ui/gfx/android/device_display_info.h"
56 #include "ui/gfx/android/java_bitmap.h"
57 #include "ui/gfx/favicon_size.h"
58 #include "ui/gfx/image/image_skia.h"
52 59
53 using content::GlobalRequestID; 60 using content::GlobalRequestID;
54 using content::NavigationController; 61 using content::NavigationController;
55 using content::WebContents; 62 using content::WebContents;
56 63
57 namespace { 64 namespace {
58 65
59 WebContents* CreateTargetContents(const chrome::NavigateParams& params, 66 WebContents* CreateTargetContents(const chrome::NavigateParams& params,
60 const GURL& url) { 67 const GURL& url) {
61 Profile* profile = params.initiating_profile; 68 Profile* profile = params.initiating_profile;
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 printing::PrintViewManagerBasic::CreateForWebContents(web_contents()); 572 printing::PrintViewManagerBasic::CreateForWebContents(web_contents());
566 printing::PrintViewManagerBasic* print_view_manager = 573 printing::PrintViewManagerBasic* print_view_manager =
567 printing::PrintViewManagerBasic::FromWebContents(web_contents()); 574 printing::PrintViewManagerBasic::FromWebContents(web_contents());
568 if (print_view_manager == NULL) 575 if (print_view_manager == NULL)
569 return false; 576 return false;
570 577
571 print_view_manager->PrintNow(); 578 print_view_manager->PrintNow();
572 return true; 579 return true;
573 } 580 }
574 581
582 ScopedJavaLocalRef<jobject> TabAndroid::GetFavicon(JNIEnv* env, jobject obj) {
583 ScopedJavaLocalRef<jobject> bitmap;
584 FaviconTabHelper* favicon_tab_helper =
585 FaviconTabHelper::FromWebContents(web_contents_.get());
586
587 if (!favicon_tab_helper)
588 return bitmap;
589 if (!favicon_tab_helper->FaviconIsValid())
590 return bitmap;
591
592 SkBitmap favicon =
593 favicon_tab_helper->GetFavicon()
594 .AsImageSkia()
595 .GetRepresentation(
596 ResourceBundle::GetSharedInstance().GetMaxScaleFactor())
597 .sk_bitmap();
598
599 if (favicon.empty()) {
600 favicon = favicon_tab_helper->GetFavicon().AsBitmap();
601 }
602
603 if (!favicon.empty()) {
604 gfx::DeviceDisplayInfo device_info;
605 const float device_scale_factor = device_info.GetDIPScale();
606 int target_size_dip = device_scale_factor * gfx::kFaviconSize;
607 if (favicon.width() != target_size_dip ||
608 favicon.height() != target_size_dip) {
609 favicon =
610 skia::ImageOperations::Resize(favicon,
611 skia::ImageOperations::RESIZE_BEST,
612 target_size_dip,
613 target_size_dip);
614 }
615
616 bitmap = gfx::ConvertToJavaBitmap(&favicon);
617 }
618 return bitmap;
619 }
620
575 prerender::PrerenderManager* TabAndroid::GetPrerenderManager() const { 621 prerender::PrerenderManager* TabAndroid::GetPrerenderManager() const {
576 Profile* profile = GetProfile(); 622 Profile* profile = GetProfile();
577 if (!profile) 623 if (!profile)
578 return NULL; 624 return NULL;
579 return prerender::PrerenderManagerFactory::GetForProfile(profile); 625 return prerender::PrerenderManagerFactory::GetForProfile(profile);
580 } 626 }
581 627
582 static void Init(JNIEnv* env, jobject obj) { 628 static void Init(JNIEnv* env, jobject obj) {
583 TRACE_EVENT0("native", "TabAndroid::Init"); 629 TRACE_EVENT0("native", "TabAndroid::Init");
584 // This will automatically bind to the Java object and pass ownership there. 630 // This will automatically bind to the Java object and pass ownership there.
585 new TabAndroid(env, obj); 631 new TabAndroid(env, obj);
586 } 632 }
587 633
588 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { 634 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) {
589 return RegisterNativesImpl(env); 635 return RegisterNativesImpl(env);
590 } 636 }
OLDNEW
« no previous file with comments | « chrome/browser/android/tab_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698