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

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: Fix the review comments and rebase the patch 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 14 matching lines...) Expand all
39 #include "chrome/common/url_constants.h" 40 #include "chrome/common/url_constants.h"
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"
50 #include "grit/ui_resources.h"
49 #include "jni/Tab_jni.h" 51 #include "jni/Tab_jni.h"
52 #include "skia/ext/image_operations.h"
50 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" 53 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
54 #include "ui/base/resource/resource_bundle.h"
51 #include "ui/base/window_open_disposition.h" 55 #include "ui/base/window_open_disposition.h"
56 #include "ui/gfx/android/device_display_info.h"
57 #include "ui/gfx/android/java_bitmap.h"
58 #include "ui/gfx/favicon_size.h"
59 #include "ui/gfx/image/image_skia.h"
52 60
53 using content::GlobalRequestID; 61 using content::GlobalRequestID;
54 using content::NavigationController; 62 using content::NavigationController;
55 using content::WebContents; 63 using content::WebContents;
56 64
57 namespace { 65 namespace {
58 66
59 WebContents* CreateTargetContents(const chrome::NavigateParams& params, 67 WebContents* CreateTargetContents(const chrome::NavigateParams& params,
60 const GURL& url) { 68 const GURL& url) {
61 Profile* profile = params.initiating_profile; 69 Profile* profile = params.initiating_profile;
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 printing::PrintViewManagerBasic::CreateForWebContents(web_contents()); 573 printing::PrintViewManagerBasic::CreateForWebContents(web_contents());
566 printing::PrintViewManagerBasic* print_view_manager = 574 printing::PrintViewManagerBasic* print_view_manager =
567 printing::PrintViewManagerBasic::FromWebContents(web_contents()); 575 printing::PrintViewManagerBasic::FromWebContents(web_contents());
568 if (print_view_manager == NULL) 576 if (print_view_manager == NULL)
569 return false; 577 return false;
570 578
571 print_view_manager->PrintNow(); 579 print_view_manager->PrintNow();
572 return true; 580 return true;
573 } 581 }
574 582
583 ScopedJavaLocalRef<jobject> TabAndroid::GetFavicon(JNIEnv* env, jobject obj) {
584 ScopedJavaLocalRef<jobject> bitmap;
585 FaviconTabHelper* favicon_tab_helper =
586 FaviconTabHelper::FromWebContents(web_contents_.get());
587
588 if (!favicon_tab_helper)
589 return bitmap;
590 if (!favicon_tab_helper->FaviconIsValid())
591 return bitmap;
592
593 SkBitmap favicon =
594 favicon_tab_helper->GetFavicon()
595 .AsImageSkia()
596 .GetRepresentation(
597 ResourceBundle::GetSharedInstance().GetMaxScaleFactor())
598 .sk_bitmap();
599
600 if (favicon.empty()) {
Jitu( very slow this week) 2014/08/01 11:35:50 If favicon is empty get the default favicon.
David Trainor- moved to gerrit 2014/08/08 20:48:57 Sorry for the communication issues. I meant, "Gra
601 gfx::Image image =
602 gfx::Image(*ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
603 IDR_DEFAULT_FAVICON));
604 favicon = image.AsBitmap();
605 }
606
607 if (!favicon.empty()) {
Jitu( very slow this week) 2014/08/01 11:35:50 If both default and favicon is not empty then scal
608 gfx::DeviceDisplayInfo device_info;
609 const float device_scale_factor = device_info.GetDIPScale();
610 int target_size_dip = device_scale_factor * gfx::kFaviconSize;
611 if (favicon.width() != target_size_dip ||
612 favicon.height() != target_size_dip) {
613 favicon =
614 skia::ImageOperations::Resize(favicon,
615 skia::ImageOperations::RESIZE_BEST,
616 target_size_dip,
617 target_size_dip);
618 }
619
620 bitmap = gfx::ConvertToJavaBitmap(&favicon);
621 }
622 return bitmap;
623 }
624
575 prerender::PrerenderManager* TabAndroid::GetPrerenderManager() const { 625 prerender::PrerenderManager* TabAndroid::GetPrerenderManager() const {
576 Profile* profile = GetProfile(); 626 Profile* profile = GetProfile();
577 if (!profile) 627 if (!profile)
578 return NULL; 628 return NULL;
579 return prerender::PrerenderManagerFactory::GetForProfile(profile); 629 return prerender::PrerenderManagerFactory::GetForProfile(profile);
580 } 630 }
581 631
582 static void Init(JNIEnv* env, jobject obj) { 632 static void Init(JNIEnv* env, jobject obj) {
583 TRACE_EVENT0("native", "TabAndroid::Init"); 633 TRACE_EVENT0("native", "TabAndroid::Init");
584 // This will automatically bind to the Java object and pass ownership there. 634 // This will automatically bind to the Java object and pass ownership there.
585 new TabAndroid(env, obj); 635 new TabAndroid(env, obj);
586 } 636 }
587 637
588 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { 638 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) {
589 return RegisterNativesImpl(env); 639 return RegisterNativesImpl(env);
590 } 640 }
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