OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/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/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "chrome/browser/ui/browser_instant_controller.h" | 23 #include "chrome/browser/ui/browser_instant_controller.h" |
24 #include "chrome/browser/ui/search/search.h" | 24 #include "chrome/browser/ui/search/search.h" |
25 #include "chrome/browser/ui/search/search_tab_helper.h" | 25 #include "chrome/browser/ui/search/search_tab_helper.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/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
29 #include "content/public/browser/navigation_entry.h" | 29 #include "content/public/browser/navigation_entry.h" |
30 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
31 #include "content/public/browser/render_widget_host_view.h" | 31 #include "content/public/browser/render_widget_host_view.h" |
32 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
| 33 #include "content/public/browser/web_contents_view.h" |
33 #include "net/base/escape.h" | 34 #include "net/base/escape.h" |
34 #include "third_party/icu/public/common/unicode/normalizer2.h" | 35 #include "third_party/icu/public/common/unicode/normalizer2.h" |
35 | 36 |
36 #if defined(TOOLKIT_VIEWS) | 37 #if defined(TOOLKIT_VIEWS) |
37 #include "ui/views/widget/widget.h" | 38 #include "ui/views/widget/widget.h" |
38 #endif | 39 #endif |
39 | 40 |
40 namespace { | 41 namespace { |
41 | 42 |
42 // An artificial delay (in milliseconds) we introduce before telling the Instant | 43 // An artificial delay (in milliseconds) we introduce before telling the Instant |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 return view_gaining_focus; | 134 return view_gaining_focus; |
134 } | 135 } |
135 | 136 |
136 // Returns true if |view| is the top-level contents view or a child view in the | 137 // Returns true if |view| is the top-level contents view or a child view in the |
137 // view hierarchy of |contents|. | 138 // view hierarchy of |contents|. |
138 bool IsViewInContents(gfx::NativeView view, content::WebContents* contents) { | 139 bool IsViewInContents(gfx::NativeView view, content::WebContents* contents) { |
139 content::RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView(); | 140 content::RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView(); |
140 if (!view || !rwhv) | 141 if (!view || !rwhv) |
141 return false; | 142 return false; |
142 | 143 |
143 gfx::NativeView tab_view = contents->GetNativeView(); | 144 gfx::NativeView tab_view = contents->GetView()->GetNativeView(); |
144 if (view == rwhv->GetNativeView() || view == tab_view) | 145 if (view == rwhv->GetNativeView() || view == tab_view) |
145 return true; | 146 return true; |
146 | 147 |
147 // Walk up the view hierarchy to determine if the view is a subview of the | 148 // Walk up the view hierarchy to determine if the view is a subview of the |
148 // WebContents view (such as a windowed plugin or http auth dialog). | 149 // WebContents view (such as a windowed plugin or http auth dialog). |
149 while (view) { | 150 while (view) { |
150 view = platform_util::GetParent(view); | 151 view = platform_util::GetParent(view); |
151 if (view == tab_view) | 152 if (view == tab_view) |
152 return true; | 153 return true; |
153 } | 154 } |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 instant_tab_ != NULL)); | 575 instant_tab_ != NULL)); |
575 | 576 |
576 // If we are on an already committed search results page, send a submit event | 577 // If we are on an already committed search results page, send a submit event |
577 // to the page, but otherwise, nothing else to do. | 578 // to the page, but otherwise, nothing else to do. |
578 if (instant_tab_) { | 579 if (instant_tab_) { |
579 if (type == INSTANT_COMMIT_PRESSED_ENTER && | 580 if (type == INSTANT_COMMIT_PRESSED_ENTER && |
580 (last_match_was_search_ || | 581 (last_match_was_search_ || |
581 last_suggestion_.behavior == INSTANT_COMPLETE_NEVER)) { | 582 last_suggestion_.behavior == INSTANT_COMPLETE_NEVER)) { |
582 EnsureSearchTermsAreSet(instant_tab_->contents(), last_omnibox_text_); | 583 EnsureSearchTermsAreSet(instant_tab_->contents(), last_omnibox_text_); |
583 instant_tab_->Submit(last_omnibox_text_); | 584 instant_tab_->Submit(last_omnibox_text_); |
584 instant_tab_->contents()->Focus(); | 585 instant_tab_->contents()->GetView()->Focus(); |
585 return true; | 586 return true; |
586 } | 587 } |
587 return false; | 588 return false; |
588 } | 589 } |
589 | 590 |
590 if (!IsPreviewingSearchResults() && type != INSTANT_COMMIT_NAVIGATED) | 591 if (!IsPreviewingSearchResults() && type != INSTANT_COMMIT_NAVIGATED) |
591 return false; | 592 return false; |
592 | 593 |
593 // There may re-entrance here, from the call to browser_->CommitInstant below, | 594 // There may re-entrance here, from the call to browser_->CommitInstant below, |
594 // which can cause a TabDeactivated notification which gets back here. | 595 // which can cause a TabDeactivated notification which gets back here. |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1094 browser_->FocusOmniboxInvisibly(); | 1095 browser_->FocusOmniboxInvisibly(); |
1095 } | 1096 } |
1096 | 1097 |
1097 void InstantController::StopCapturingKeyStrokes( | 1098 void InstantController::StopCapturingKeyStrokes( |
1098 content::WebContents* contents) { | 1099 content::WebContents* contents) { |
1099 // Nothing to do if omnibox doesn't have invisible focus. | 1100 // Nothing to do if omnibox doesn't have invisible focus. |
1100 if (!extended_enabled_ || omnibox_focus_state_ != OMNIBOX_FOCUS_INVISIBLE) | 1101 if (!extended_enabled_ || omnibox_focus_state_ != OMNIBOX_FOCUS_INVISIBLE) |
1101 return; | 1102 return; |
1102 | 1103 |
1103 DCHECK(IsContentsFrom(instant_tab(), contents)); | 1104 DCHECK(IsContentsFrom(instant_tab(), contents)); |
1104 contents->Focus(); | 1105 contents->GetView()->Focus(); |
1105 } | 1106 } |
1106 | 1107 |
1107 void InstantController::NavigateToURL(const content::WebContents* contents, | 1108 void InstantController::NavigateToURL(const content::WebContents* contents, |
1108 const GURL& url, | 1109 const GURL& url, |
1109 content::PageTransition transition) { | 1110 content::PageTransition transition) { |
1110 // TODO(samarth): handle case where contents are no longer "active" (e.g. user | 1111 // TODO(samarth): handle case where contents are no longer "active" (e.g. user |
1111 // has switched tabs). | 1112 // has switched tabs). |
1112 if (!extended_enabled_) | 1113 if (!extended_enabled_) |
1113 return; | 1114 return; |
1114 if (overlay_) | 1115 if (overlay_) |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1503 overlay_->SendMostVisitedItems(items); | 1504 overlay_->SendMostVisitedItems(items); |
1504 if (ntp_) | 1505 if (ntp_) |
1505 ntp_->SendMostVisitedItems(items); | 1506 ntp_->SendMostVisitedItems(items); |
1506 if (instant_tab_) | 1507 if (instant_tab_) |
1507 instant_tab_->SendMostVisitedItems(items); | 1508 instant_tab_->SendMostVisitedItems(items); |
1508 content::NotificationService::current()->Notify( | 1509 content::NotificationService::current()->Notify( |
1509 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, | 1510 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, |
1510 content::Source<InstantController>(this), | 1511 content::Source<InstantController>(this), |
1511 content::NotificationService::NoDetails()); | 1512 content::NotificationService::NoDetails()); |
1512 } | 1513 } |
OLD | NEW |