diff options
16 files changed, 160 insertions, 57 deletions
diff --git a/android_webview/java/src/org/chromium/android_webview/AwWebContentsDelegateAdapter.java b/android_webview/java/src/org/chromium/android_webview/AwWebContentsDelegateAdapter.java index 260ea96..da09a1a 100644 --- a/android_webview/java/src/org/chromium/android_webview/AwWebContentsDelegateAdapter.java +++ b/android_webview/java/src/org/chromium/android_webview/AwWebContentsDelegateAdapter.java @@ -92,13 +92,6 @@ class AwWebContentsDelegateAdapter extends AwWebContentsDelegate { } @Override - public boolean addNewContents(int nativeSourceWebContents, int nativeWebContents, - int disposition, Rect initialPosition, boolean userGesture) { - // This is overridden native side; see the other addNewContents overload. - throw new RuntimeException("Impossible"); - } - - @Override public void closeContents() { mContentsClient.onCloseWindow(); } diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ChromeWebContentsDelegateAndroid.java b/chrome/android/java/src/org/chromium/chrome/browser/ChromeWebContentsDelegateAndroid.java index 546f302..f1c0355 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/ChromeWebContentsDelegateAndroid.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/ChromeWebContentsDelegateAndroid.java @@ -26,6 +26,12 @@ public class ChromeWebContentsDelegateAndroid extends WebContentsDelegateAndroid public void onFindMatchRectsAvailable(FindMatchRectsDetails result) { } + @CalledByNative + public boolean addNewContents(int nativeSourceWebContents, int nativeWebContents, + int disposition, Rect initialPosition, boolean userGesture) { + return false; + } + // Helper functions used to create types that are part of the public interface @CalledByNative private static Rect createRect(int x, int y, int right, int bottom) { diff --git a/chrome/android/testshell/testshell_tab.cc b/chrome/android/testshell/testshell_tab.cc index 656bc31..568190d 100644 --- a/chrome/android/testshell/testshell_tab.cc +++ b/chrome/android/testshell/testshell_tab.cc @@ -8,6 +8,7 @@ #include "base/logging.h" #include "chrome/browser/android/chrome_web_contents_delegate_android.h" #include "chrome/browser/ui/android/window_android_helper.h" +#include "chrome/browser/ui/browser_navigator.h" #include "chrome/common/net/url_fixer_upper.h" #include "content/public/browser/android/content_view_core.h" #include "content/public/browser/web_contents.h" @@ -97,6 +98,10 @@ void TestShellTab::RunExternalProtocolDialog(const GURL& url) { NOTIMPLEMENTED(); } +void TestShellTab::HandlePopupNavigation(chrome::NavigateParams* params) { + NOTIMPLEMENTED(); +} + bool TestShellTab::RegisterTestShellTab(JNIEnv* env) { return RegisterNativesImpl(env); } diff --git a/chrome/android/testshell/testshell_tab.h b/chrome/android/testshell/testshell_tab.h index bb06ad9..99a0d65 100644 --- a/chrome/android/testshell/testshell_tab.h +++ b/chrome/android/testshell/testshell_tab.h @@ -16,6 +16,10 @@ class SyncedTabDelegate; } namespace chrome { +struct NavigateParams; +} + +namespace chrome { namespace android { class ChromeWebContentsDelegateAndroid; } @@ -68,7 +72,7 @@ class TestShellTab : public TabAndroid { virtual void OnNewTabPageReady() OVERRIDE; virtual void RunExternalProtocolDialog(const GURL& url) OVERRIDE; - + virtual void HandlePopupNavigation(chrome::NavigateParams* params) OVERRIDE; virtual int GetSyncId() const OVERRIDE; virtual void SetSyncId(int sync_id) OVERRIDE; diff --git a/chrome/browser/android/chrome_web_contents_delegate_android.cc b/chrome/browser/android/chrome_web_contents_delegate_android.cc index 0eb1157..b2df0ec 100644 --- a/chrome/browser/android/chrome_web_contents_delegate_android.cc +++ b/chrome/browser/android/chrome_web_contents_delegate_android.cc @@ -5,18 +5,27 @@ #include "chrome/browser/android/chrome_web_contents_delegate_android.h" #include "base/android/jni_android.h" +#include "base/command_line.h" +#include "chrome/browser/android/tab_android.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/file_select_helper.h" #include "chrome/browser/media/media_capture_devices_dispatcher.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_manager.h" +#include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" +#include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" +#include "chrome/browser/ui/browser_navigator.h" #include "chrome/browser/ui/find_bar/find_notification_details.h" #include "chrome/browser/ui/find_bar/find_tab_helper.h" +#include "chrome/common/chrome_switches.h" #include "content/public/browser/notification_details.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_source.h" +#include "content/public/browser/render_view_host.h" #include "content/public/browser/web_contents.h" #include "content/public/common/file_chooser_params.h" #include "jni/ChromeWebContentsDelegateAndroid_jni.h" +#include "third_party/WebKit/public/web/WebWindowFeatures.h" #include "ui/gfx/rect.h" #include "ui/gfx/rect_f.h" @@ -24,6 +33,7 @@ #include "chrome/browser/pepper_broker_infobar_delegate.h" #endif +using base::android::AttachCurrentThread; using base::android::ScopedJavaLocalRef; using content::FileChooserParams; using content::WebContents; @@ -217,6 +227,96 @@ bool ChromeWebContentsDelegateAndroid::RequestPpapiBrokerPermission( #endif } +WebContents* ChromeWebContentsDelegateAndroid::OpenURLFromTab( + WebContents* source, + const content::OpenURLParams& params) { + WindowOpenDisposition disposition = params.disposition; + if (!source || (disposition != CURRENT_TAB && + disposition != NEW_FOREGROUND_TAB && + disposition != NEW_BACKGROUND_TAB && + disposition != OFF_THE_RECORD && + disposition != NEW_POPUP && + disposition != NEW_WINDOW)) { + // We can't handle this here. Give the parent a chance. + return WebContentsDelegateAndroid::OpenURLFromTab(source, params); + } + + Profile* profile = Profile::FromBrowserContext(source->GetBrowserContext()); + chrome::NavigateParams nav_params(profile, + params.url, + params.transition); + FillNavigateParamsFromOpenURLParams(&nav_params, params); + nav_params.source_contents = source; + nav_params.window_action = chrome::NavigateParams::SHOW_WINDOW; + nav_params.user_gesture = params.user_gesture; + + PopupBlockerTabHelper* popup_blocker_helper = + PopupBlockerTabHelper::FromWebContents(source); + DCHECK(popup_blocker_helper); + + if ((params.disposition == NEW_POPUP || + params.disposition == NEW_FOREGROUND_TAB || + params.disposition == NEW_BACKGROUND_TAB || + params.disposition == NEW_WINDOW) && + !params.user_gesture && + !CommandLine::ForCurrentProcess()->HasSwitch( + switches::kDisablePopupBlocking)) { + if (popup_blocker_helper->MaybeBlockPopup(nav_params, + WebKit::WebWindowFeatures())) { + return NULL; + } + } + + return WebContentsDelegateAndroid::OpenURLFromTab(source, params); +} + +void ChromeWebContentsDelegateAndroid::AddNewContents( + WebContents* source, + WebContents* new_contents, + WindowOpenDisposition disposition, + const gfx::Rect& initial_pos, + bool user_gesture, + bool* was_blocked) { + // No code for this yet. + DCHECK_NE(disposition, SAVE_TO_DISK); + // Can't create a new contents for the current tab - invalid case. + DCHECK_NE(disposition, CURRENT_TAB); + + BlockedContentTabHelper* source_blocked_content = NULL; + if (source) + source_blocked_content = BlockedContentTabHelper::FromWebContents(source); + + TabAndroid::InitTabHelpers(new_contents); + + if (source_blocked_content) { + if (source_blocked_content->all_contents_blocked()) { + source_blocked_content->AddWebContents( + new_contents, disposition, initial_pos, user_gesture); + if (was_blocked) + *was_blocked = true; + return; + } + + new_contents->GetRenderViewHost()->DisassociateFromPopupCount(); + } + + JNIEnv* env = AttachCurrentThread(); + ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); + bool handled = false; + if (!obj.is_null()) { + handled = Java_ChromeWebContentsDelegateAndroid_addNewContents( + env, + obj.obj(), + reinterpret_cast<jint>(source), + reinterpret_cast<jint>(new_contents), + static_cast<jint>(disposition), + NULL, + user_gesture); + } + + if (!handled) + delete new_contents; +} } // namespace android } // namespace chrome diff --git a/chrome/browser/android/chrome_web_contents_delegate_android.h b/chrome/browser/android/chrome_web_contents_delegate_android.h index 321b8b7..9c22997 100644 --- a/chrome/browser/android/chrome_web_contents_delegate_android.h +++ b/chrome/browser/android/chrome_web_contents_delegate_android.h @@ -62,6 +62,15 @@ class ChromeWebContentsDelegateAndroid const GURL& url, const base::FilePath& plugin_path, const base::Callback<void(bool)>& callback) OVERRIDE; + virtual content::WebContents* OpenURLFromTab( + content::WebContents* source, + const content::OpenURLParams& params) OVERRIDE; + virtual void AddNewContents(content::WebContents* source, + content::WebContents* new_contents, + WindowOpenDisposition disposition, + const gfx::Rect& initial_pos, + bool user_gesture, + bool* was_blocked) OVERRIDE; private: // NotificationObserver implementation. diff --git a/chrome/browser/android/tab_android.cc b/chrome/browser/android/tab_android.cc index d4da9b7..e8b3100 100644 --- a/chrome/browser/android/tab_android.cc +++ b/chrome/browser/android/tab_android.cc @@ -20,6 +20,7 @@ #include "chrome/browser/ui/android/window_android_helper.h" #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" +#include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" #include "chrome/browser/ui/browser_tab_contents.h" #include "chrome/browser/ui/find_bar/find_tab_helper.h" @@ -77,6 +78,7 @@ void BrowserTabContents::AttachTabHelpers(WebContents* contents) { PasswordManagerDelegateImpl::CreateForWebContents(contents); PasswordManager::CreateForWebContentsAndDelegate( contents, PasswordManagerDelegateImpl::FromWebContents(contents)); + PopupBlockerTabHelper::CreateForWebContents(contents); PrefsTabHelper::CreateForWebContents(contents); prerender::PrerenderTabHelper::CreateForWebContentsWithPasswordManager( contents, PasswordManager::FromWebContents(contents)); diff --git a/chrome/browser/android/tab_android.h b/chrome/browser/android/tab_android.h index 19d8f25..53ff14c 100644 --- a/chrome/browser/android/tab_android.h +++ b/chrome/browser/android/tab_android.h @@ -20,6 +20,10 @@ namespace browser_sync { class SyncedTabDelegate; } +namespace chrome { +struct NavigateParams; +} + namespace content { struct ContextMenuParams; class WebContents; @@ -44,6 +48,8 @@ class TabAndroid { const SessionID& id() const { return tab_id_; } + virtual void HandlePopupNavigation(chrome::NavigateParams* params) = 0; + virtual void OnReceivedHttpAuthRequest(jobject auth_handler, const string16& host, const string16& realm) = 0; @@ -90,11 +96,11 @@ class TabAndroid { static bool RegisterTabAndroid(JNIEnv* env); + static void InitTabHelpers(content::WebContents* web_contents); + protected: virtual ~TabAndroid(); - static void InitTabHelpers(content::WebContents* web_contents); - content::WebContents* InitWebContentsFromView(JNIEnv* env, jobject content_view); diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index 380aa2a..2d60399f 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -81,6 +81,7 @@ #include "chrome/browser/ssl/ssl_tab_helper.h" #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" #include "chrome/browser/tab_contents/tab_util.h" +#include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" #include "chrome/browser/ui/chrome_select_file_policy.h" #include "chrome/browser/ui/sync/sync_promo_ui.h" #include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h" @@ -169,10 +170,6 @@ #include "chrome/browser/crash_handler_host_linux.h" #endif -#if !defined(OS_ANDROID) -#include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" -#endif - #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" #endif @@ -525,7 +522,6 @@ void SetApplicationLocaleOnIOThread(const std::string& locale) { g_io_thread_application_locale.Get() = locale; } -#if !defined(OS_ANDROID) struct BlockedPopupParams { BlockedPopupParams(const GURL& target_url, const content::Referrer& referrer, @@ -572,7 +568,6 @@ void HandleBlockedPopupOnUIThread(const BlockedPopupParams& params) { params.user_gesture, params.opener_suppressed); } -#endif } // namespace @@ -1996,7 +1991,6 @@ bool ChromeContentBrowserClient::CanCreateWindow( return false; } -#if !defined(OS_ANDROID) if (is_guest) return true; @@ -2026,7 +2020,6 @@ bool ChromeContentBrowserClient::CanCreateWindow( opener_id))); return false; } -#endif return true; } diff --git a/chrome/browser/ui/android/tab_model/tab_model_list.cc b/chrome/browser/ui/android/tab_model/tab_model_list.cc index aecd9e4..00dc288 100644 --- a/chrome/browser/ui/android/tab_model/tab_model_list.cc +++ b/chrome/browser/ui/android/tab_model/tab_model_list.cc @@ -4,8 +4,10 @@ #include "chrome/browser/ui/android/tab_model/tab_model_list.h" +#include "chrome/browser/android/tab_android.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/android/tab_model/tab_model.h" +#include "chrome/browser/ui/browser_navigator.h" namespace { @@ -32,6 +34,15 @@ void TabModelList::RemoveTabModel(TabModel* tab_model) { tab_models().erase(remove_tab_model); } +void TabModelList::HandlePopupNavigation(chrome::NavigateParams* params) { + TabAndroid* tab = TabAndroid::FromWebContents(params->source_contents); + + // NOTE: If this fails contact dtrainor@. + DCHECK(tab); + tab->HandlePopupNavigation(params); +} + + TabModel* TabModelList::GetTabModelWithProfile( Profile* profile) { if (!profile) diff --git a/chrome/browser/ui/android/tab_model/tab_model_list.h b/chrome/browser/ui/android/tab_model/tab_model_list.h index 0d8e0df..b4c1cd9 100644 --- a/chrome/browser/ui/android/tab_model/tab_model_list.h +++ b/chrome/browser/ui/android/tab_model/tab_model_list.h @@ -12,6 +12,10 @@ class Profile; class TabModel; +namespace chrome { +struct NavigateParams; +} + // Stores a list of all TabModel objects. class TabModelList { public: @@ -19,6 +23,7 @@ class TabModelList { typedef TabModelVector::iterator iterator; typedef TabModelVector::const_iterator const_iterator; + static void HandlePopupNavigation(chrome::NavigateParams* params); static void AddTabModel(TabModel* tab_model); static void RemoveTabModel(TabModel* tab_model); diff --git a/chrome/browser/ui/blocked_content/popup_blocker_tab_helper.cc b/chrome/browser/ui/blocked_content/popup_blocker_tab_helper.cc index 0d27929..551d831 100644 --- a/chrome/browser/ui/blocked_content/popup_blocker_tab_helper.cc +++ b/chrome/browser/ui/blocked_content/popup_blocker_tab_helper.cc @@ -20,6 +20,10 @@ #include "content/public/browser/web_contents_view.h" #include "third_party/WebKit/public/web/WebWindowFeatures.h" +#if defined(OS_ANDROID) +#include "chrome/browser/ui/android/tab_model/tab_model_list.h" +#endif + using WebKit::WebWindowFeatures; DEFINE_WEB_CONTENTS_USER_DATA_KEY(PopupBlockerTabHelper); @@ -139,7 +143,11 @@ void PopupBlockerTabHelper::ShowBlockedPopup(int32 id) { BlockedRequest* popup = blocked_popups_.Lookup(id); if (!popup) return; +#if defined(OS_ANDROID) + TabModelList::HandlePopupNavigation(&popup->params); +#else chrome::Navigate(&popup->params); +#endif if (popup->params.target_contents) { popup->params.target_contents->Send(new ChromeViewMsg_SetWindowFeatures( popup->params.target_contents->GetRoutingID(), popup->window_features)); diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi index 4ce2d2b..3e1c504 100644 --- a/chrome/chrome_browser_ui.gypi +++ b/chrome/chrome_browser_ui.gypi @@ -2816,8 +2816,6 @@ # There's no Browser/BrowserList on Android. 'browser/ui/active_tab_tracker.cc', 'browser/ui/active_tab_tracker.h', - 'browser/ui/blocked_content/popup_blocker_tab_helper.cc', - 'browser/ui/blocked_content/popup_blocker_tab_helper.h', 'browser/ui/bookmarks/bookmark_bubble_sign_in_delegate.cc', 'browser/ui/bookmarks/bookmark_bubble_sign_in_delegate.h', 'browser/ui/bookmarks/bookmark_context_menu_controller.cc', @@ -2827,7 +2825,6 @@ 'browser/ui/browser_finder.cc', 'browser/ui/browser_iterator.cc', 'browser/ui/browser_list.cc', - 'browser/ui/browser_navigator.cc', 'browser/ui/browser_otr_state.cc', 'browser/ui/browser_tab_contents.cc', 'browser/ui/browser_tab_restore_service_delegate.cc', diff --git a/components/web_contents_delegate_android/android/java/src/org/chromium/components/web_contents_delegate_android/WebContentsDelegateAndroid.java b/components/web_contents_delegate_android/android/java/src/org/chromium/components/web_contents_delegate_android/WebContentsDelegateAndroid.java index c09cb89..7db0705 100644 --- a/components/web_contents_delegate_android/android/java/src/org/chromium/components/web_contents_delegate_android/WebContentsDelegateAndroid.java +++ b/components/web_contents_delegate_android/android/java/src/org/chromium/components/web_contents_delegate_android/WebContentsDelegateAndroid.java @@ -57,12 +57,6 @@ public class WebContentsDelegateAndroid { } @CalledByNative - public boolean addNewContents(int nativeSourceWebContents, int nativeWebContents, - int disposition, Rect initialPosition, boolean userGesture) { - return false; - } - - @CalledByNative public void activateContents() { } diff --git a/components/web_contents_delegate_android/web_contents_delegate_android.cc b/components/web_contents_delegate_android/web_contents_delegate_android.cc index 8f599a1..c908f6a 100644 --- a/components/web_contents_delegate_android/web_contents_delegate_android.cc +++ b/components/web_contents_delegate_android/web_contents_delegate_android.cc @@ -124,30 +124,6 @@ void WebContentsDelegateAndroid::NavigationStateChanged( changed_flags); } -void WebContentsDelegateAndroid::AddNewContents( - WebContents* source, - WebContents* new_contents, - WindowOpenDisposition disposition, - const gfx::Rect& initial_pos, - bool user_gesture, - bool* was_blocked) { - JNIEnv* env = AttachCurrentThread(); - ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); - bool handled = false; - if (!obj.is_null()) { - handled = Java_WebContentsDelegateAndroid_addNewContents( - env, - obj.obj(), - reinterpret_cast<jint>(source), - reinterpret_cast<jint>(new_contents), - static_cast<jint>(disposition), - NULL, - user_gesture); - } - if (!handled) - delete new_contents; -} - void WebContentsDelegateAndroid::ActivateContents(WebContents* contents) { JNIEnv* env = AttachCurrentThread(); ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); diff --git a/components/web_contents_delegate_android/web_contents_delegate_android.h b/components/web_contents_delegate_android/web_contents_delegate_android.h index 68bca15..d375be9 100644 --- a/components/web_contents_delegate_android/web_contents_delegate_android.h +++ b/components/web_contents_delegate_android/web_contents_delegate_android.h @@ -57,12 +57,6 @@ class WebContentsDelegateAndroid : public content::WebContentsDelegate { SkColor color) OVERRIDE; virtual void NavigationStateChanged(const content::WebContents* source, unsigned changed_flags) OVERRIDE; - virtual void AddNewContents(content::WebContents* source, - content::WebContents* new_contents, - WindowOpenDisposition disposition, - const gfx::Rect& initial_pos, - bool user_gesture, - bool* was_blocked) OVERRIDE; virtual void ActivateContents(content::WebContents* contents) OVERRIDE; virtual void DeactivateContents(content::WebContents* contents) OVERRIDE; virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE; |