| 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/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 Loading... |
| 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( |
| 163 ChromeViewMsg_SearchBoxGrantChromeSearchAccessFromOrigin, |
| 164 OnGrantChromeSearchAccessFromOrigin) |
| 160 IPC_MESSAGE_HANDLER(ChromeViewMsg_InstantMostVisitedItemsChanged, | 165 IPC_MESSAGE_HANDLER(ChromeViewMsg_InstantMostVisitedItemsChanged, |
| 161 OnMostVisitedChanged) | 166 OnMostVisitedChanged) |
| 162 IPC_MESSAGE_UNHANDLED(handled = false) | 167 IPC_MESSAGE_UNHANDLED(handled = false) |
| 163 IPC_END_MESSAGE_MAP() | 168 IPC_END_MESSAGE_MAP() |
| 164 return handled; | 169 return handled; |
| 165 } | 170 } |
| 166 | 171 |
| 167 void SearchBox::DidClearWindowObject(WebKit::WebFrame* frame) { | 172 void SearchBox::DidClearWindowObject(WebKit::WebFrame* frame) { |
| 168 extensions_v8::SearchBoxExtension::DispatchOnWindowReady(frame); | 173 extensions_v8::SearchBoxExtension::DispatchOnWindowReady(frame); |
| 169 } | 174 } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 } | 289 } |
| 285 | 290 |
| 286 void SearchBox::OnThemeChanged(const ThemeBackgroundInfo& theme_info) { | 291 void SearchBox::OnThemeChanged(const ThemeBackgroundInfo& theme_info) { |
| 287 theme_info_ = theme_info; | 292 theme_info_ = theme_info; |
| 288 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 293 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
| 289 extensions_v8::SearchBoxExtension::DispatchThemeChange( | 294 extensions_v8::SearchBoxExtension::DispatchThemeChange( |
| 290 render_view()->GetWebView()->mainFrame()); | 295 render_view()->GetWebView()->mainFrame()); |
| 291 } | 296 } |
| 292 } | 297 } |
| 293 | 298 |
| 299 void SearchBox::OnFontInformationReceived(const string16& omnibox_font, |
| 300 size_t omnibox_font_size) { |
| 301 omnibox_font_ = omnibox_font; |
| 302 omnibox_font_size_ = omnibox_font_size; |
| 303 } |
| 304 |
| 305 void SearchBox::OnGrantChromeSearchAccessFromOrigin(const GURL& origin_url) { |
| 306 string16 chrome_search_scheme(ASCIIToUTF16(chrome::kChromeSearchScheme)); |
| 307 WebKit::WebSecurityPolicy::addOriginAccessWhitelistEntry( |
| 308 origin_url, |
| 309 chrome_search_scheme, |
| 310 ASCIIToUTF16(chrome::kChromeUIFaviconHost), |
| 311 false); |
| 312 WebKit::WebSecurityPolicy::addOriginAccessWhitelistEntry( |
| 313 origin_url, |
| 314 chrome_search_scheme, |
| 315 ASCIIToUTF16(chrome::kChromeUIThemeHost), |
| 316 false); |
| 317 WebKit::WebSecurityPolicy::addOriginAccessWhitelistEntry( |
| 318 origin_url, |
| 319 chrome_search_scheme, |
| 320 ASCIIToUTF16(chrome::kChromeUIThumbnailHost), |
| 321 false); |
| 322 } |
| 323 |
| 294 double SearchBox::GetZoom() const { | 324 double SearchBox::GetZoom() const { |
| 295 WebKit::WebView* web_view = render_view()->GetWebView(); | 325 WebKit::WebView* web_view = render_view()->GetWebView(); |
| 296 if (web_view) { | 326 if (web_view) { |
| 297 double zoom = WebKit::WebView::zoomLevelToZoomFactor(web_view->zoomLevel()); | 327 double zoom = WebKit::WebView::zoomLevelToZoomFactor(web_view->zoomLevel()); |
| 298 if (zoom != 0) | 328 if (zoom != 0) |
| 299 return zoom; | 329 return zoom; |
| 300 } | 330 } |
| 301 return 1.0; | 331 return 1.0; |
| 302 } | 332 } |
| 303 | 333 |
| 304 void SearchBox::OnFontInformationReceived(const string16& omnibox_font, | |
| 305 size_t omnibox_font_size) { | |
| 306 omnibox_font_ = omnibox_font; | |
| 307 omnibox_font_size_ = omnibox_font_size; | |
| 308 } | |
| 309 | |
| 310 void SearchBox::Reset() { | 334 void SearchBox::Reset() { |
| 311 query_.clear(); | 335 query_.clear(); |
| 312 verbatim_ = false; | 336 verbatim_ = false; |
| 313 selection_start_ = 0; | 337 selection_start_ = 0; |
| 314 selection_end_ = 0; | 338 selection_end_ = 0; |
| 315 results_base_ = 0; | 339 results_base_ = 0; |
| 316 popup_bounds_ = gfx::Rect(); | 340 popup_bounds_ = gfx::Rect(); |
| 317 start_margin_ = 0; | 341 start_margin_ = 0; |
| 318 autocomplete_results_.clear(); | 342 autocomplete_results_.clear(); |
| 319 is_key_capture_enabled_ = false; | 343 is_key_capture_enabled_ = false; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 GURL url = GURL(ostr.str()); | 384 GURL url = GURL(ostr.str()); |
| 361 return UTF8ToUTF16(url.spec()); | 385 return UTF8ToUTF16(url.spec()); |
| 362 } | 386 } |
| 363 | 387 |
| 364 string16 SearchBox::GenerateFaviconUrl(int id) { | 388 string16 SearchBox::GenerateFaviconUrl(int id) { |
| 365 std::ostringstream ostr; | 389 std::ostringstream ostr; |
| 366 ostr << kFaviconUrlPrefix << id; | 390 ostr << kFaviconUrlPrefix << id; |
| 367 GURL url = GURL(ostr.str()); | 391 GURL url = GURL(ostr.str()); |
| 368 return UTF8ToUTF16(url.spec()); | 392 return UTF8ToUTF16(url.spec()); |
| 369 } | 393 } |
| OLD | NEW |