Chromium Code Reviews| 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, | |
| 68 tab_util::GetSiteInstanceForNewTab(profile, url)); | |
| 69 if (params.source_contents) { | |
| 70 create_params.initial_size = | |
| 71 params.source_contents->GetContainerBounds().size(); | |
| 72 if (params.should_set_opener) | |
| 73 create_params.opener = params.source_contents; | |
| 74 } | |
| 75 if (params.disposition == NEW_BACKGROUND_TAB) | |
| 76 create_params.initially_hidden = true; | |
| 77 | |
| 78 WebContents* target_contents = WebContents::Create(create_params); | |
| 79 | |
| 80 return target_contents; | |
| 81 } | |
| 82 | |
| 83 } // namespace | |
| 50 | 84 |
| 51 TabAndroid* TabAndroid::FromWebContents(content::WebContents* web_contents) { | 85 TabAndroid* TabAndroid::FromWebContents(content::WebContents* web_contents) { |
| 52 CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(web_contents); | 86 CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(web_contents); |
| 53 if (!core_tab_helper) | 87 if (!core_tab_helper) |
| 54 return NULL; | 88 return NULL; |
| 55 | 89 |
| 56 CoreTabHelperDelegate* core_delegate = core_tab_helper->delegate(); | 90 CoreTabHelperDelegate* core_delegate = core_tab_helper->delegate(); |
| 57 if (!core_delegate) | 91 if (!core_delegate) |
| 58 return NULL; | 92 return NULL; |
| 59 | 93 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 | 197 |
| 164 void TabAndroid::SetSyncId(int sync_id) { | 198 void TabAndroid::SetSyncId(int sync_id) { |
| 165 JNIEnv* env = base::android::AttachCurrentThread(); | 199 JNIEnv* env = base::android::AttachCurrentThread(); |
| 166 ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); | 200 ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); |
| 167 if (obj.is_null()) | 201 if (obj.is_null()) |
| 168 return; | 202 return; |
| 169 Java_Tab_setSyncId(env, obj.obj(), sync_id); | 203 Java_Tab_setSyncId(env, obj.obj(), sync_id); |
| 170 } | 204 } |
| 171 | 205 |
| 172 void TabAndroid::HandlePopupNavigation(chrome::NavigateParams* params) { | 206 void TabAndroid::HandlePopupNavigation(chrome::NavigateParams* params) { |
| 173 NOTIMPLEMENTED(); | 207 if (params->disposition != SUPPRESS_OPEN && |
|
David Trainor- moved to gerrit
2014/07/16 15:29:24
there is a dcheck for params->disposition != CURRE
Jitu( very slow this week)
2014/07/17 13:26:02
Done.
| |
| 208 params->disposition != SAVE_TO_DISK && | |
| 209 params->disposition != IGNORE_ACTION) { | |
| 210 if (!params->url.is_empty()) { | |
| 211 bool was_blocked = false; | |
| 212 GURL url(params->url); | |
| 213 params->target_contents = CreateTargetContents(*params, url); | |
| 214 NavigationController::LoadURLParams load_url_params(url); | |
| 215 MakeLoadURLParams(params, &load_url_params); | |
| 216 params->target_contents->GetController().LoadURLWithParams( | |
| 217 load_url_params); | |
| 218 web_contents_delegate_->AddNewContents(params->source_contents, | |
| 219 params->target_contents, | |
| 220 params->disposition, | |
| 221 params->window_bounds, | |
| 222 params->user_gesture, | |
| 223 &was_blocked); | |
| 224 if (was_blocked) | |
| 225 params->target_contents = NULL; | |
| 226 } | |
| 227 } | |
| 174 } | 228 } |
| 175 | 229 |
| 176 bool TabAndroid::ShouldWelcomePageLinkToTermsOfService() { | 230 bool TabAndroid::ShouldWelcomePageLinkToTermsOfService() { |
| 177 NOTIMPLEMENTED(); | 231 NOTIMPLEMENTED(); |
| 178 return false; | 232 return false; |
| 179 } | 233 } |
| 180 | 234 |
| 181 bool TabAndroid::HasPrerenderedUrl(GURL gurl) { | 235 bool TabAndroid::HasPrerenderedUrl(GURL gurl) { |
| 182 prerender::PrerenderManager* prerender_manager = GetPrerenderManager(); | 236 prerender::PrerenderManager* prerender_manager = GetPrerenderManager(); |
| 183 if (!prerender_manager) | 237 if (!prerender_manager) |
| 184 return false; | 238 return false; |
| 185 | 239 |
| 186 std::vector<content::WebContents*> contents = | 240 std::vector<content::WebContents*> contents = |
| 187 prerender_manager->GetAllPrerenderingContents(); | 241 prerender_manager->GetAllPrerenderingContents(); |
| 188 prerender::PrerenderContents* prerender_contents; | 242 prerender::PrerenderContents* prerender_contents; |
| 189 for (size_t i = 0; i < contents.size(); ++i) { | 243 for (size_t i = 0; i < contents.size(); ++i) { |
| 190 prerender_contents = prerender_manager-> | 244 prerender_contents = prerender_manager-> |
| 191 GetPrerenderContents(contents.at(i)); | 245 GetPrerenderContents(contents.at(i)); |
| 192 if (prerender_contents->prerender_url() == gurl && | 246 if (prerender_contents->prerender_url() == gurl && |
| 193 prerender_contents->has_finished_loading()) { | 247 prerender_contents->has_finished_loading()) { |
| 194 return true; | 248 return true; |
| 195 } | 249 } |
| 196 } | 250 } |
| 197 return false; | 251 return false; |
| 198 } | 252 } |
| 199 | 253 |
| 254 void TabAndroid::MakeLoadURLParams( | |
| 255 chrome::NavigateParams* params, | |
| 256 NavigationController::LoadURLParams* load_url_params) { | |
| 257 load_url_params->referrer = params->referrer; | |
| 258 load_url_params->frame_tree_node_id = params->frame_tree_node_id; | |
| 259 load_url_params->redirect_chain = params->redirect_chain; | |
| 260 load_url_params->transition_type = params->transition; | |
| 261 load_url_params->extra_headers = params->extra_headers; | |
| 262 load_url_params->should_replace_current_entry = | |
| 263 params->should_replace_current_entry; | |
| 264 | |
| 265 if (params->transferred_global_request_id != GlobalRequestID()) { | |
| 266 load_url_params->transferred_global_request_id = | |
| 267 params->transferred_global_request_id; | |
| 268 } | |
| 269 load_url_params->is_renderer_initiated = params->is_renderer_initiated; | |
|
David Trainor- moved to gerrit
2014/07/16 15:29:23
fix indentation
Jitu( very slow this week)
2014/07/17 13:26:02
Done.
| |
| 270 | |
| 271 // Only allows the browser-initiated navigation to use POST. | |
| 272 if (params->uses_post && !params->is_renderer_initiated) { | |
| 273 load_url_params->load_type = | |
| 274 NavigationController::LOAD_TYPE_BROWSER_INITIATED_HTTP_POST; | |
| 275 load_url_params->browser_initiated_post_data = | |
| 276 params->browser_initiated_post_data; | |
| 277 } | |
| 278 } | |
| 279 | |
| 200 void TabAndroid::SwapTabContents(content::WebContents* old_contents, | 280 void TabAndroid::SwapTabContents(content::WebContents* old_contents, |
| 201 content::WebContents* new_contents, | 281 content::WebContents* new_contents, |
| 202 bool did_start_load, | 282 bool did_start_load, |
| 203 bool did_finish_load) { | 283 bool did_finish_load) { |
| 204 JNIEnv* env = base::android::AttachCurrentThread(); | 284 JNIEnv* env = base::android::AttachCurrentThread(); |
| 205 | 285 |
| 206 // We need to notify the native InfobarContainer so infobars can be swapped. | 286 // We need to notify the native InfobarContainer so infobars can be swapped. |
| 207 InfoBarContainerAndroid* infobar_container = | 287 InfoBarContainerAndroid* infobar_container = |
| 208 reinterpret_cast<InfoBarContainerAndroid*>( | 288 reinterpret_cast<InfoBarContainerAndroid*>( |
| 209 Java_Tab_getNativeInfoBarContainer( | 289 Java_Tab_getNativeInfoBarContainer( |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 520 | 600 |
| 521 static void Init(JNIEnv* env, jobject obj) { | 601 static void Init(JNIEnv* env, jobject obj) { |
| 522 TRACE_EVENT0("native", "TabAndroid::Init"); | 602 TRACE_EVENT0("native", "TabAndroid::Init"); |
| 523 // This will automatically bind to the Java object and pass ownership there. | 603 // This will automatically bind to the Java object and pass ownership there. |
| 524 new TabAndroid(env, obj); | 604 new TabAndroid(env, obj); |
| 525 } | 605 } |
| 526 | 606 |
| 527 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { | 607 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { |
| 528 return RegisterNativesImpl(env); | 608 return RegisterNativesImpl(env); |
| 529 } | 609 } |
| OLD | NEW |