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

Side by Side Diff: chrome/browser/ui/android/infobars/infobar_container_android.cc

Issue 22694006: Infobar system refactor. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/ui/android/infobars/infobar_container_android.h" 5 #include "chrome/browser/ui/android/infobars/infobar_container_android.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "chrome/browser/infobars/infobar.h" 10 #include "chrome/browser/infobars/infobar.h"
(...skipping 21 matching lines...) Expand all
32 32
33 void InfoBarContainerAndroid::Destroy(JNIEnv* env, jobject obj) { 33 void InfoBarContainerAndroid::Destroy(JNIEnv* env, jobject obj) {
34 delete this; 34 delete this;
35 } 35 }
36 36
37 void InfoBarContainerAndroid::OnWebContentsReplaced( 37 void InfoBarContainerAndroid::OnWebContentsReplaced(
38 content::WebContents* old_web_contents, 38 content::WebContents* old_web_contents,
39 content::WebContents* new_web_contents) { 39 content::WebContents* new_web_contents) {
40 InfoBarService* new_infobar_service = new_web_contents ? 40 InfoBarService* new_infobar_service = new_web_contents ?
41 InfoBarService::FromWebContents(new_web_contents) : NULL; 41 InfoBarService::FromWebContents(new_web_contents) : NULL;
42 if (new_infobar_service) 42 ChangeInfoBarService(new_infobar_service);
43 ChangeInfoBarService(new_infobar_service);
44 } 43 }
45 44
46 void InfoBarContainerAndroid::PlatformSpecificAddInfoBar(InfoBar* infobar, 45 void InfoBarContainerAndroid::PlatformSpecificAddInfoBar(InfoBar* infobar,
47 size_t position) { 46 size_t position) {
48 DCHECK(infobar); 47 DCHECK(infobar);
49 InfoBarAndroid* android_bar = static_cast<InfoBarAndroid*>(infobar); 48 InfoBarAndroid* android_bar = static_cast<InfoBarAndroid*>(infobar);
50 if (!android_bar) { 49 if (!android_bar) {
51 // TODO(bulach): CLANK: implement other types of InfoBars. 50 // TODO(bulach): CLANK: implement other types of InfoBars.
52 // TODO(jrg): this will always print out WARNING_TYPE as an int. 51 // TODO(jrg): this will always print out WARNING_TYPE as an int.
53 // Try and be more helpful. 52 // Try and be more helpful.
(...skipping 20 matching lines...) Expand all
74 base::android::ScopedJavaLocalRef<jobject> java_infobar = 73 base::android::ScopedJavaLocalRef<jobject> java_infobar =
75 android_bar->CreateRenderInfoBar(env); 74 android_bar->CreateRenderInfoBar(env);
76 Java_InfoBarContainer_addInfoBar( 75 Java_InfoBarContainer_addInfoBar(
77 env, weak_java_infobar_container_.get(env).obj(), java_infobar.obj()); 76 env, weak_java_infobar_container_.get(env).obj(), java_infobar.obj());
78 android_bar->set_java_infobar(java_infobar); 77 android_bar->set_java_infobar(java_infobar);
79 } 78 }
80 79
81 void InfoBarContainerAndroid::PlatformSpecificReplaceInfoBar( 80 void InfoBarContainerAndroid::PlatformSpecificReplaceInfoBar(
82 InfoBar* old_infobar, 81 InfoBar* old_infobar,
83 InfoBar* new_infobar) { 82 InfoBar* new_infobar) {
84 InfoBarAndroid* new_android_bar = static_cast<InfoBarAndroid*>(new_infobar); 83 static_cast<InfoBarAndroid*>(new_infobar)->PassJavaInfoBar(
85 InfoBarAndroid* old_android_bar = (old_infobar == NULL) ? 84 static_cast<InfoBarAndroid*>(old_infobar));
86 NULL : static_cast<InfoBarAndroid*>(old_infobar);
87 new_android_bar->PassJavaInfoBar(old_android_bar);
88 } 85 }
89 86
90 void InfoBarContainerAndroid::PlatformSpecificRemoveInfoBar(InfoBar* infobar) { 87 void InfoBarContainerAndroid::PlatformSpecificRemoveInfoBar(InfoBar* infobar) {
91 InfoBarAndroid* android_infobar = static_cast<InfoBarAndroid*>(infobar); 88 InfoBarAndroid* android_infobar = static_cast<InfoBarAndroid*>(infobar);
92 android_infobar->CloseJavaInfoBar(); 89 android_infobar->CloseJavaInfoBar();
93 base::MessageLoop::current()->DeleteSoon(FROM_HERE, infobar);
94 } 90 }
95 91
96 92
97 // Native JNI methods --------------------------------------------------------- 93 // Native JNI methods ---------------------------------------------------------
98 94
99 static int Init(JNIEnv* env, 95 static int Init(JNIEnv* env,
100 jobject obj, 96 jobject obj,
101 jint native_web_contents, 97 jint native_web_contents,
102 jobject auto_login_delegate) { 98 jobject auto_login_delegate) {
103 InfoBarContainerAndroid* infobar_container = 99 InfoBarContainerAndroid* infobar_container =
104 new InfoBarContainerAndroid(env, obj, auto_login_delegate); 100 new InfoBarContainerAndroid(env, obj, auto_login_delegate);
105 infobar_container->ChangeInfoBarService(InfoBarService::FromWebContents( 101 infobar_container->ChangeInfoBarService(InfoBarService::FromWebContents(
106 reinterpret_cast<content::WebContents*>(native_web_contents))); 102 reinterpret_cast<content::WebContents*>(native_web_contents)));
107 return reinterpret_cast<int>(infobar_container); 103 return reinterpret_cast<int>(infobar_container);
108 } 104 }
109 105
110 bool RegisterInfoBarContainer(JNIEnv* env) { 106 bool RegisterInfoBarContainer(JNIEnv* env) {
111 return RegisterNativesImpl(env); 107 return RegisterNativesImpl(env);
112 } 108 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698