Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1084)

Side by Side Diff: chrome/browser/ui/browser_instant_controller.cc

Issue 20501002: Adds paste function to searchbox api and handles paste event on fakebox (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/browser_instant_controller.h" 5 #include "chrome/browser/ui/browser_instant_controller.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/extensions/extension_service.h" 9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/extensions/extension_web_ui.h" 10 #include "chrome/browser/extensions/extension_web_ui.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/search/instant_service.h" 12 #include "chrome/browser/search/instant_service.h"
13 #include "chrome/browser/search/instant_service_factory.h" 13 #include "chrome/browser/search/instant_service_factory.h"
14 #include "chrome/browser/search/search.h" 14 #include "chrome/browser/search/search.h"
15 #include "chrome/browser/search_engines/template_url.h" 15 #include "chrome/browser/search_engines/template_url.h"
16 #include "chrome/browser/search_engines/template_url_service.h" 16 #include "chrome/browser/search_engines/template_url_service.h"
17 #include "chrome/browser/search_engines/template_url_service_factory.h" 17 #include "chrome/browser/search_engines/template_url_service_factory.h"
18 #include "chrome/browser/ui/browser.h" 18 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/browser_window.h" 19 #include "chrome/browser/ui/browser_window.h"
20 #include "chrome/browser/ui/omnibox/location_bar.h" 20 #include "chrome/browser/ui/omnibox/location_bar.h"
21 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
21 #include "chrome/browser/ui/omnibox/omnibox_view.h" 22 #include "chrome/browser/ui/omnibox/omnibox_view.h"
22 #include "chrome/browser/ui/search/instant_ntp.h" 23 #include "chrome/browser/ui/search/instant_ntp.h"
23 #include "chrome/browser/ui/search/search_model.h" 24 #include "chrome/browser/ui/search/search_model.h"
24 #include "chrome/browser/ui/search/search_tab_helper.h" 25 #include "chrome/browser/ui/search/search_tab_helper.h"
25 #include "chrome/browser/ui/tabs/tab_strip_model.h" 26 #include "chrome/browser/ui/tabs/tab_strip_model.h"
26 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" 27 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h"
27 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
28 #include "chrome/common/url_constants.h" 29 #include "chrome/common/url_constants.h"
29 #include "components/user_prefs/pref_registry_syncable.h" 30 #include "components/user_prefs/pref_registry_syncable.h"
30 #include "content/public/browser/render_process_host.h" 31 #include "content/public/browser/render_process_host.h"
31 #include "content/public/browser/user_metrics.h" 32 #include "content/public/browser/user_metrics.h"
32 #include "content/public/browser/web_contents.h" 33 #include "content/public/browser/web_contents.h"
34 #include "content/public/browser/web_contents_view.h"
33 35
34 using content::UserMetricsAction; 36 using content::UserMetricsAction;
35 37
36 //////////////////////////////////////////////////////////////////////////////// 38 ////////////////////////////////////////////////////////////////////////////////
37 // BrowserInstantController, public: 39 // BrowserInstantController, public:
38 40
39 BrowserInstantController::BrowserInstantController(Browser* browser) 41 BrowserInstantController::BrowserInstantController(Browser* browser)
40 : browser_(browser), 42 : browser_(browser),
41 instant_(this), 43 instant_(this),
42 instant_unload_handler_(browser) { 44 instant_unload_handler_(browser) {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 void BrowserInstantController::ReplaceWebContentsAt( 146 void BrowserInstantController::ReplaceWebContentsAt(
145 int index, 147 int index,
146 scoped_ptr<content::WebContents> new_contents) { 148 scoped_ptr<content::WebContents> new_contents) {
147 DCHECK_NE(TabStripModel::kNoTab, index); 149 DCHECK_NE(TabStripModel::kNoTab, index);
148 scoped_ptr<content::WebContents> old_contents(browser_->tab_strip_model()-> 150 scoped_ptr<content::WebContents> old_contents(browser_->tab_strip_model()->
149 ReplaceWebContentsAt(index, new_contents.release())); 151 ReplaceWebContentsAt(index, new_contents.release()));
150 instant_unload_handler_.RunUnloadListenersOrDestroy(old_contents.Pass(), 152 instant_unload_handler_.RunUnloadListenersOrDestroy(old_contents.Pass(),
151 index); 153 index);
152 } 154 }
153 155
154 void BrowserInstantController::FocusOmnibox(bool caret_visibility) { 156 void BrowserInstantController::FocusOmnibox(OmniboxFocusState state) {
155 OmniboxView* omnibox_view = browser_->window()->GetLocationBar()-> 157 OmniboxView* omnibox_view = browser_->window()->GetLocationBar()->
156 GetLocationEntry(); 158 GetLocationEntry();
157 omnibox_view->SetFocus(); 159
158 omnibox_view->model()->SetCaretVisibility(caret_visibility); 160 // Do not add a default case in the switch block for the following reasons:
159 if (!caret_visibility) { 161 // (1) Explicitly handle the new states. If new states are added in the
160 // If the user clicked on the fakebox, any text already in the omnibox 162 // OmniboxFocusState, the compiler will warn the developer to handle the new
161 // should get cleared when they start typing. Selecting all the existing 163 // states.
162 // text is a convenient way to accomplish this. It also gives a slight 164 // (2) An attacker may control the renderer and sends the browser process a
163 // visual cue to users who really understand selection state about what will 165 // malformed IPC. This function responds to the invalid |state| values by
164 // happen if they start typing. 166 // doing nothing instead of crashing the browser process (intentional no-op).
165 omnibox_view->SelectAll(false); 167 switch (state) {
168 case OMNIBOX_FOCUS_VISIBLE:
169 omnibox_view->SetFocus();
170 omnibox_view->model()->SetCaretVisibility(true);
171 break;
172 case OMNIBOX_FOCUS_INVISIBLE:
173 omnibox_view->SetFocus();
174 omnibox_view->model()->SetCaretVisibility(false);
175 // If the user clicked on the fakebox, any text already in the omnibox
176 // should get cleared when they start typing. Selecting all the existing
177 // text is a convenient way to accomplish this. It also gives a slight
178 // visual cue to users who really understand selection state about what
179 // will happen if they start typing.
180 omnibox_view->SelectAll(false);
181 break;
182 case OMNIBOX_FOCUS_NONE:
183 // Remove focus only if the popup is closed. This will prevent someone
184 // from changing the omnibox value and closing the popup without user
185 // interaction.
186 if (!omnibox_view->model()->popup_model()->IsOpen()) {
187 content::WebContents* contents = GetActiveWebContents();
188 if (contents)
189 contents->GetView()->Focus();
190 }
191 break;
166 } 192 }
167 } 193 }
168 194
169 content::WebContents* BrowserInstantController::GetActiveWebContents() const { 195 content::WebContents* BrowserInstantController::GetActiveWebContents() const {
170 return browser_->tab_strip_model()->GetActiveWebContents(); 196 return browser_->tab_strip_model()->GetActiveWebContents();
171 } 197 }
172 198
173 void BrowserInstantController::ActiveTabChanged() { 199 void BrowserInstantController::ActiveTabChanged() {
174 instant_.ActiveTabChanged(); 200 instant_.ActiveTabChanged();
175 } 201 }
176 202
177 void BrowserInstantController::TabDeactivated(content::WebContents* contents) { 203 void BrowserInstantController::TabDeactivated(content::WebContents* contents) {
178 instant_.TabDeactivated(contents); 204 instant_.TabDeactivated(contents);
179 } 205 }
180 206
181 void BrowserInstantController::OpenURL( 207 void BrowserInstantController::OpenURL(
182 const GURL& url, 208 const GURL& url,
183 content::PageTransition transition, 209 content::PageTransition transition,
184 WindowOpenDisposition disposition) { 210 WindowOpenDisposition disposition) {
185 browser_->OpenURL(content::OpenURLParams(url, 211 browser_->OpenURL(content::OpenURLParams(url,
186 content::Referrer(), 212 content::Referrer(),
187 disposition, 213 disposition,
188 transition, 214 transition,
189 false)); 215 false));
190 } 216 }
191 217
218 void BrowserInstantController::PasteIntoOmnibox(const string16& text) {
219 OmniboxView* omnibox_view = browser_->window()->GetLocationBar()->
220 GetLocationEntry();
221 // The first case is for right click to paste, where the text is retrieved
222 // from the clipboard already sanitized. The second case is needed to handle
223 // drag-and-drop value and it has to be sanitazed before setting it into the
224 // omnibox.
225 string16 text_to_paste = text.empty() ?
226 omnibox_view->GetClipboardText() :
227 omnibox_view->SanitizeTextForPaste(text);
228
229 if (!text_to_paste.empty()) {
230 if (!omnibox_view->model()->has_focus())
231 omnibox_view->SetFocus();
232 omnibox_view->OnBeforePossibleChange();
233 omnibox_view->model()->on_paste();
234 omnibox_view->SetUserText(text_to_paste);
235 omnibox_view->OnAfterPossibleChange();
236 }
237 }
238
192 void BrowserInstantController::SetOmniboxBounds(const gfx::Rect& bounds) { 239 void BrowserInstantController::SetOmniboxBounds(const gfx::Rect& bounds) {
193 instant_.SetOmniboxBounds(bounds); 240 instant_.SetOmniboxBounds(bounds);
194 } 241 }
195 242
196 void BrowserInstantController::ToggleVoiceSearch() { 243 void BrowserInstantController::ToggleVoiceSearch() {
197 instant_.ToggleVoiceSearch(); 244 instant_.ToggleVoiceSearch();
198 } 245 }
199 246
200 //////////////////////////////////////////////////////////////////////////////// 247 ////////////////////////////////////////////////////////////////////////////////
201 // BrowserInstantController, SearchModelObserver implementation: 248 // BrowserInstantController, SearchModelObserver implementation:
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 299
253 if (!instant_service->IsInstantProcess( 300 if (!instant_service->IsInstantProcess(
254 contents->GetRenderProcessHost()->GetID())) 301 contents->GetRenderProcessHost()->GetID()))
255 continue; 302 continue;
256 303
257 // Reload the contents to ensure that it gets assigned to a non-priviledged 304 // Reload the contents to ensure that it gets assigned to a non-priviledged
258 // renderer. 305 // renderer.
259 contents->GetController().Reload(false); 306 contents->GetController().Reload(false);
260 } 307 }
261 } 308 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_instant_controller.h ('k') | chrome/browser/ui/omnibox/omnibox_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698