| 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/ui/search_engines/search_engine_tab_helper.h" | 5 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" |
| 6 | 6 |
| 7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/browser/search_engines/template_url.h" | 8 #include "chrome/browser/search_engines/template_url.h" |
| 9 #include "chrome/browser/search_engines/template_url_fetcher.h" | 9 #include "chrome/browser/search_engines/template_url_fetcher.h" |
| 10 #include "chrome/browser/search_engines/template_url_service.h" | 10 #include "chrome/browser/search_engines/template_url_service.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 79 |
| 80 case search_provider::EXPLICIT_PROVIDER: | 80 case search_provider::EXPLICIT_PROVIDER: |
| 81 provider_type = TemplateURLFetcher::EXPLICIT_PROVIDER; | 81 provider_type = TemplateURLFetcher::EXPLICIT_PROVIDER; |
| 82 break; | 82 break; |
| 83 | 83 |
| 84 default: | 84 default: |
| 85 NOTREACHED(); | 85 NOTREACHED(); |
| 86 return; | 86 return; |
| 87 } | 87 } |
| 88 | 88 |
| 89 const NavigationController& controller = tab_contents()->controller(); | 89 const NavigationController& controller = tab_contents()->GetController(); |
| 90 const NavigationEntry* entry = controller.GetLastCommittedEntry(); | 90 const NavigationEntry* entry = controller.GetLastCommittedEntry(); |
| 91 DCHECK(entry); | 91 DCHECK(entry); |
| 92 | 92 |
| 93 const NavigationEntry* base_entry = entry; | 93 const NavigationEntry* base_entry = entry; |
| 94 if (IsFormSubmit(base_entry)) { | 94 if (IsFormSubmit(base_entry)) { |
| 95 // If the current page is a form submit, find the last page that was not | 95 // If the current page is a form submit, find the last page that was not |
| 96 // a form submit and use its url to generate the keyword from. | 96 // a form submit and use its url to generate the keyword from. |
| 97 int index = controller.last_committed_entry_index() - 1; | 97 int index = controller.last_committed_entry_index() - 1; |
| 98 while (index >= 0 && IsFormSubmit(controller.GetEntryAtIndex(index))) | 98 while (index >= 0 && IsFormSubmit(controller.GetEntryAtIndex(index))) |
| 99 index--; | 99 index--; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 129 void SearchEngineTabHelper::GenerateKeywordIfNecessary( | 129 void SearchEngineTabHelper::GenerateKeywordIfNecessary( |
| 130 const content::FrameNavigateParams& params) { | 130 const content::FrameNavigateParams& params) { |
| 131 if (!params.searchable_form_url.is_valid()) | 131 if (!params.searchable_form_url.is_valid()) |
| 132 return; | 132 return; |
| 133 | 133 |
| 134 Profile* profile = | 134 Profile* profile = |
| 135 Profile::FromBrowserContext(tab_contents()->browser_context()); | 135 Profile::FromBrowserContext(tab_contents()->browser_context()); |
| 136 if (profile->IsOffTheRecord()) | 136 if (profile->IsOffTheRecord()) |
| 137 return; | 137 return; |
| 138 | 138 |
| 139 const NavigationController& controller = tab_contents()->controller(); | 139 const NavigationController& controller = tab_contents()->GetController(); |
| 140 int last_index = controller.last_committed_entry_index(); | 140 int last_index = controller.last_committed_entry_index(); |
| 141 // When there was no previous page, the last index will be 0. This is | 141 // When there was no previous page, the last index will be 0. This is |
| 142 // normally due to a form submit that opened in a new tab. | 142 // normally due to a form submit that opened in a new tab. |
| 143 // TODO(brettw) bug 916126: we should support keywords when form submits | 143 // TODO(brettw) bug 916126: we should support keywords when form submits |
| 144 // happen in new tabs. | 144 // happen in new tabs. |
| 145 if (last_index <= 0) | 145 if (last_index <= 0) |
| 146 return; | 146 return; |
| 147 const NavigationEntry* previous_entry = | 147 const NavigationEntry* previous_entry = |
| 148 controller.GetEntryAtIndex(last_index - 1); | 148 controller.GetEntryAtIndex(last_index - 1); |
| 149 if (IsFormSubmit(previous_entry)) { | 149 if (IsFormSubmit(previous_entry)) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 // or the favicon url wasn't obtained before the load started. This assumes | 197 // or the favicon url wasn't obtained before the load started. This assumes |
| 198 // the later. | 198 // the later. |
| 199 // TODO(sky): Need a way to set the favicon that doesn't involve generating | 199 // TODO(sky): Need a way to set the favicon that doesn't involve generating |
| 200 // its url. | 200 // its url. |
| 201 new_url->SetFaviconURL( | 201 new_url->SetFaviconURL( |
| 202 TemplateURL::GenerateFaviconURL(params.referrer.url)); | 202 TemplateURL::GenerateFaviconURL(params.referrer.url)); |
| 203 } | 203 } |
| 204 new_url->set_safe_for_autoreplace(true); | 204 new_url->set_safe_for_autoreplace(true); |
| 205 url_service->Add(new_url); | 205 url_service->Add(new_url); |
| 206 } | 206 } |
| OLD | NEW |