| OLD | NEW |
| 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/tab_android.h" | 5 #include "chrome/browser/android/tab_android.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
| 9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| 11 #include "chrome/browser/android/chrome_web_contents_delegate_android.h" | 11 #include "chrome/browser/android/chrome_web_contents_delegate_android.h" |
| 12 #include "chrome/browser/browser_about_handler.h" | 12 #include "chrome/browser/browser_about_handler.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 14 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 15 #include "chrome/browser/google/google_url_tracker_factory.h" | 15 #include "chrome/browser/google/google_url_tracker_factory.h" |
| 16 #include "chrome/browser/infobars/infobar_service.h" | 16 #include "chrome/browser/infobars/infobar_service.h" |
| 17 #include "chrome/browser/prerender/prerender_contents.h" | 17 #include "chrome/browser/prerender/prerender_contents.h" |
| 18 #include "chrome/browser/prerender/prerender_manager.h" | 18 #include "chrome/browser/prerender/prerender_manager.h" |
| 19 #include "chrome/browser/prerender/prerender_manager_factory.h" | 19 #include "chrome/browser/prerender/prerender_manager_factory.h" |
| 20 #include "chrome/browser/printing/print_view_manager_basic.h" | 20 #include "chrome/browser/printing/print_view_manager_basic.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/profiles/profile_android.h" | 22 #include "chrome/browser/profiles/profile_android.h" |
| 23 #include "chrome/browser/search/search.h" | 23 #include "chrome/browser/search/search.h" |
| 24 #include "chrome/browser/sessions/session_tab_helper.h" | 24 #include "chrome/browser/sessions/session_tab_helper.h" |
| 25 #include "chrome/browser/sync/glue/synced_tab_delegate_android.h" | 25 #include "chrome/browser/sync/glue/synced_tab_delegate_android.h" |
| 26 #include "chrome/browser/tab_contents/tab_util.h" |
| 26 #include "chrome/browser/ui/android/content_settings/popup_blocked_infobar_deleg
ate.h" | 27 #include "chrome/browser/ui/android/content_settings/popup_blocked_infobar_deleg
ate.h" |
| 27 #include "chrome/browser/ui/android/context_menu_helper.h" | 28 #include "chrome/browser/ui/android/context_menu_helper.h" |
| 28 #include "chrome/browser/ui/android/infobars/infobar_container_android.h" | 29 #include "chrome/browser/ui/android/infobars/infobar_container_android.h" |
| 29 #include "chrome/browser/ui/android/tab_model/tab_model.h" | 30 #include "chrome/browser/ui/android/tab_model/tab_model.h" |
| 30 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" | 31 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" |
| 31 #include "chrome/browser/ui/android/window_android_helper.h" | 32 #include "chrome/browser/ui/android/window_android_helper.h" |
| 32 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" | 33 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" |
| 33 #include "chrome/browser/ui/search/instant_search_prerenderer.h" | 34 #include "chrome/browser/ui/search/instant_search_prerenderer.h" |
| 34 #include "chrome/browser/ui/search/search_tab_helper.h" | 35 #include "chrome/browser/ui/search/search_tab_helper.h" |
| 35 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" | 36 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
| 36 #include "chrome/browser/ui/tab_helpers.h" | 37 #include "chrome/browser/ui/tab_helpers.h" |
| 37 #include "chrome/browser/ui/toolbar/toolbar_model_impl.h" | 38 #include "chrome/browser/ui/toolbar/toolbar_model_impl.h" |
| 38 #include "chrome/common/url_constants.h" | 39 #include "chrome/common/url_constants.h" |
| 39 #include "components/google/core/browser/google_url_tracker.h" | 40 #include "components/google/core/browser/google_url_tracker.h" |
| 40 #include "components/google/core/browser/google_util.h" | 41 #include "components/google/core/browser/google_util.h" |
| 41 #include "components/infobars/core/infobar_container.h" | 42 #include "components/infobars/core/infobar_container.h" |
| 42 #include "components/url_fixer/url_fixer.h" | 43 #include "components/url_fixer/url_fixer.h" |
| 43 #include "content/public/browser/android/content_view_core.h" | 44 #include "content/public/browser/android/content_view_core.h" |
| 44 #include "content/public/browser/navigation_entry.h" | 45 #include "content/public/browser/navigation_entry.h" |
| 45 #include "content/public/browser/notification_service.h" | 46 #include "content/public/browser/notification_service.h" |
| 46 #include "content/public/browser/user_metrics.h" | 47 #include "content/public/browser/user_metrics.h" |
| 47 #include "content/public/browser/web_contents.h" | 48 #include "content/public/browser/web_contents.h" |
| 48 #include "jni/Tab_jni.h" | 49 #include "jni/Tab_jni.h" |
| 49 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" | 50 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" |
| 51 #include "ui/base/window_open_disposition.h" |
| 52 |
| 53 using content::GlobalRequestID; |
| 54 using content::NavigationController; |
| 55 using content::WebContents; |
| 56 |
| 57 namespace { |
| 58 |
| 59 WebContents* CreateTargetContents(const chrome::NavigateParams& params, |
| 60 const GURL& url) { |
| 61 Profile* profile = params.initiating_profile; |
| 62 |
| 63 if (profile->IsOffTheRecord() || params.disposition == OFF_THE_RECORD) { |
| 64 profile = profile->GetOffTheRecordProfile(); |
| 65 } |
| 66 WebContents::CreateParams create_params( |
| 67 profile, tab_util::GetSiteInstanceForNewTab(profile, url)); |
| 68 if (params.source_contents) { |
| 69 create_params.initial_size = |
| 70 params.source_contents->GetContainerBounds().size(); |
| 71 if (params.should_set_opener) |
| 72 create_params.opener = params.source_contents; |
| 73 } |
| 74 if (params.disposition == NEW_BACKGROUND_TAB) |
| 75 create_params.initially_hidden = true; |
| 76 |
| 77 WebContents* target_contents = WebContents::Create(create_params); |
| 78 |
| 79 return target_contents; |
| 80 } |
| 81 |
| 82 } // namespace |
| 50 | 83 |
| 51 TabAndroid* TabAndroid::FromWebContents(content::WebContents* web_contents) { | 84 TabAndroid* TabAndroid::FromWebContents(content::WebContents* web_contents) { |
| 52 CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(web_contents); | 85 CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(web_contents); |
| 53 if (!core_tab_helper) | 86 if (!core_tab_helper) |
| 54 return NULL; | 87 return NULL; |
| 55 | 88 |
| 56 CoreTabHelperDelegate* core_delegate = core_tab_helper->delegate(); | 89 CoreTabHelperDelegate* core_delegate = core_tab_helper->delegate(); |
| 57 if (!core_delegate) | 90 if (!core_delegate) |
| 58 return NULL; | 91 return NULL; |
| 59 | 92 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 | 196 |
| 164 void TabAndroid::SetSyncId(int sync_id) { | 197 void TabAndroid::SetSyncId(int sync_id) { |
| 165 JNIEnv* env = base::android::AttachCurrentThread(); | 198 JNIEnv* env = base::android::AttachCurrentThread(); |
| 166 ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); | 199 ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); |
| 167 if (obj.is_null()) | 200 if (obj.is_null()) |
| 168 return; | 201 return; |
| 169 Java_Tab_setSyncId(env, obj.obj(), sync_id); | 202 Java_Tab_setSyncId(env, obj.obj(), sync_id); |
| 170 } | 203 } |
| 171 | 204 |
| 172 void TabAndroid::HandlePopupNavigation(chrome::NavigateParams* params) { | 205 void TabAndroid::HandlePopupNavigation(chrome::NavigateParams* params) { |
| 173 NOTIMPLEMENTED(); | 206 if (params->disposition != SUPPRESS_OPEN && |
| 207 params->disposition != SAVE_TO_DISK && |
| 208 params->disposition != IGNORE_ACTION) { |
| 209 if (!params->url.is_empty()) { |
| 210 bool was_blocked = false; |
| 211 GURL url(params->url); |
| 212 NavigationController::LoadURLParams load_url_params(url); |
| 213 MakeLoadURLParams(params, &load_url_params); |
| 214 if (params->disposition == CURRENT_TAB) { |
| 215 web_contents_.get()->GetController().LoadURLWithParams(load_url_params); |
| 216 } else { |
| 217 params->target_contents = CreateTargetContents(*params, url); |
| 218 params->target_contents->GetController().LoadURLWithParams( |
| 219 load_url_params); |
| 220 web_contents_delegate_->AddNewContents(params->source_contents, |
| 221 params->target_contents, |
| 222 params->disposition, |
| 223 params->window_bounds, |
| 224 params->user_gesture, |
| 225 &was_blocked); |
| 226 if (was_blocked) |
| 227 params->target_contents = NULL; |
| 228 } |
| 229 } |
| 230 } |
| 174 } | 231 } |
| 175 | 232 |
| 176 bool TabAndroid::ShouldWelcomePageLinkToTermsOfService() { | 233 bool TabAndroid::ShouldWelcomePageLinkToTermsOfService() { |
| 177 NOTIMPLEMENTED(); | 234 NOTIMPLEMENTED(); |
| 178 return false; | 235 return false; |
| 179 } | 236 } |
| 180 | 237 |
| 181 bool TabAndroid::HasPrerenderedUrl(GURL gurl) { | 238 bool TabAndroid::HasPrerenderedUrl(GURL gurl) { |
| 182 prerender::PrerenderManager* prerender_manager = GetPrerenderManager(); | 239 prerender::PrerenderManager* prerender_manager = GetPrerenderManager(); |
| 183 if (!prerender_manager) | 240 if (!prerender_manager) |
| 184 return false; | 241 return false; |
| 185 | 242 |
| 186 std::vector<content::WebContents*> contents = | 243 std::vector<content::WebContents*> contents = |
| 187 prerender_manager->GetAllPrerenderingContents(); | 244 prerender_manager->GetAllPrerenderingContents(); |
| 188 prerender::PrerenderContents* prerender_contents; | 245 prerender::PrerenderContents* prerender_contents; |
| 189 for (size_t i = 0; i < contents.size(); ++i) { | 246 for (size_t i = 0; i < contents.size(); ++i) { |
| 190 prerender_contents = prerender_manager-> | 247 prerender_contents = prerender_manager-> |
| 191 GetPrerenderContents(contents.at(i)); | 248 GetPrerenderContents(contents.at(i)); |
| 192 if (prerender_contents->prerender_url() == gurl && | 249 if (prerender_contents->prerender_url() == gurl && |
| 193 prerender_contents->has_finished_loading()) { | 250 prerender_contents->has_finished_loading()) { |
| 194 return true; | 251 return true; |
| 195 } | 252 } |
| 196 } | 253 } |
| 197 return false; | 254 return false; |
| 198 } | 255 } |
| 199 | 256 |
| 257 void TabAndroid::MakeLoadURLParams( |
| 258 chrome::NavigateParams* params, |
| 259 NavigationController::LoadURLParams* load_url_params) { |
| 260 load_url_params->referrer = params->referrer; |
| 261 load_url_params->frame_tree_node_id = params->frame_tree_node_id; |
| 262 load_url_params->redirect_chain = params->redirect_chain; |
| 263 load_url_params->transition_type = params->transition; |
| 264 load_url_params->extra_headers = params->extra_headers; |
| 265 load_url_params->should_replace_current_entry = |
| 266 params->should_replace_current_entry; |
| 267 |
| 268 if (params->transferred_global_request_id != GlobalRequestID()) { |
| 269 load_url_params->transferred_global_request_id = |
| 270 params->transferred_global_request_id; |
| 271 } |
| 272 load_url_params->is_renderer_initiated = params->is_renderer_initiated; |
| 273 |
| 274 // Only allows the browser-initiated navigation to use POST. |
| 275 if (params->uses_post && !params->is_renderer_initiated) { |
| 276 load_url_params->load_type = |
| 277 NavigationController::LOAD_TYPE_BROWSER_INITIATED_HTTP_POST; |
| 278 load_url_params->browser_initiated_post_data = |
| 279 params->browser_initiated_post_data; |
| 280 } |
| 281 } |
| 282 |
| 200 void TabAndroid::SwapTabContents(content::WebContents* old_contents, | 283 void TabAndroid::SwapTabContents(content::WebContents* old_contents, |
| 201 content::WebContents* new_contents, | 284 content::WebContents* new_contents, |
| 202 bool did_start_load, | 285 bool did_start_load, |
| 203 bool did_finish_load) { | 286 bool did_finish_load) { |
| 204 JNIEnv* env = base::android::AttachCurrentThread(); | 287 JNIEnv* env = base::android::AttachCurrentThread(); |
| 205 | 288 |
| 206 // We need to notify the native InfobarContainer so infobars can be swapped. | 289 // We need to notify the native InfobarContainer so infobars can be swapped. |
| 207 InfoBarContainerAndroid* infobar_container = | 290 InfoBarContainerAndroid* infobar_container = |
| 208 reinterpret_cast<InfoBarContainerAndroid*>( | 291 reinterpret_cast<InfoBarContainerAndroid*>( |
| 209 Java_Tab_getNativeInfoBarContainer( | 292 Java_Tab_getNativeInfoBarContainer( |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 | 603 |
| 521 static void Init(JNIEnv* env, jobject obj) { | 604 static void Init(JNIEnv* env, jobject obj) { |
| 522 TRACE_EVENT0("native", "TabAndroid::Init"); | 605 TRACE_EVENT0("native", "TabAndroid::Init"); |
| 523 // This will automatically bind to the Java object and pass ownership there. | 606 // This will automatically bind to the Java object and pass ownership there. |
| 524 new TabAndroid(env, obj); | 607 new TabAndroid(env, obj); |
| 525 } | 608 } |
| 526 | 609 |
| 527 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { | 610 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { |
| 528 return RegisterNativesImpl(env); | 611 return RegisterNativesImpl(env); |
| 529 } | 612 } |
| OLD | NEW |