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

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

Issue 23264020: Move Android to use new Popup Blocker API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Comments Created 7 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 | Annotate | Revision Log
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/chrome_web_contents_delegate_android.h" 5 #include "chrome/browser/android/chrome_web_contents_delegate_android.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/command_line.h"
9 #include "chrome/browser/android/tab_android.h"
8 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/file_select_helper.h" 11 #include "chrome/browser/file_select_helper.h"
10 #include "chrome/browser/media/media_capture_devices_dispatcher.h" 12 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
13 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_manager.h" 14 #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_manager.h"
15 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h"
16 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
17 #include "chrome/browser/ui/browser_navigator.h"
12 #include "chrome/browser/ui/find_bar/find_notification_details.h" 18 #include "chrome/browser/ui/find_bar/find_notification_details.h"
13 #include "chrome/browser/ui/find_bar/find_tab_helper.h" 19 #include "chrome/browser/ui/find_bar/find_tab_helper.h"
20 #include "chrome/common/chrome_switches.h"
14 #include "content/public/browser/notification_details.h" 21 #include "content/public/browser/notification_details.h"
15 #include "content/public/browser/notification_service.h" 22 #include "content/public/browser/notification_service.h"
16 #include "content/public/browser/notification_source.h" 23 #include "content/public/browser/notification_source.h"
24 #include "content/public/browser/render_view_host.h"
17 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
18 #include "content/public/common/file_chooser_params.h" 26 #include "content/public/common/file_chooser_params.h"
19 #include "jni/ChromeWebContentsDelegateAndroid_jni.h" 27 #include "jni/ChromeWebContentsDelegateAndroid_jni.h"
28 #include "third_party/WebKit/public/web/WebWindowFeatures.h"
20 #include "ui/gfx/rect.h" 29 #include "ui/gfx/rect.h"
21 #include "ui/gfx/rect_f.h" 30 #include "ui/gfx/rect_f.h"
22 31
23 #if defined(ENABLE_PLUGINS) 32 #if defined(ENABLE_PLUGINS)
24 #include "chrome/browser/pepper_broker_infobar_delegate.h" 33 #include "chrome/browser/pepper_broker_infobar_delegate.h"
25 #endif 34 #endif
26 35
36 using base::android::AttachCurrentThread;
27 using base::android::ScopedJavaLocalRef; 37 using base::android::ScopedJavaLocalRef;
28 using content::FileChooserParams; 38 using content::FileChooserParams;
29 using content::WebContents; 39 using content::WebContents;
30 40
31 namespace { 41 namespace {
32 42
33 ScopedJavaLocalRef<jobject> CreateJavaRectF( 43 ScopedJavaLocalRef<jobject> CreateJavaRectF(
34 JNIEnv* env, 44 JNIEnv* env,
35 const gfx::RectF& rect) { 45 const gfx::RectF& rect) {
36 return ScopedJavaLocalRef<jobject>( 46 return ScopedJavaLocalRef<jobject>(
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 const base::Callback<void(bool)>& callback) { 220 const base::Callback<void(bool)>& callback) {
211 #if defined(ENABLE_PLUGINS) 221 #if defined(ENABLE_PLUGINS)
212 PepperBrokerInfoBarDelegate::Create( 222 PepperBrokerInfoBarDelegate::Create(
213 web_contents, url, plugin_path, callback); 223 web_contents, url, plugin_path, callback);
214 return true; 224 return true;
215 #else 225 #else
216 return false; 226 return false;
217 #endif 227 #endif
218 } 228 }
219 229
230 WebContents* ChromeWebContentsDelegateAndroid::OpenURLFromTab(
231 WebContents* source,
232 const content::OpenURLParams& params) {
233 WindowOpenDisposition disposition = params.disposition;
234 if (!source || (disposition != CURRENT_TAB &&
235 disposition != NEW_FOREGROUND_TAB &&
236 disposition != NEW_BACKGROUND_TAB &&
237 disposition != OFF_THE_RECORD &&
238 disposition != NEW_POPUP &&
239 disposition != NEW_WINDOW)) {
240 // We can't handle this here. Give the parent a chance.
241 return WebContentsDelegateAndroid::OpenURLFromTab(source, params);
242 }
243
244 Profile* profile = Profile::FromBrowserContext(source->GetBrowserContext());
245 chrome::NavigateParams nav_params(profile,
246 params.url,
247 params.transition);
248 FillNavigateParamsFromOpenURLParams(&nav_params, params);
249 nav_params.source_contents = source;
250 nav_params.window_action = chrome::NavigateParams::SHOW_WINDOW;
251 nav_params.user_gesture = params.user_gesture;
252
253 PopupBlockerTabHelper* popup_blocker_helper =
254 PopupBlockerTabHelper::FromWebContents(source);
255 DCHECK(popup_blocker_helper);
256
257 if ((params.disposition == NEW_POPUP ||
258 params.disposition == NEW_FOREGROUND_TAB ||
Ted C 2013/08/21 21:06:15 should these be indented +1 to match with the open
David Trainor- moved to gerrit 2013/08/21 21:18:28 Done.
259 params.disposition == NEW_BACKGROUND_TAB ||
260 params.disposition == NEW_WINDOW) &&
261 !params.user_gesture &&
262 !CommandLine::ForCurrentProcess()->HasSwitch(
263 switches::kDisablePopupBlocking)) {
264 if (popup_blocker_helper->MaybeBlockPopup(nav_params,
265 WebKit::WebWindowFeatures())) {
266 return NULL;
267 }
268 }
269
270 return WebContentsDelegateAndroid::OpenURLFromTab(source, params);
271 }
272
273 void ChromeWebContentsDelegateAndroid::AddNewContents(
274 WebContents* source,
275 WebContents* new_contents,
276 WindowOpenDisposition disposition,
277 const gfx::Rect& initial_pos,
278 bool user_gesture,
279 bool* was_blocked) {
280 // No code for this yet.
281 DCHECK_NE(disposition, SAVE_TO_DISK);
282 // Can't create a new contents for the current tab - invalid case.
283 DCHECK_NE(disposition, CURRENT_TAB);
284
285 BlockedContentTabHelper* source_blocked_content = NULL;
286 if (source)
287 source_blocked_content = BlockedContentTabHelper::FromWebContents(source);
288
289 TabAndroid::InitTabHelpers(new_contents);
290
291 if (source_blocked_content) {
292 if (source_blocked_content->all_contents_blocked()) {
293 source_blocked_content->AddWebContents(
294 new_contents, disposition, initial_pos, user_gesture);
295 if (was_blocked)
296 *was_blocked = true;
297 return;
298 }
299
300 new_contents->GetRenderViewHost()->DisassociateFromPopupCount();
301 }
302
303 JNIEnv* env = AttachCurrentThread();
304 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env);
305 bool handled = false;
306 if (!obj.is_null()) {
307 handled = Java_ChromeWebContentsDelegateAndroid_addNewContents(
308 env,
309 obj.obj(),
310 reinterpret_cast<jint>(source),
311 reinterpret_cast<jint>(new_contents),
312 static_cast<jint>(disposition),
313 NULL,
314 user_gesture);
315 }
316
317 if (!handled)
318 delete new_contents;
319 }
220 320
221 } // namespace android 321 } // namespace android
222 } // namespace chrome 322 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698