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

Side by Side Diff: chrome/renderer/searchbox/searchbox.cc

Issue 11896113: Add chrome-search: access from Instant overlay (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Charlie's comments. Created 7 years, 9 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 | Annotate | Revision Log
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/renderer/searchbox/searchbox.h" 5 #include "chrome/renderer/searchbox/searchbox.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/common/render_messages.h" 8 #include "chrome/common/render_messages.h"
9 #include "chrome/common/url_constants.h"
9 #include "chrome/renderer/searchbox/searchbox_extension.h" 10 #include "chrome/renderer/searchbox/searchbox_extension.h"
10 #include "content/public/renderer/render_view.h" 11 #include "content/public/renderer/render_view.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
12 14
13 namespace { 15 namespace {
14 16
15 // Prefix for a thumbnail URL. 17 // Prefix for a thumbnail URL.
16 const char kThumbnailUrlPrefix[] = "chrome-search://thumb/"; 18 const char kThumbnailUrlPrefix[] = "chrome-search://thumb/";
17 19
18 // Prefix for a thumbnail URL. 20 // Prefix for a thumbnail URL.
19 const char kFaviconUrlPrefix[] = "chrome-search://favicon/"; 21 const char kFaviconUrlPrefix[] = "chrome-search://favicon/";
20 22
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxCancelSelection, 152 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxCancelSelection,
151 OnCancelSelection) 153 OnCancelSelection)
152 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSetDisplayInstantResults, 154 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSetDisplayInstantResults,
153 OnSetDisplayInstantResults) 155 OnSetDisplayInstantResults)
154 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxKeyCaptureChanged, 156 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxKeyCaptureChanged,
155 OnKeyCaptureChange) 157 OnKeyCaptureChange)
156 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxThemeChanged, 158 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxThemeChanged,
157 OnThemeChanged) 159 OnThemeChanged)
158 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxFontInformation, 160 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxFontInformation,
159 OnFontInformationReceived) 161 OnFontInformationReceived)
162 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxGrantAccessFromOrigin,
163 OnGrantAccessFromOrigin)
160 IPC_MESSAGE_HANDLER(ChromeViewMsg_InstantMostVisitedItemsChanged, 164 IPC_MESSAGE_HANDLER(ChromeViewMsg_InstantMostVisitedItemsChanged,
161 OnMostVisitedChanged) 165 OnMostVisitedChanged)
162 IPC_MESSAGE_UNHANDLED(handled = false) 166 IPC_MESSAGE_UNHANDLED(handled = false)
163 IPC_END_MESSAGE_MAP() 167 IPC_END_MESSAGE_MAP()
164 return handled; 168 return handled;
165 } 169 }
166 170
167 void SearchBox::DidClearWindowObject(WebKit::WebFrame* frame) { 171 void SearchBox::DidClearWindowObject(WebKit::WebFrame* frame) {
168 extensions_v8::SearchBoxExtension::DispatchOnWindowReady(frame); 172 extensions_v8::SearchBoxExtension::DispatchOnWindowReady(frame);
169 } 173 }
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 } 285 }
282 286
283 void SearchBox::OnThemeChanged(const ThemeBackgroundInfo& theme_info) { 287 void SearchBox::OnThemeChanged(const ThemeBackgroundInfo& theme_info) {
284 theme_info_ = theme_info; 288 theme_info_ = theme_info;
285 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { 289 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
286 extensions_v8::SearchBoxExtension::DispatchThemeChange( 290 extensions_v8::SearchBoxExtension::DispatchThemeChange(
287 render_view()->GetWebView()->mainFrame()); 291 render_view()->GetWebView()->mainFrame());
288 } 292 }
289 } 293 }
290 294
295 void SearchBox::OnFontInformationReceived(const string16& omnibox_font,
296 size_t omnibox_font_size) {
297 omnibox_font_ = omnibox_font;
298 omnibox_font_size_ = omnibox_font_size;
299 }
300
301 void SearchBox::OnGrantAccessFromOrigin(const GURL& origin_url) {
302 string16 chrome_search_scheme(ASCIIToUTF16(chrome::kChromeSearchScheme));
303 WebKit::WebSecurityPolicy::addOriginAccessWhitelistEntry(
304 origin_url,
305 chrome_search_scheme,
306 ASCIIToUTF16(chrome::kChromeUIFaviconHost),
307 false);
308 WebKit::WebSecurityPolicy::addOriginAccessWhitelistEntry(
309 origin_url,
310 chrome_search_scheme,
311 ASCIIToUTF16(chrome::kChromeUIThemeHost),
312 false);
313 WebKit::WebSecurityPolicy::addOriginAccessWhitelistEntry(
314 origin_url,
315 chrome_search_scheme,
316 ASCIIToUTF16(chrome::kChromeUIThumbnailHost),
317 false);
318 }
319
291 double SearchBox::GetZoom() const { 320 double SearchBox::GetZoom() const {
292 WebKit::WebView* web_view = render_view()->GetWebView(); 321 WebKit::WebView* web_view = render_view()->GetWebView();
293 if (web_view) { 322 if (web_view) {
294 double zoom = WebKit::WebView::zoomLevelToZoomFactor(web_view->zoomLevel()); 323 double zoom = WebKit::WebView::zoomLevelToZoomFactor(web_view->zoomLevel());
295 if (zoom != 0) 324 if (zoom != 0)
296 return zoom; 325 return zoom;
297 } 326 }
298 return 1.0; 327 return 1.0;
299 } 328 }
300 329
301 void SearchBox::OnFontInformationReceived(const string16& omnibox_font,
302 size_t omnibox_font_size) {
303 omnibox_font_ = omnibox_font;
304 omnibox_font_size_ = omnibox_font_size;
305 }
306
307 void SearchBox::Reset() { 330 void SearchBox::Reset() {
308 query_.clear(); 331 query_.clear();
309 verbatim_ = false; 332 verbatim_ = false;
310 selection_start_ = 0; 333 selection_start_ = 0;
311 selection_end_ = 0; 334 selection_end_ = 0;
312 results_base_ = 0; 335 results_base_ = 0;
313 popup_bounds_ = gfx::Rect(); 336 popup_bounds_ = gfx::Rect();
314 start_margin_ = 0; 337 start_margin_ = 0;
315 end_margin_ = 0; 338 end_margin_ = 0;
316 autocomplete_results_.clear(); 339 autocomplete_results_.clear();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 GURL url = GURL(ostr.str()); 381 GURL url = GURL(ostr.str());
359 return UTF8ToUTF16(url.spec()); 382 return UTF8ToUTF16(url.spec());
360 } 383 }
361 384
362 string16 SearchBox::GenerateFaviconUrl(int id) { 385 string16 SearchBox::GenerateFaviconUrl(int id) {
363 std::ostringstream ostr; 386 std::ostringstream ostr;
364 ostr << kFaviconUrlPrefix << id; 387 ostr << kFaviconUrlPrefix << id;
365 GURL url = GURL(ostr.str()); 388 GURL url = GURL(ostr.str());
366 return UTF8ToUTF16(url.spec()); 389 return UTF8ToUTF16(url.spec());
367 } 390 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698