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/ui/search/search_tab_helper.h" | 5 #include "chrome/browser/ui/search/search_tab_helper.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 contents->GetController().GetLastCommittedEntry(); | 60 contents->GetController().GetLastCommittedEntry(); |
61 return search::NavEntryIsInstantNTP(contents, entry) && | 61 return search::NavEntryIsInstantNTP(contents, entry) && |
62 entry->GetURL() != GURL(chrome::kChromeSearchLocalNtpUrl); | 62 entry->GetURL() != GURL(chrome::kChromeSearchLocalNtpUrl); |
63 } | 63 } |
64 | 64 |
65 bool IsNTP(const content::WebContents* contents) { | 65 bool IsNTP(const content::WebContents* contents) { |
66 // We can't use WebContents::GetURL() because that uses the active entry, | 66 // We can't use WebContents::GetURL() because that uses the active entry, |
67 // whereas we want the visible entry. | 67 // whereas we want the visible entry. |
68 const content::NavigationEntry* entry = | 68 const content::NavigationEntry* entry = |
69 contents->GetController().GetVisibleEntry(); | 69 contents->GetController().GetVisibleEntry(); |
70 if (entry && entry->GetVirtualURL() == GURL(chrome::kChromeUINewTabURL)) | 70 if (entry && entry->GetVirtualURL() == chrome::kChromeUINewTabURL) |
71 return true; | 71 return true; |
72 | 72 |
73 return search::IsInstantNTP(contents); | 73 return search::IsInstantNTP(contents); |
74 } | 74 } |
75 | 75 |
76 bool IsLocal(const content::WebContents* contents) { | 76 bool IsLocal(const content::WebContents* contents) { |
77 if (!contents) | 77 if (!contents) |
78 return false; | 78 return false; |
79 const content::NavigationEntry* entry = | 79 const content::NavigationEntry* entry = |
80 contents->GetController().GetVisibleEntry(); | 80 contents->GetController().GetVisibleEntry(); |
81 return entry && entry->GetURL() == GURL(chrome::kChromeSearchLocalNtpUrl); | 81 return entry && entry->GetURL() == chrome::kChromeSearchLocalNtpUrl; |
82 } | 82 } |
83 | 83 |
84 // Returns true if |contents| are rendered inside an Instant process. | 84 // Returns true if |contents| are rendered inside an Instant process. |
85 bool InInstantProcess(Profile* profile, | 85 bool InInstantProcess(Profile* profile, |
86 const content::WebContents* contents) { | 86 const content::WebContents* contents) { |
87 if (!profile || !contents) | 87 if (!profile || !contents) |
88 return false; | 88 return false; |
89 | 89 |
90 InstantService* instant_service = | 90 InstantService* instant_service = |
91 InstantServiceFactory::GetForProfile(profile); | 91 InstantServiceFactory::GetForProfile(profile); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 // ensures that the title is properly set to the string defined by the Chrome | 246 // ensures that the title is properly set to the string defined by the Chrome |
247 // UI language (rather than the server language) in all cases. | 247 // UI language (rather than the server language) in all cases. |
248 // | 248 // |
249 // We only override the title when it's nonempty to allow the page to set the | 249 // We only override the title when it's nonempty to allow the page to set the |
250 // title if it really wants. An empty title means to use the default. There's | 250 // title if it really wants. An empty title means to use the default. There's |
251 // also a race condition between this code and the page's SetTitle call which | 251 // also a race condition between this code and the page's SetTitle call which |
252 // this rule avoids. | 252 // this rule avoids. |
253 content::NavigationEntry* entry = | 253 content::NavigationEntry* entry = |
254 web_contents_->GetController().GetLastCommittedEntry(); | 254 web_contents_->GetController().GetLastCommittedEntry(); |
255 if (entry && entry->GetTitle().empty() && | 255 if (entry && entry->GetTitle().empty() && |
256 (entry->GetVirtualURL() == GURL(chrome::kChromeUINewTabURL) || | 256 (entry->GetVirtualURL() == chrome::kChromeUINewTabURL || |
257 search::NavEntryIsInstantNTP(web_contents_, entry))) { | 257 search::NavEntryIsInstantNTP(web_contents_, entry))) { |
258 web_contents_->UpdateTitleForEntry( | 258 web_contents_->UpdateTitleForEntry( |
259 entry, l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); | 259 entry, l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); |
260 } | 260 } |
261 } | 261 } |
262 | 262 |
263 void SearchTabHelper::DidFinishLoad(content::RenderFrameHost* render_frame_host, | 263 void SearchTabHelper::DidFinishLoad(content::RenderFrameHost* render_frame_host, |
264 const GURL& /* validated_url */) { | 264 const GURL& /* validated_url */) { |
265 if (!render_frame_host->GetParent()) { | 265 if (!render_frame_host->GetParent()) { |
266 if (search::IsInstantNTP(web_contents_)) | 266 if (search::IsInstantNTP(web_contents_)) |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 | 500 |
501 bool SearchTabHelper::IsInputInProgress() const { | 501 bool SearchTabHelper::IsInputInProgress() const { |
502 OmniboxView* omnibox = GetOmniboxView(); | 502 OmniboxView* omnibox = GetOmniboxView(); |
503 return !model_.mode().is_ntp() && omnibox && | 503 return !model_.mode().is_ntp() && omnibox && |
504 omnibox->model()->focus_state() == OMNIBOX_FOCUS_VISIBLE; | 504 omnibox->model()->focus_state() == OMNIBOX_FOCUS_VISIBLE; |
505 } | 505 } |
506 | 506 |
507 OmniboxView* SearchTabHelper::GetOmniboxView() const { | 507 OmniboxView* SearchTabHelper::GetOmniboxView() const { |
508 return delegate_ ? delegate_->GetOmniboxView() : NULL; | 508 return delegate_ ? delegate_->GetOmniboxView() : NULL; |
509 } | 509 } |
OLD | NEW |