Move Webstore URL concepts to //extensions and out
[chromium-blink-merge.git] / chrome / browser / android / tab_android.cc
blobe56e5e949b40b243d0096184319dbe7ae2f5de54
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
3 // found in the LICENSE file.
5 #include "chrome/browser/android/tab_android.h"
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_array.h"
9 #include "base/android/jni_string.h"
10 #include "base/debug/trace_event.h"
11 #include "chrome/browser/android/chrome_web_contents_delegate_android.h"
12 #include "chrome/browser/browser_about_handler.h"
13 #include "chrome/browser/chrome_notification_types.h"
14 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
15 #include "chrome/browser/favicon/favicon_tab_helper.h"
16 #include "chrome/browser/google/google_url_tracker_factory.h"
17 #include "chrome/browser/infobars/infobar_service.h"
18 #include "chrome/browser/prerender/prerender_contents.h"
19 #include "chrome/browser/prerender/prerender_manager.h"
20 #include "chrome/browser/prerender/prerender_manager_factory.h"
21 #include "chrome/browser/printing/print_view_manager_basic.h"
22 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/profiles/profile_android.h"
24 #include "chrome/browser/search/search.h"
25 #include "chrome/browser/sessions/session_tab_helper.h"
26 #include "chrome/browser/sync/glue/synced_tab_delegate_android.h"
27 #include "chrome/browser/tab_contents/tab_util.h"
28 #include "chrome/browser/ui/android/content_settings/popup_blocked_infobar_delegate.h"
29 #include "chrome/browser/ui/android/context_menu_helper.h"
30 #include "chrome/browser/ui/android/infobars/infobar_container_android.h"
31 #include "chrome/browser/ui/android/tab_model/tab_model.h"
32 #include "chrome/browser/ui/android/tab_model/tab_model_list.h"
33 #include "chrome/browser/ui/android/window_android_helper.h"
34 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
35 #include "chrome/browser/ui/search/instant_search_prerenderer.h"
36 #include "chrome/browser/ui/search/search_tab_helper.h"
37 #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
38 #include "chrome/browser/ui/tab_helpers.h"
39 #include "chrome/browser/ui/toolbar/toolbar_model_impl.h"
40 #include "chrome/common/url_constants.h"
41 #include "components/google/core/browser/google_url_tracker.h"
42 #include "components/google/core/browser/google_util.h"
43 #include "components/infobars/core/infobar_container.h"
44 #include "components/url_fixer/url_fixer.h"
45 #include "content/public/browser/android/content_view_core.h"
46 #include "content/public/browser/navigation_entry.h"
47 #include "content/public/browser/notification_service.h"
48 #include "content/public/browser/user_metrics.h"
49 #include "content/public/browser/web_contents.h"
50 #include "jni/Tab_jni.h"
51 #include "skia/ext/image_operations.h"
52 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
53 #include "ui/base/resource/resource_bundle.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"
60 using content::GlobalRequestID;
61 using content::NavigationController;
62 using content::WebContents;
64 namespace {
66 WebContents* CreateTargetContents(const chrome::NavigateParams& params,
67 const GURL& url) {
68 Profile* profile = params.initiating_profile;
70 if (profile->IsOffTheRecord() || params.disposition == OFF_THE_RECORD) {
71 profile = profile->GetOffTheRecordProfile();
73 WebContents::CreateParams create_params(
74 profile, tab_util::GetSiteInstanceForNewTab(profile, url));
75 if (params.source_contents) {
76 create_params.initial_size =
77 params.source_contents->GetContainerBounds().size();
78 if (params.should_set_opener)
79 create_params.opener = params.source_contents;
81 if (params.disposition == NEW_BACKGROUND_TAB)
82 create_params.initially_hidden = true;
84 WebContents* target_contents = WebContents::Create(create_params);
86 return target_contents;
89 bool MaybeSwapWithPrerender(const GURL& url, chrome::NavigateParams* params) {
90 Profile* profile =
91 Profile::FromBrowserContext(params->target_contents->GetBrowserContext());
93 prerender::PrerenderManager* prerender_manager =
94 prerender::PrerenderManagerFactory::GetForProfile(profile);
95 if (!prerender_manager)
96 return false;
97 return prerender_manager->MaybeUsePrerenderedPage(url, params);
100 } // namespace
102 TabAndroid* TabAndroid::FromWebContents(content::WebContents* web_contents) {
103 CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(web_contents);
104 if (!core_tab_helper)
105 return NULL;
107 CoreTabHelperDelegate* core_delegate = core_tab_helper->delegate();
108 if (!core_delegate)
109 return NULL;
111 return static_cast<TabAndroid*>(core_delegate);
114 TabAndroid* TabAndroid::GetNativeTab(JNIEnv* env, jobject obj) {
115 return reinterpret_cast<TabAndroid*>(Java_Tab_getNativePtr(env, obj));
118 void TabAndroid::AttachTabHelpers(content::WebContents* web_contents) {
119 DCHECK(web_contents);
121 TabHelpers::AttachTabHelpers(web_contents);
124 TabAndroid::TabAndroid(JNIEnv* env, jobject obj)
125 : weak_java_tab_(env, obj),
126 synced_tab_delegate_(new browser_sync::SyncedTabDelegateAndroid(this)) {
127 Java_Tab_setNativePtr(env, obj, reinterpret_cast<intptr_t>(this));
130 TabAndroid::~TabAndroid() {
131 JNIEnv* env = base::android::AttachCurrentThread();
132 Java_Tab_clearNativePtr(env, weak_java_tab_.get(env).obj());
135 base::android::ScopedJavaLocalRef<jobject> TabAndroid::GetJavaObject() {
136 JNIEnv* env = base::android::AttachCurrentThread();
137 return weak_java_tab_.get(env);
140 int TabAndroid::GetAndroidId() const {
141 JNIEnv* env = base::android::AttachCurrentThread();
142 return Java_Tab_getId(env, weak_java_tab_.get(env).obj());
145 int TabAndroid::GetSyncId() const {
146 JNIEnv* env = base::android::AttachCurrentThread();
147 return Java_Tab_getSyncId(env, weak_java_tab_.get(env).obj());
150 base::string16 TabAndroid::GetTitle() const {
151 JNIEnv* env = base::android::AttachCurrentThread();
152 return base::android::ConvertJavaStringToUTF16(
153 Java_Tab_getTitle(env, weak_java_tab_.get(env).obj()));
156 GURL TabAndroid::GetURL() const {
157 JNIEnv* env = base::android::AttachCurrentThread();
158 return GURL(base::android::ConvertJavaStringToUTF8(
159 Java_Tab_getUrl(env, weak_java_tab_.get(env).obj())));
162 bool TabAndroid::LoadIfNeeded() {
163 JNIEnv* env = base::android::AttachCurrentThread();
164 return Java_Tab_loadIfNeeded(env, weak_java_tab_.get(env).obj());
167 content::ContentViewCore* TabAndroid::GetContentViewCore() const {
168 if (!web_contents())
169 return NULL;
171 return content::ContentViewCore::FromWebContents(web_contents());
174 Profile* TabAndroid::GetProfile() const {
175 if (!web_contents())
176 return NULL;
178 return Profile::FromBrowserContext(web_contents()->GetBrowserContext());
181 browser_sync::SyncedTabDelegate* TabAndroid::GetSyncedTabDelegate() const {
182 return synced_tab_delegate_.get();
185 void TabAndroid::SetWindowSessionID(SessionID::id_type window_id) {
186 session_window_id_.set_id(window_id);
188 if (!web_contents())
189 return;
191 SessionTabHelper* session_tab_helper =
192 SessionTabHelper::FromWebContents(web_contents());
193 session_tab_helper->SetWindowID(session_window_id_);
196 void TabAndroid::SetSyncId(int sync_id) {
197 JNIEnv* env = base::android::AttachCurrentThread();
198 Java_Tab_setSyncId(env, weak_java_tab_.get(env).obj(), sync_id);
201 void TabAndroid::HandlePopupNavigation(chrome::NavigateParams* params) {
202 if (params->disposition != SUPPRESS_OPEN &&
203 params->disposition != SAVE_TO_DISK &&
204 params->disposition != IGNORE_ACTION) {
205 if (!params->url.is_empty()) {
206 bool was_blocked = false;
207 GURL url(params->url);
208 if (params->disposition == CURRENT_TAB) {
209 params->target_contents = web_contents_.get();
210 if (!MaybeSwapWithPrerender(url, params)) {
211 NavigationController::LoadURLParams load_url_params(url);
212 MakeLoadURLParams(params, &load_url_params);
213 params->target_contents->GetController().LoadURLWithParams(
214 load_url_params);
216 } else {
217 params->target_contents = CreateTargetContents(*params, url);
218 NavigationController::LoadURLParams load_url_params(url);
219 MakeLoadURLParams(params, &load_url_params);
220 params->target_contents->GetController().LoadURLWithParams(
221 load_url_params);
222 web_contents_delegate_->AddNewContents(params->source_contents,
223 params->target_contents,
224 params->disposition,
225 params->window_bounds,
226 params->user_gesture,
227 &was_blocked);
228 if (was_blocked)
229 params->target_contents = NULL;
235 bool TabAndroid::ShouldWelcomePageLinkToTermsOfService() {
236 NOTIMPLEMENTED();
237 return false;
240 bool TabAndroid::HasPrerenderedUrl(GURL gurl) {
241 prerender::PrerenderManager* prerender_manager = GetPrerenderManager();
242 if (!prerender_manager)
243 return false;
245 std::vector<content::WebContents*> contents =
246 prerender_manager->GetAllPrerenderingContents();
247 prerender::PrerenderContents* prerender_contents;
248 for (size_t i = 0; i < contents.size(); ++i) {
249 prerender_contents = prerender_manager->
250 GetPrerenderContents(contents.at(i));
251 if (prerender_contents->prerender_url() == gurl &&
252 prerender_contents->has_finished_loading()) {
253 return true;
256 return false;
259 void TabAndroid::MakeLoadURLParams(
260 chrome::NavigateParams* params,
261 NavigationController::LoadURLParams* load_url_params) {
262 load_url_params->referrer = params->referrer;
263 load_url_params->frame_tree_node_id = params->frame_tree_node_id;
264 load_url_params->redirect_chain = params->redirect_chain;
265 load_url_params->transition_type = params->transition;
266 load_url_params->extra_headers = params->extra_headers;
267 load_url_params->should_replace_current_entry =
268 params->should_replace_current_entry;
270 if (params->transferred_global_request_id != GlobalRequestID()) {
271 load_url_params->transferred_global_request_id =
272 params->transferred_global_request_id;
274 load_url_params->is_renderer_initiated = params->is_renderer_initiated;
276 // Only allows the browser-initiated navigation to use POST.
277 if (params->uses_post && !params->is_renderer_initiated) {
278 load_url_params->load_type =
279 NavigationController::LOAD_TYPE_BROWSER_INITIATED_HTTP_POST;
280 load_url_params->browser_initiated_post_data =
281 params->browser_initiated_post_data;
285 void TabAndroid::SwapTabContents(content::WebContents* old_contents,
286 content::WebContents* new_contents,
287 bool did_start_load,
288 bool did_finish_load) {
289 JNIEnv* env = base::android::AttachCurrentThread();
291 // We need to notify the native InfobarContainer so infobars can be swapped.
292 InfoBarContainerAndroid* infobar_container =
293 reinterpret_cast<InfoBarContainerAndroid*>(
294 Java_Tab_getNativeInfoBarContainer(
295 env,
296 weak_java_tab_.get(env).obj()));
297 InfoBarService* new_infobar_service =
298 new_contents ? InfoBarService::FromWebContents(new_contents) : NULL;
299 infobar_container->ChangeInfoBarManager(new_infobar_service);
301 Java_Tab_swapWebContents(
302 env,
303 weak_java_tab_.get(env).obj(),
304 reinterpret_cast<intptr_t>(new_contents),
305 did_start_load,
306 did_finish_load);
309 void TabAndroid::OnWebContentsInstantSupportDisabled(
310 const content::WebContents* contents) {
311 DCHECK(contents);
312 if (web_contents() != contents)
313 return;
315 JNIEnv* env = base::android::AttachCurrentThread();
316 Java_Tab_onWebContentsInstantSupportDisabled(env,
317 weak_java_tab_.get(env).obj());
320 void TabAndroid::Observe(int type,
321 const content::NotificationSource& source,
322 const content::NotificationDetails& details) {
323 JNIEnv* env = base::android::AttachCurrentThread();
324 switch (type) {
325 case chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED: {
326 TabSpecificContentSettings* settings =
327 TabSpecificContentSettings::FromWebContents(web_contents());
328 if (!settings->IsBlockageIndicated(CONTENT_SETTINGS_TYPE_POPUPS)) {
329 // TODO(dfalcantara): Create an InfoBarDelegate to keep the
330 // PopupBlockedInfoBar logic native-side instead of straddling the JNI
331 // boundary.
332 int num_popups = 0;
333 PopupBlockerTabHelper* popup_blocker_helper =
334 PopupBlockerTabHelper::FromWebContents(web_contents());
335 if (popup_blocker_helper)
336 num_popups = popup_blocker_helper->GetBlockedPopupsCount();
338 if (num_popups > 0)
339 PopupBlockedInfoBarDelegate::Create(web_contents(), num_popups);
341 settings->SetBlockageHasBeenIndicated(CONTENT_SETTINGS_TYPE_POPUPS);
343 break;
345 case chrome::NOTIFICATION_FAVICON_UPDATED:
346 Java_Tab_onFaviconUpdated(env, weak_java_tab_.get(env).obj());
347 break;
348 case content::NOTIFICATION_NAV_ENTRY_CHANGED:
349 Java_Tab_onNavEntryChanged(env, weak_java_tab_.get(env).obj());
350 break;
351 default:
352 NOTREACHED() << "Unexpected notification " << type;
353 break;
357 void TabAndroid::Destroy(JNIEnv* env, jobject obj) {
358 delete this;
361 void TabAndroid::InitWebContents(JNIEnv* env,
362 jobject obj,
363 jboolean incognito,
364 jobject jcontent_view_core,
365 jobject jweb_contents_delegate,
366 jobject jcontext_menu_populator) {
367 content::ContentViewCore* content_view_core =
368 content::ContentViewCore::GetNativeContentViewCore(env,
369 jcontent_view_core);
370 DCHECK(content_view_core);
371 DCHECK(content_view_core->GetWebContents());
373 web_contents_.reset(content_view_core->GetWebContents());
374 AttachTabHelpers(web_contents_.get());
376 SetWindowSessionID(session_window_id_.id());
378 session_tab_id_.set_id(
379 SessionTabHelper::FromWebContents(web_contents())->session_id().id());
380 ContextMenuHelper::FromWebContents(web_contents())->SetPopulator(
381 jcontext_menu_populator);
382 WindowAndroidHelper::FromWebContents(web_contents())->
383 SetWindowAndroid(content_view_core->GetWindowAndroid());
384 CoreTabHelper::FromWebContents(web_contents())->set_delegate(this);
385 SearchTabHelper::FromWebContents(web_contents())->set_delegate(this);
386 web_contents_delegate_.reset(
387 new chrome::android::ChromeWebContentsDelegateAndroid(
388 env, jweb_contents_delegate));
389 web_contents_delegate_->LoadProgressChanged(web_contents(), 0);
390 web_contents()->SetDelegate(web_contents_delegate_.get());
392 notification_registrar_.Add(
393 this,
394 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED,
395 content::Source<content::WebContents>(web_contents()));
396 notification_registrar_.Add(
397 this,
398 chrome::NOTIFICATION_FAVICON_UPDATED,
399 content::Source<content::WebContents>(web_contents()));
400 notification_registrar_.Add(
401 this,
402 content::NOTIFICATION_NAV_ENTRY_CHANGED,
403 content::Source<content::NavigationController>(
404 &web_contents()->GetController()));
406 synced_tab_delegate_->SetWebContents(web_contents());
408 // Verify that the WebContents this tab represents matches the expected
409 // off the record state.
410 CHECK_EQ(GetProfile()->IsOffTheRecord(), incognito);
413 void TabAndroid::DestroyWebContents(JNIEnv* env,
414 jobject obj,
415 jboolean delete_native) {
416 DCHECK(web_contents());
418 notification_registrar_.Remove(
419 this,
420 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED,
421 content::Source<content::WebContents>(web_contents()));
422 notification_registrar_.Remove(
423 this,
424 chrome::NOTIFICATION_FAVICON_UPDATED,
425 content::Source<content::WebContents>(web_contents()));
426 notification_registrar_.Remove(
427 this,
428 content::NOTIFICATION_NAV_ENTRY_CHANGED,
429 content::Source<content::NavigationController>(
430 &web_contents()->GetController()));
432 web_contents()->SetDelegate(NULL);
434 if (delete_native) {
435 web_contents_.reset();
436 synced_tab_delegate_->ResetWebContents();
437 } else {
438 // Release the WebContents so it does not get deleted by the scoped_ptr.
439 ignore_result(web_contents_.release());
443 base::android::ScopedJavaLocalRef<jobject> TabAndroid::GetProfileAndroid(
444 JNIEnv* env,
445 jobject obj) {
446 Profile* profile = GetProfile();
447 if (!profile)
448 return base::android::ScopedJavaLocalRef<jobject>();
449 ProfileAndroid* profile_android = ProfileAndroid::FromProfile(profile);
450 if (!profile_android)
451 return base::android::ScopedJavaLocalRef<jobject>();
453 return profile_android->GetJavaObject();
456 TabAndroid::TabLoadStatus TabAndroid::LoadUrl(JNIEnv* env,
457 jobject obj,
458 jstring url,
459 jstring j_extra_headers,
460 jbyteArray j_post_data,
461 jint page_transition,
462 jstring j_referrer_url,
463 jint referrer_policy,
464 jboolean is_renderer_initiated) {
465 if (!web_contents())
466 return PAGE_LOAD_FAILED;
468 GURL gurl(base::android::ConvertJavaStringToUTF8(env, url));
469 if (gurl.is_empty())
470 return PAGE_LOAD_FAILED;
472 // If the page was prerendered, use it.
473 // Note in incognito mode, we don't have a PrerenderManager.
475 prerender::PrerenderManager* prerender_manager =
476 prerender::PrerenderManagerFactory::GetForProfile(GetProfile());
477 if (prerender_manager) {
478 bool prefetched_page_loaded = HasPrerenderedUrl(gurl);
479 // Getting the load status before MaybeUsePrerenderedPage() b/c it resets.
480 chrome::NavigateParams params(NULL, web_contents());
481 InstantSearchPrerenderer* prerenderer =
482 InstantSearchPrerenderer::GetForProfile(GetProfile());
483 if (prerenderer) {
484 const base::string16& search_terms =
485 chrome::ExtractSearchTermsFromURL(GetProfile(), gurl);
486 if (!search_terms.empty() &&
487 prerenderer->CanCommitQuery(web_contents_.get(), search_terms)) {
488 prerenderer->Commit(search_terms);
490 if (prerenderer->UsePrerenderedPage(gurl, &params))
491 return FULL_PRERENDERED_PAGE_LOAD;
493 prerenderer->Cancel();
495 if (prerender_manager->MaybeUsePrerenderedPage(gurl, &params)) {
496 return prefetched_page_loaded ?
497 FULL_PRERENDERED_PAGE_LOAD : PARTIAL_PRERENDERED_PAGE_LOAD;
501 GURL fixed_url(
502 url_fixer::FixupURL(gurl.possibly_invalid_spec(), std::string()));
503 if (!fixed_url.is_valid())
504 return PAGE_LOAD_FAILED;
506 if (!HandleNonNavigationAboutURL(fixed_url)) {
507 // Notify the GoogleURLTracker of searches, it might want to change the
508 // actual Google site used (for instance when in the UK, google.co.uk, when
509 // in the US google.com).
510 // Note that this needs to happen before we initiate the navigation as the
511 // GoogleURLTracker uses the navigation pending notification to trigger the
512 // infobar.
513 if (google_util::IsGoogleSearchUrl(fixed_url) &&
514 (page_transition & content::PAGE_TRANSITION_GENERATED)) {
515 GoogleURLTracker* tracker =
516 GoogleURLTrackerFactory::GetForProfile(GetProfile());
517 if (tracker)
518 tracker->SearchCommitted();
521 // Record UMA "ShowHistory" here. That way it'll pick up both user
522 // typing chrome://history as well as selecting from the drop down menu.
523 if (fixed_url.spec() == chrome::kChromeUIHistoryURL) {
524 content::RecordAction(base::UserMetricsAction("ShowHistory"));
527 content::NavigationController::LoadURLParams load_params(fixed_url);
528 if (j_extra_headers) {
529 load_params.extra_headers = base::android::ConvertJavaStringToUTF8(
530 env,
531 j_extra_headers);
533 if (j_post_data) {
534 load_params.load_type =
535 content::NavigationController::LOAD_TYPE_BROWSER_INITIATED_HTTP_POST;
536 std::vector<uint8> post_data;
537 base::android::JavaByteArrayToByteVector(env, j_post_data, &post_data);
538 load_params.browser_initiated_post_data =
539 base::RefCountedBytes::TakeVector(&post_data);
541 load_params.transition_type =
542 content::PageTransitionFromInt(page_transition);
543 if (j_referrer_url) {
544 load_params.referrer = content::Referrer(
545 GURL(base::android::ConvertJavaStringToUTF8(env, j_referrer_url)),
546 static_cast<blink::WebReferrerPolicy>(referrer_policy));
548 const base::string16 search_terms =
549 chrome::ExtractSearchTermsFromURL(GetProfile(), gurl);
550 SearchTabHelper* search_tab_helper =
551 SearchTabHelper::FromWebContents(web_contents_.get());
552 if (!search_terms.empty() && search_tab_helper &&
553 search_tab_helper->SupportsInstant()) {
554 search_tab_helper->Submit(search_terms);
555 return DEFAULT_PAGE_LOAD;
557 load_params.is_renderer_initiated = is_renderer_initiated;
558 web_contents()->GetController().LoadURLWithParams(load_params);
560 return DEFAULT_PAGE_LOAD;
563 ToolbarModel::SecurityLevel TabAndroid::GetSecurityLevel(JNIEnv* env,
564 jobject obj) {
565 return ToolbarModelImpl::GetSecurityLevelForWebContents(web_contents());
568 void TabAndroid::SetActiveNavigationEntryTitleForUrl(JNIEnv* env,
569 jobject obj,
570 jstring jurl,
571 jstring jtitle) {
572 DCHECK(web_contents());
574 base::string16 title;
575 if (jtitle)
576 title = base::android::ConvertJavaStringToUTF16(env, jtitle);
578 std::string url;
579 if (jurl)
580 url = base::android::ConvertJavaStringToUTF8(env, jurl);
582 content::NavigationEntry* entry =
583 web_contents()->GetController().GetVisibleEntry();
584 if (entry && url == entry->GetVirtualURL().spec())
585 entry->SetTitle(title);
588 bool TabAndroid::Print(JNIEnv* env, jobject obj) {
589 if (!web_contents())
590 return false;
592 printing::PrintViewManagerBasic::CreateForWebContents(web_contents());
593 printing::PrintViewManagerBasic* print_view_manager =
594 printing::PrintViewManagerBasic::FromWebContents(web_contents());
595 if (print_view_manager == NULL)
596 return false;
598 print_view_manager->PrintNow();
599 return true;
602 ScopedJavaLocalRef<jobject> TabAndroid::GetFavicon(JNIEnv* env, jobject obj) {
603 ScopedJavaLocalRef<jobject> bitmap;
604 FaviconTabHelper* favicon_tab_helper =
605 FaviconTabHelper::FromWebContents(web_contents_.get());
607 if (!favicon_tab_helper)
608 return bitmap;
610 // If the favicon isn't valid, it will return a default bitmap.
612 SkBitmap favicon =
613 favicon_tab_helper->GetFavicon()
614 .AsImageSkia()
615 .GetRepresentation(
616 ResourceBundle::GetSharedInstance().GetMaxScaleFactor())
617 .sk_bitmap();
619 if (favicon.empty()) {
620 favicon = favicon_tab_helper->GetFavicon().AsBitmap();
623 if (!favicon.empty()) {
624 gfx::DeviceDisplayInfo device_info;
625 const float device_scale_factor = device_info.GetDIPScale();
626 int target_size_dip = device_scale_factor * gfx::kFaviconSize;
627 if (favicon.width() != target_size_dip ||
628 favicon.height() != target_size_dip) {
629 favicon =
630 skia::ImageOperations::Resize(favicon,
631 skia::ImageOperations::RESIZE_BEST,
632 target_size_dip,
633 target_size_dip);
636 bitmap = gfx::ConvertToJavaBitmap(&favicon);
638 return bitmap;
641 jboolean TabAndroid::IsFaviconValid(JNIEnv* env, jobject jobj) {
642 return web_contents() &&
643 FaviconTabHelper::FromWebContents(web_contents())->FaviconIsValid();
646 prerender::PrerenderManager* TabAndroid::GetPrerenderManager() const {
647 Profile* profile = GetProfile();
648 if (!profile)
649 return NULL;
650 return prerender::PrerenderManagerFactory::GetForProfile(profile);
653 static void Init(JNIEnv* env, jobject obj) {
654 TRACE_EVENT0("native", "TabAndroid::Init");
655 // This will automatically bind to the Java object and pass ownership there.
656 new TabAndroid(env, obj);
659 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) {
660 return RegisterNativesImpl(env);