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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
12 #include "chrome/browser/autocomplete/autocomplete_match.h" | 12 #include "chrome/browser/autocomplete/autocomplete_match.h" |
13 #include "chrome/browser/instant/instant_delegate.h" | 13 #include "chrome/browser/instant/instant_delegate.h" |
14 #include "chrome/browser/instant/instant_field_trial.h" | 14 #include "chrome/browser/instant/instant_field_trial.h" |
15 #include "chrome/browser/instant/instant_loader.h" | 15 #include "chrome/browser/instant/instant_loader.h" |
16 #include "chrome/browser/instant/promo_counter.h" | 16 #include "chrome/browser/instant/promo_counter.h" |
17 #include "chrome/browser/platform_util.h" | 17 #include "chrome/browser/platform_util.h" |
18 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/search_engines/template_url.h" | 20 #include "chrome/browser/search_engines/template_url.h" |
21 #include "chrome/browser/search_engines/template_url_service.h" | 21 #include "chrome/browser/search_engines/template_url_service.h" |
22 #include "chrome/browser/search_engines/template_url_service_factory.h" | 22 #include "chrome/browser/search_engines/template_url_service_factory.h" |
23 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" | 23 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" |
24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
25 #include "chrome/common/chrome_notification_types.h" | 25 #include "chrome/common/chrome_notification_types.h" |
26 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
27 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
28 #include "content/browser/renderer_host/render_widget_host_view.h" | 28 #include "content/browser/renderer_host/render_widget_host_view.h" |
29 #include "content/browser/tab_contents/tab_contents.h" | 29 #include "content/browser/tab_contents/tab_contents.h" |
30 #include "content/common/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
31 | 31 |
32 #if defined(TOOLKIT_VIEWS) | 32 #if defined(TOOLKIT_VIEWS) |
33 #include "views/focus/focus_manager.h" | 33 #include "views/focus/focus_manager.h" |
34 #include "views/view.h" | 34 #include "views/view.h" |
35 #include "views/widget/widget.h" | 35 #include "views/widget/widget.h" |
36 #endif | 36 #endif |
37 | 37 |
38 InstantController::InstantController(Profile* profile, | 38 InstantController::InstantController(Profile* profile, |
39 InstantDelegate* delegate) | 39 InstantDelegate* delegate) |
40 : delegate_(delegate), | 40 : delegate_(delegate), |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 // For the HIDDEN field trial we process |user_text| at commit time, which | 179 // For the HIDDEN field trial we process |user_text| at commit time, which |
180 // means we're never really out of date. | 180 // means we're never really out of date. |
181 is_out_of_date_ = false; | 181 is_out_of_date_ = false; |
182 loader_->MaybeLoadInstantURL(tab_contents, template_url); | 182 loader_->MaybeLoadInstantURL(tab_contents, template_url); |
183 return true; | 183 return true; |
184 } | 184 } |
185 | 185 |
186 UpdateLoader(template_url, match.destination_url, match.transition, user_text, | 186 UpdateLoader(template_url, match.destination_url, match.transition, user_text, |
187 verbatim, suggested_text); | 187 verbatim, suggested_text); |
188 | 188 |
189 NotificationService::current()->Notify( | 189 content::NotificationService::current()->Notify( |
190 chrome::NOTIFICATION_INSTANT_CONTROLLER_UPDATED, | 190 chrome::NOTIFICATION_INSTANT_CONTROLLER_UPDATED, |
191 content::Source<InstantController>(this), | 191 content::Source<InstantController>(this), |
192 NotificationService::NoDetails()); | 192 content::NotificationService::NoDetails()); |
193 return true; | 193 return true; |
194 } | 194 } |
195 | 195 |
196 void InstantController::SetOmniboxBounds(const gfx::Rect& bounds) { | 196 void InstantController::SetOmniboxBounds(const gfx::Rect& bounds) { |
197 if (omnibox_bounds_ == bounds) | 197 if (omnibox_bounds_ == bounds) |
198 return; | 198 return; |
199 | 199 |
200 // Always track the omnibox bounds. That way if Update is later invoked the | 200 // Always track the omnibox bounds. That way if Update is later invoked the |
201 // bounds are in sync. | 201 // bounds are in sync. |
202 omnibox_bounds_ = bounds; | 202 omnibox_bounds_ = bounds; |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 (!is_out_of_date_ && loader_.get() && loader_->ready() && | 464 (!is_out_of_date_ && loader_.get() && loader_->ready() && |
465 loader_->http_status_ok()); | 465 loader_->http_status_ok()); |
466 if (displayable == is_displayable_) | 466 if (displayable == is_displayable_) |
467 return; | 467 return; |
468 | 468 |
469 is_displayable_ = displayable; | 469 is_displayable_ = displayable; |
470 if (!is_displayable_) { | 470 if (!is_displayable_) { |
471 delegate_->HideInstant(); | 471 delegate_->HideInstant(); |
472 } else { | 472 } else { |
473 delegate_->ShowInstant(loader_->preview_contents()); | 473 delegate_->ShowInstant(loader_->preview_contents()); |
474 NotificationService::current()->Notify( | 474 content::NotificationService::current()->Notify( |
475 chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN, | 475 chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN, |
476 content::Source<InstantController>(this), | 476 content::Source<InstantController>(this), |
477 NotificationService::NoDetails()); | 477 content::NotificationService::NoDetails()); |
478 } | 478 } |
479 } | 479 } |
480 | 480 |
481 void InstantController::UpdateLoader(const TemplateURL* template_url, | 481 void InstantController::UpdateLoader(const TemplateURL* template_url, |
482 const GURL& url, | 482 const GURL& url, |
483 content::PageTransition transition_type, | 483 content::PageTransition transition_type, |
484 const string16& user_text, | 484 const string16& user_text, |
485 bool verbatim, | 485 bool verbatim, |
486 string16* suggested_text) { | 486 string16* suggested_text) { |
487 is_out_of_date_ = false; | 487 is_out_of_date_ = false; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 if (destroy_factory_.empty()) { | 537 if (destroy_factory_.empty()) { |
538 MessageLoop::current()->PostTask( | 538 MessageLoop::current()->PostTask( |
539 FROM_HERE, destroy_factory_.NewRunnableMethod( | 539 FROM_HERE, destroy_factory_.NewRunnableMethod( |
540 &InstantController::DestroyLoaders)); | 540 &InstantController::DestroyLoaders)); |
541 } | 541 } |
542 } | 542 } |
543 | 543 |
544 void InstantController::DestroyLoaders() { | 544 void InstantController::DestroyLoaders() { |
545 loaders_to_destroy_.reset(); | 545 loaders_to_destroy_.reset(); |
546 } | 546 } |
OLD | NEW |