| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/instant/instant_controller.h" | 5 #include "chrome/browser/instant/instant_controller.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "chrome/browser/autocomplete/autocomplete_match.h" | 13 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 14 #include "chrome/browser/instant/instant_delegate.h" | 14 #include "chrome/browser/instant/instant_delegate.h" |
| 15 #include "chrome/browser/instant/instant_field_trial.h" | 15 #include "chrome/browser/instant/instant_field_trial.h" |
| 16 #include "chrome/browser/instant/instant_loader.h" | 16 #include "chrome/browser/instant/instant_loader.h" |
| 17 #include "chrome/browser/instant/promo_counter.h" | 17 #include "chrome/browser/instant/promo_counter.h" |
| 18 #include "chrome/browser/platform_util.h" | 18 #include "chrome/browser/platform_util.h" |
| 19 #include "chrome/browser/prefs/pref_service.h" | 19 #include "chrome/browser/prefs/pref_service.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/search_engines/template_url.h" | 21 #include "chrome/browser/search_engines/template_url.h" |
| 22 #include "chrome/browser/search_engines/template_url_service.h" | 22 #include "chrome/browser/search_engines/template_url_service.h" |
| 23 #include "chrome/browser/search_engines/template_url_service_factory.h" | 23 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 24 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" | 24 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" |
| 25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 26 #include "chrome/common/chrome_notification_types.h" | 26 #include "chrome/common/chrome_notification_types.h" |
| 27 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
| 28 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
| 29 #include "content/browser/renderer_host/render_widget_host_view.h" | 29 #include "content/browser/renderer_host/render_widget_host_view.h" |
| 30 #include "content/browser/tab_contents/tab_contents.h" | |
| 31 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
| 31 #include "content/public/browser/web_contents.h" |
| 32 | 32 |
| 33 #if defined(TOOLKIT_VIEWS) | 33 #if defined(TOOLKIT_VIEWS) |
| 34 #include "ui/views/focus/focus_manager.h" | 34 #include "ui/views/focus/focus_manager.h" |
| 35 #include "ui/views/view.h" | 35 #include "ui/views/view.h" |
| 36 #include "ui/views/widget/widget.h" | 36 #include "ui/views/widget/widget.h" |
| 37 #endif | 37 #endif |
| 38 | 38 |
| 39 InstantController::InstantController(Profile* profile, | 39 InstantController::InstantController(Profile* profile, |
| 40 InstantDelegate* delegate) | 40 InstantDelegate* delegate) |
| 41 : delegate_(delegate), | 41 : delegate_(delegate), |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 string16 suggested_text; | 262 string16 suggested_text; |
| 263 UpdateLoader(template_url, last_url_, last_transition_type_, last_user_text_, | 263 UpdateLoader(template_url, last_url_, last_transition_type_, last_user_text_, |
| 264 true, &suggested_text); | 264 true, &suggested_text); |
| 265 return true; | 265 return true; |
| 266 } | 266 } |
| 267 | 267 |
| 268 TabContentsWrapper* InstantController::CommitCurrentPreview( | 268 TabContentsWrapper* InstantController::CommitCurrentPreview( |
| 269 InstantCommitType type) { | 269 InstantCommitType type) { |
| 270 DCHECK(loader_.get()); | 270 DCHECK(loader_.get()); |
| 271 TabContentsWrapper* tab = ReleasePreviewContents(type); | 271 TabContentsWrapper* tab = ReleasePreviewContents(type); |
| 272 tab->tab_contents()->GetController().CopyStateFromAndPrune( | 272 tab->web_contents()->GetController().CopyStateFromAndPrune( |
| 273 &tab_contents_->tab_contents()->GetController()); | 273 &tab_contents_->web_contents()->GetController()); |
| 274 delegate_->CommitInstant(tab); | 274 delegate_->CommitInstant(tab); |
| 275 CompleteRelease(tab); | 275 CompleteRelease(tab); |
| 276 return tab; | 276 return tab; |
| 277 } | 277 } |
| 278 | 278 |
| 279 void InstantController::SetCommitOnMouseUp() { | 279 void InstantController::SetCommitOnMouseUp() { |
| 280 commit_on_mouse_up_ = true; | 280 commit_on_mouse_up_ = true; |
| 281 } | 281 } |
| 282 | 282 |
| 283 bool InstantController::IsMouseDownFromActivate() { | 283 bool InstantController::IsMouseDownFromActivate() { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 298 } | 298 } |
| 299 #else | 299 #else |
| 300 void InstantController::OnAutocompleteLostFocus( | 300 void InstantController::OnAutocompleteLostFocus( |
| 301 gfx::NativeView view_gaining_focus) { | 301 gfx::NativeView view_gaining_focus) { |
| 302 if (!IsCurrent()) { | 302 if (!IsCurrent()) { |
| 303 DestroyPreviewContents(); | 303 DestroyPreviewContents(); |
| 304 return; | 304 return; |
| 305 } | 305 } |
| 306 | 306 |
| 307 RenderWidgetHostView* rwhv = | 307 RenderWidgetHostView* rwhv = |
| 308 GetPreviewContents()->tab_contents()->GetRenderWidgetHostView(); | 308 GetPreviewContents()->web_contents()->GetRenderWidgetHostView(); |
| 309 if (!view_gaining_focus || !rwhv) { | 309 if (!view_gaining_focus || !rwhv) { |
| 310 DestroyPreviewContents(); | 310 DestroyPreviewContents(); |
| 311 return; | 311 return; |
| 312 } | 312 } |
| 313 | 313 |
| 314 #if defined(TOOLKIT_VIEWS) | 314 #if defined(TOOLKIT_VIEWS) |
| 315 // For views the top level widget is always focused. If the focus change | 315 // For views the top level widget is always focused. If the focus change |
| 316 // originated in views determine the child Widget from the view that is being | 316 // originated in views determine the child Widget from the view that is being |
| 317 // focused. | 317 // focused. |
| 318 if (view_gaining_focus) { | 318 if (view_gaining_focus) { |
| 319 views::Widget* widget = | 319 views::Widget* widget = |
| 320 views::Widget::GetWidgetForNativeView(view_gaining_focus); | 320 views::Widget::GetWidgetForNativeView(view_gaining_focus); |
| 321 if (widget) { | 321 if (widget) { |
| 322 views::FocusManager* focus_manager = widget->GetFocusManager(); | 322 views::FocusManager* focus_manager = widget->GetFocusManager(); |
| 323 if (focus_manager && focus_manager->is_changing_focus() && | 323 if (focus_manager && focus_manager->is_changing_focus() && |
| 324 focus_manager->GetFocusedView() && | 324 focus_manager->GetFocusedView() && |
| 325 focus_manager->GetFocusedView()->GetWidget()) { | 325 focus_manager->GetFocusedView()->GetWidget()) { |
| 326 view_gaining_focus = | 326 view_gaining_focus = |
| 327 focus_manager->GetFocusedView()->GetWidget()->GetNativeView(); | 327 focus_manager->GetFocusedView()->GetWidget()->GetNativeView(); |
| 328 } | 328 } |
| 329 } | 329 } |
| 330 } | 330 } |
| 331 #endif | 331 #endif |
| 332 | 332 |
| 333 gfx::NativeView tab_view = | 333 gfx::NativeView tab_view = |
| 334 GetPreviewContents()->tab_contents()->GetNativeView(); | 334 GetPreviewContents()->web_contents()->GetNativeView(); |
| 335 // Focus is going to the renderer. | 335 // Focus is going to the renderer. |
| 336 if (rwhv->GetNativeView() == view_gaining_focus || | 336 if (rwhv->GetNativeView() == view_gaining_focus || |
| 337 tab_view == view_gaining_focus) { | 337 tab_view == view_gaining_focus) { |
| 338 if (!IsMouseDownFromActivate()) { | 338 if (!IsMouseDownFromActivate()) { |
| 339 // If the mouse is not down, focus is not going to the renderer. Someone | 339 // If the mouse is not down, focus is not going to the renderer. Someone |
| 340 // else moved focus and we shouldn't commit. | 340 // else moved focus and we shouldn't commit. |
| 341 DestroyPreviewContents(); | 341 DestroyPreviewContents(); |
| 342 return; | 342 return; |
| 343 } | 343 } |
| 344 | 344 |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 if (!weak_factory_.HasWeakPtrs()) { | 555 if (!weak_factory_.HasWeakPtrs()) { |
| 556 MessageLoop::current()->PostTask( | 556 MessageLoop::current()->PostTask( |
| 557 FROM_HERE, base::Bind(&InstantController::DestroyLoaders, | 557 FROM_HERE, base::Bind(&InstantController::DestroyLoaders, |
| 558 weak_factory_.GetWeakPtr())); | 558 weak_factory_.GetWeakPtr())); |
| 559 } | 559 } |
| 560 } | 560 } |
| 561 | 561 |
| 562 void InstantController::DestroyLoaders() { | 562 void InstantController::DestroyLoaders() { |
| 563 loaders_to_destroy_.reset(); | 563 loaders_to_destroy_.reset(); |
| 564 } | 564 } |
| OLD | NEW |