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

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

Issue 2315323002: Pass JavaRef to WebContents::FromJavaWebContents. (Closed)
Patch Set: Created 4 years, 3 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') | chrome/browser/android/tab_state.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 #include "ui/base/window_open_disposition.h" 92 #include "ui/base/window_open_disposition.h"
93 #include "ui/display/display.h" 93 #include "ui/display/display.h"
94 #include "ui/display/screen.h" 94 #include "ui/display/screen.h"
95 #include "ui/gfx/android/java_bitmap.h" 95 #include "ui/gfx/android/java_bitmap.h"
96 #include "ui/gfx/favicon_size.h" 96 #include "ui/gfx/favicon_size.h"
97 #include "ui/gfx/image/image_skia.h" 97 #include "ui/gfx/image/image_skia.h"
98 98
99 using base::android::AttachCurrentThread; 99 using base::android::AttachCurrentThread;
100 using base::android::ConvertUTF8ToJavaString; 100 using base::android::ConvertUTF8ToJavaString;
101 using base::android::JavaParamRef; 101 using base::android::JavaParamRef;
102 using base::android::JavaRef;
102 using content::BrowserThread; 103 using content::BrowserThread;
103 using content::GlobalRequestID; 104 using content::GlobalRequestID;
104 using content::NavigationController; 105 using content::NavigationController;
105 using content::WebContents; 106 using content::WebContents;
106 using navigation_interception::InterceptNavigationDelegate; 107 using navigation_interception::InterceptNavigationDelegate;
107 using navigation_interception::NavigationParams; 108 using navigation_interception::NavigationParams;
108 109
109 TabAndroid* TabAndroid::FromWebContents( 110 TabAndroid* TabAndroid::FromWebContents(
110 const content::WebContents* web_contents) { 111 const content::WebContents* web_contents) {
111 const CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents( 112 const CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(
112 web_contents); 113 web_contents);
113 if (!core_tab_helper) 114 if (!core_tab_helper)
114 return NULL; 115 return NULL;
115 116
116 CoreTabHelperDelegate* core_delegate = core_tab_helper->delegate(); 117 CoreTabHelperDelegate* core_delegate = core_tab_helper->delegate();
117 if (!core_delegate) 118 if (!core_delegate)
118 return NULL; 119 return NULL;
119 120
120 return static_cast<TabAndroid*>(core_delegate); 121 return static_cast<TabAndroid*>(core_delegate);
121 } 122 }
122 123
123 TabAndroid* TabAndroid::GetNativeTab(JNIEnv* env, jobject obj) { 124 TabAndroid* TabAndroid::GetNativeTab(JNIEnv* env, const JavaRef<jobject>& obj) {
124 return reinterpret_cast<TabAndroid*>(Java_Tab_getNativePtr(env, obj)); 125 return reinterpret_cast<TabAndroid*>(Java_Tab_getNativePtr(env, obj));
125 } 126 }
126 127
127 void TabAndroid::AttachTabHelpers(content::WebContents* web_contents) { 128 void TabAndroid::AttachTabHelpers(content::WebContents* web_contents) {
128 DCHECK(web_contents); 129 DCHECK(web_contents);
129 130
130 TabHelpers::AttachTabHelpers(web_contents); 131 TabHelpers::AttachTabHelpers(web_contents);
131 } 132 }
132 133
133 TabAndroid::TabAndroid(JNIEnv* env, jobject obj) 134 TabAndroid::TabAndroid(JNIEnv* env, const JavaRef<jobject>& obj)
134 : weak_java_tab_(env, obj), 135 : weak_java_tab_(env, obj),
135 content_layer_(cc::Layer::Create()), 136 content_layer_(cc::Layer::Create()),
136 tab_content_manager_(NULL), 137 tab_content_manager_(NULL),
137 synced_tab_delegate_(new browser_sync::SyncedTabDelegateAndroid(this)) { 138 synced_tab_delegate_(new browser_sync::SyncedTabDelegateAndroid(this)) {
138 Java_Tab_setNativePtr(env, obj, reinterpret_cast<intptr_t>(this)); 139 Java_Tab_setNativePtr(env, obj, reinterpret_cast<intptr_t>(this));
139 } 140 }
140 141
141 TabAndroid::~TabAndroid() { 142 TabAndroid::~TabAndroid() {
142 GetContentLayer()->RemoveAllChildren(); 143 GetContentLayer()->RemoveAllChildren();
143 JNIEnv* env = base::android::AttachCurrentThread(); 144 JNIEnv* env = base::android::AttachCurrentThread();
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 delete this; 362 delete this;
362 } 363 }
363 364
364 void TabAndroid::InitWebContents( 365 void TabAndroid::InitWebContents(
365 JNIEnv* env, 366 JNIEnv* env,
366 const JavaParamRef<jobject>& obj, 367 const JavaParamRef<jobject>& obj,
367 jboolean incognito, 368 jboolean incognito,
368 const JavaParamRef<jobject>& jweb_contents, 369 const JavaParamRef<jobject>& jweb_contents,
369 const JavaParamRef<jobject>& jweb_contents_delegate, 370 const JavaParamRef<jobject>& jweb_contents_delegate,
370 const JavaParamRef<jobject>& jcontext_menu_populator) { 371 const JavaParamRef<jobject>& jcontext_menu_populator) {
371 web_contents_.reset( 372 web_contents_.reset(content::WebContents::FromJavaWebContents(jweb_contents));
372 content::WebContents::FromJavaWebContents(jweb_contents.obj()));
373 DCHECK(web_contents_.get()); 373 DCHECK(web_contents_.get());
374 374
375 AttachTabHelpers(web_contents_.get()); 375 AttachTabHelpers(web_contents_.get());
376 376
377 SetWindowSessionID(session_window_id_.id()); 377 SetWindowSessionID(session_window_id_.id());
378 378
379 session_tab_id_.set_id( 379 session_tab_id_.set_id(
380 SessionTabHelper::FromWebContents(web_contents())->session_id().id()); 380 SessionTabHelper::FromWebContents(web_contents())->session_id().id());
381 ContextMenuHelper::FromWebContents(web_contents())->SetPopulator( 381 ContextMenuHelper::FromWebContents(web_contents())->SetPopulator(
382 jcontext_menu_populator); 382 jcontext_menu_populator);
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 if (tab_content_manager_) 884 if (tab_content_manager_)
885 tab_content_manager_->AttachLiveLayer(GetAndroidId(), GetContentLayer()); 885 tab_content_manager_->AttachLiveLayer(GetAndroidId(), GetContentLayer());
886 } 886 }
887 887
888 void TabAndroid::AttachOverlayWebContents( 888 void TabAndroid::AttachOverlayWebContents(
889 JNIEnv* env, 889 JNIEnv* env,
890 const JavaParamRef<jobject>& obj, 890 const JavaParamRef<jobject>& obj,
891 const JavaParamRef<jobject>& jweb_contents, 891 const JavaParamRef<jobject>& jweb_contents,
892 jboolean visible) { 892 jboolean visible) {
893 WebContents* web_contents = 893 WebContents* web_contents =
894 content::WebContents::FromJavaWebContents(jweb_contents.obj()); 894 content::WebContents::FromJavaWebContents(jweb_contents);
895 DCHECK(web_contents); 895 DCHECK(web_contents);
896 DCHECK(web_contents->GetNativeView()); 896 DCHECK(web_contents->GetNativeView());
897 897
898 web_contents->GetNativeView()->GetLayer()->SetHideLayerAndSubtree(!visible); 898 web_contents->GetNativeView()->GetLayer()->SetHideLayerAndSubtree(!visible);
899 content_layer_->AddChild(web_contents->GetNativeView()->GetLayer()); 899 content_layer_->AddChild(web_contents->GetNativeView()->GetLayer());
900 } 900 }
901 901
902 void TabAndroid::DetachOverlayWebContents( 902 void TabAndroid::DetachOverlayWebContents(
903 JNIEnv* env, 903 JNIEnv* env,
904 const JavaParamRef<jobject>& obj, 904 const JavaParamRef<jobject>& obj,
905 const JavaParamRef<jobject>& jweb_contents) { 905 const JavaParamRef<jobject>& jweb_contents) {
906 WebContents* web_contents = 906 WebContents* web_contents =
907 content::WebContents::FromJavaWebContents(jweb_contents.obj()); 907 content::WebContents::FromJavaWebContents(jweb_contents);
908 DCHECK(web_contents); 908 DCHECK(web_contents);
909 DCHECK(web_contents->GetNativeView()); 909 DCHECK(web_contents->GetNativeView());
910 910
911 if (web_contents->GetNativeView()->GetLayer()->parent() == content_layer_) 911 if (web_contents->GetNativeView()->GetLayer()->parent() == content_layer_)
912 web_contents->GetNativeView()->GetLayer()->RemoveFromParent(); 912 web_contents->GetNativeView()->GetLayer()->RemoveFromParent();
913 } 913 }
914 914
915 static void Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { 915 static void Init(JNIEnv* env, const JavaParamRef<jobject>& obj) {
916 TRACE_EVENT0("native", "TabAndroid::Init"); 916 TRACE_EVENT0("native", "TabAndroid::Init");
917 // This will automatically bind to the Java object and pass ownership there. 917 // This will automatically bind to the Java object and pass ownership there.
918 new TabAndroid(env, obj); 918 new TabAndroid(env, obj);
919 } 919 }
920 920
921 // static 921 // static
922 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { 922 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) {
923 return RegisterNativesImpl(env); 923 return RegisterNativesImpl(env);
924 } 924 }
OLDNEW
« no previous file with comments | « chrome/browser/android/tab_android.h ('k') | chrome/browser/android/tab_state.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698