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" |
| 50 | 51 |
| 52 using content::GlobalRequestID; | |
| 53 using content::NavigationController; | |
| 54 using content::WebContents; | |
| 55 | |
| 56 namespace { | |
| 57 | |
| 58 WebContents* CreateTargetContents(const chrome::NavigateParams& params, | |
| 59 const GURL& url) { | |
| 60 WebContents::CreateParams create_params( | |
| 61 params.initiating_profile, | |
|
David Trainor- moved to gerrit
2014/07/15 20:34:35
Is this the right profile? What if we're opening
Jitu( very slow this week)
2014/07/16 14:17:49
We are assuming that params.initiating_profile giv
| |
| 62 tab_util::GetSiteInstanceForNewTab(params.initiating_profile, url)); | |
| 63 if (params.source_contents) { | |
| 64 create_params.initial_size = | |
| 65 params.source_contents->GetContainerBounds().size(); | |
| 66 if (params.should_set_opener) | |
| 67 create_params.opener = params.source_contents; | |
| 68 } | |
| 69 if (params.disposition == NEW_BACKGROUND_TAB) | |
| 70 create_params.initially_hidden = true; | |
| 71 | |
| 72 WebContents* target_contents = WebContents::Create(create_params); | |
| 73 | |
| 74 // New tabs can have WebUI URLs that will make calls back to arbitrary | |
| 75 // tab helpers, so the entire set of tab helpers needs to be set up | |
| 76 // immediately. | |
| 77 TabAndroid::AttachTabHelpers(target_contents); | |
|
David Trainor- moved to gerrit
2014/07/15 20:34:35
ChromeWebContentsDelegateAndroid::AddNewContents()
Jitu( very slow this week)
2014/07/16 14:17:49
Done.
| |
| 78 return target_contents; | |
| 79 } | |
| 80 | |
| 81 } // namespace | |
| 82 | |
| 51 TabAndroid* TabAndroid::FromWebContents(content::WebContents* web_contents) { | 83 TabAndroid* TabAndroid::FromWebContents(content::WebContents* web_contents) { |
| 52 CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(web_contents); | 84 CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(web_contents); |
| 53 if (!core_tab_helper) | 85 if (!core_tab_helper) |
| 54 return NULL; | 86 return NULL; |
| 55 | 87 |
| 56 CoreTabHelperDelegate* core_delegate = core_tab_helper->delegate(); | 88 CoreTabHelperDelegate* core_delegate = core_tab_helper->delegate(); |
| 57 if (!core_delegate) | 89 if (!core_delegate) |
| 58 return NULL; | 90 return NULL; |
| 59 | 91 |
| 60 return static_cast<TabAndroid*>(core_delegate); | 92 return static_cast<TabAndroid*>(core_delegate); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 } | 194 } |
| 163 | 195 |
| 164 void TabAndroid::SetSyncId(int sync_id) { | 196 void TabAndroid::SetSyncId(int sync_id) { |
| 165 JNIEnv* env = base::android::AttachCurrentThread(); | 197 JNIEnv* env = base::android::AttachCurrentThread(); |
| 166 ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); | 198 ScopedJavaLocalRef<jobject> obj = weak_java_tab_.get(env); |
| 167 if (obj.is_null()) | 199 if (obj.is_null()) |
| 168 return; | 200 return; |
| 169 Java_Tab_setSyncId(env, obj.obj(), sync_id); | 201 Java_Tab_setSyncId(env, obj.obj(), sync_id); |
| 170 } | 202 } |
| 171 | 203 |
| 172 void TabAndroid::HandlePopupNavigation(chrome::NavigateParams* params) { | 204 void TabAndroid::HandlePopupNavigation(chrome::NavigateParams* params) { |
|
David Trainor- moved to gerrit
2014/07/15 20:34:35
Should we check disposition here? There are some
Jitu( very slow this week)
2014/07/16 14:17:49
Done.
PTAL
| |
| 173 NOTIMPLEMENTED(); | 205 if (!params->url.is_empty()) { |
| 206 bool was_blocked = false; | |
| 207 GURL url = params->url; | |
|
David Trainor- moved to gerrit
2014/07/15 20:34:35
GURL url(params->url)?
Jitu( very slow this week)
2014/07/16 14:17:49
Done.
| |
| 208 params->target_contents = CreateTargetContents(*params, url); | |
| 209 NavigationController::LoadURLParams load_url_params(url); | |
| 210 MakeLoadURLParams(params, &load_url_params); | |
| 211 params->target_contents->GetController().LoadURLWithParams(load_url_params); | |
| 212 web_contents_delegate_->AddNewContents(params->source_contents, | |
| 213 params->target_contents, | |
| 214 params->disposition, | |
| 215 params->window_bounds, | |
| 216 params->user_gesture, | |
| 217 &was_blocked); | |
| 218 if (was_blocked) | |
| 219 params->target_contents = NULL; | |
| 220 } | |
| 174 } | 221 } |
| 175 | 222 |
| 176 bool TabAndroid::ShouldWelcomePageLinkToTermsOfService() { | 223 bool TabAndroid::ShouldWelcomePageLinkToTermsOfService() { |
| 177 NOTIMPLEMENTED(); | 224 NOTIMPLEMENTED(); |
| 178 return false; | 225 return false; |
| 179 } | 226 } |
| 180 | 227 |
| 181 bool TabAndroid::HasPrerenderedUrl(GURL gurl) { | 228 bool TabAndroid::HasPrerenderedUrl(GURL gurl) { |
| 182 prerender::PrerenderManager* prerender_manager = GetPrerenderManager(); | 229 prerender::PrerenderManager* prerender_manager = GetPrerenderManager(); |
| 183 if (!prerender_manager) | 230 if (!prerender_manager) |
| 184 return false; | 231 return false; |
| 185 | 232 |
| 186 std::vector<content::WebContents*> contents = | 233 std::vector<content::WebContents*> contents = |
| 187 prerender_manager->GetAllPrerenderingContents(); | 234 prerender_manager->GetAllPrerenderingContents(); |
| 188 prerender::PrerenderContents* prerender_contents; | 235 prerender::PrerenderContents* prerender_contents; |
| 189 for (size_t i = 0; i < contents.size(); ++i) { | 236 for (size_t i = 0; i < contents.size(); ++i) { |
| 190 prerender_contents = prerender_manager-> | 237 prerender_contents = prerender_manager-> |
| 191 GetPrerenderContents(contents.at(i)); | 238 GetPrerenderContents(contents.at(i)); |
| 192 if (prerender_contents->prerender_url() == gurl && | 239 if (prerender_contents->prerender_url() == gurl && |
| 193 prerender_contents->has_finished_loading()) { | 240 prerender_contents->has_finished_loading()) { |
| 194 return true; | 241 return true; |
| 195 } | 242 } |
| 196 } | 243 } |
| 197 return false; | 244 return false; |
| 198 } | 245 } |
| 199 | 246 |
| 247 void TabAndroid::MakeLoadURLParams( | |
| 248 chrome::NavigateParams* params, | |
| 249 NavigationController::LoadURLParams* load_url_params) { | |
| 250 load_url_params->referrer = params->referrer; | |
| 251 load_url_params->frame_tree_node_id = params->frame_tree_node_id; | |
| 252 load_url_params->redirect_chain = params->redirect_chain; | |
| 253 load_url_params->transition_type = params->transition; | |
| 254 load_url_params->extra_headers = params->extra_headers; | |
| 255 load_url_params->should_replace_current_entry = | |
| 256 params->should_replace_current_entry; | |
| 257 | |
| 258 if (params->transferred_global_request_id != GlobalRequestID()) { | |
| 259 load_url_params->is_renderer_initiated = params->is_renderer_initiated; | |
|
David Trainor- moved to gerrit
2014/07/15 20:34:35
Can we just pull this line out of the if block? W
Jitu( very slow this week)
2014/07/16 14:17:49
Done.
| |
| 260 load_url_params->transferred_global_request_id = | |
| 261 params->transferred_global_request_id; | |
| 262 } else if (params->is_renderer_initiated) { | |
| 263 load_url_params->is_renderer_initiated = true; | |
| 264 } | |
| 265 | |
| 266 // Only allows the browser-initiated navigation to use POST. | |
| 267 if (params->uses_post && !params->is_renderer_initiated) { | |
| 268 load_url_params->load_type = | |
| 269 NavigationController::LOAD_TYPE_BROWSER_INITIATED_HTTP_POST; | |
| 270 load_url_params->browser_initiated_post_data = | |
| 271 params->browser_initiated_post_data; | |
| 272 } | |
| 273 } | |
| 274 | |
| 200 void TabAndroid::SwapTabContents(content::WebContents* old_contents, | 275 void TabAndroid::SwapTabContents(content::WebContents* old_contents, |
| 201 content::WebContents* new_contents, | 276 content::WebContents* new_contents, |
| 202 bool did_start_load, | 277 bool did_start_load, |
| 203 bool did_finish_load) { | 278 bool did_finish_load) { |
| 204 JNIEnv* env = base::android::AttachCurrentThread(); | 279 JNIEnv* env = base::android::AttachCurrentThread(); |
| 205 | 280 |
| 206 // We need to notify the native InfobarContainer so infobars can be swapped. | 281 // We need to notify the native InfobarContainer so infobars can be swapped. |
| 207 InfoBarContainerAndroid* infobar_container = | 282 InfoBarContainerAndroid* infobar_container = |
| 208 reinterpret_cast<InfoBarContainerAndroid*>( | 283 reinterpret_cast<InfoBarContainerAndroid*>( |
| 209 Java_Tab_getNativeInfoBarContainer( | 284 Java_Tab_getNativeInfoBarContainer( |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 520 | 595 |
| 521 static void Init(JNIEnv* env, jobject obj) { | 596 static void Init(JNIEnv* env, jobject obj) { |
| 522 TRACE_EVENT0("native", "TabAndroid::Init"); | 597 TRACE_EVENT0("native", "TabAndroid::Init"); |
| 523 // This will automatically bind to the Java object and pass ownership there. | 598 // This will automatically bind to the Java object and pass ownership there. |
| 524 new TabAndroid(env, obj); | 599 new TabAndroid(env, obj); |
| 525 } | 600 } |
| 526 | 601 |
| 527 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { | 602 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { |
| 528 return RegisterNativesImpl(env); | 603 return RegisterNativesImpl(env); |
| 529 } | 604 } |
| OLD | NEW |