| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/search/local_omnibox_popup_source.h" | 5 #include "chrome/browser/search/local_omnibox_popup_source.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/ref_counted_memory.h" | 8 #include "base/memory/ref_counted_memory.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| 11 #include "chrome/common/url_constants.h" | 11 #include "chrome/common/url_constants.h" |
| 12 #include "content/public/common/content_client.h" | 12 #include "content/public/common/content_client.h" |
| 13 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
| 14 #include "grit/browser_resources.h" | 14 #include "grit/browser_resources.h" |
| 15 #include "net/url_request/url_request.h" | 15 #include "net/url_request/url_request.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 const char kHTMLFilename[] = "local-omnibox-popup.html"; | 19 const char kHtmlFilename[] = "local-omnibox-popup.html"; |
| 20 const char kJsFilename[] = "local-omnibox-popup.js"; | 20 const char kJSFilename[] = "local-omnibox-popup.js"; |
| 21 const char kCSSFilename[] = "local-omnibox-popup.css"; | 21 const char kCssFilename[] = "local-omnibox-popup.css"; |
| 22 const char kPageIconFilename[] = "images/page_icon.png"; | 22 const char kPageIconFilename[] = "images/page_icon.png"; |
| 23 const char kPageIcon2xFilename[] = "images/2x/page_icon.png"; | 23 const char kPageIcon2xFilename[] = "images/2x/page_icon.png"; |
| 24 const char kSearchIconFilename[] = "images/search_icon.png"; | 24 const char kSearchIconFilename[] = "images/search_icon.png"; |
| 25 const char kSearchIcon2xFilename[] = "images/2x/search_icon.png"; | 25 const char kSearchIcon2xFilename[] = "images/2x/search_icon.png"; |
| 26 | 26 |
| 27 } // namespace | 27 } // namespace |
| 28 | 28 |
| 29 LocalOmniboxPopupSource::LocalOmniboxPopupSource() { | 29 LocalOmniboxPopupSource::LocalOmniboxPopupSource() { |
| 30 } | 30 } |
| 31 | 31 |
| 32 LocalOmniboxPopupSource::~LocalOmniboxPopupSource() { | 32 LocalOmniboxPopupSource::~LocalOmniboxPopupSource() { |
| 33 } | 33 } |
| 34 | 34 |
| 35 std::string LocalOmniboxPopupSource::GetSource() { | 35 std::string LocalOmniboxPopupSource::GetSource() { |
| 36 return chrome::kChromeSearchLocalOmniboxPopupHost; | 36 return chrome::kChromeSearchLocalOmniboxPopupHost; |
| 37 } | 37 } |
| 38 | 38 |
| 39 void LocalOmniboxPopupSource::StartDataRequest( | 39 void LocalOmniboxPopupSource::StartDataRequest( |
| 40 const std::string& path, | 40 const std::string& path, |
| 41 bool is_incognito, | 41 bool is_incognito, |
| 42 const content::URLDataSource::GotDataCallback& callback) { | 42 const content::URLDataSource::GotDataCallback& callback) { |
| 43 int identifier = -1; | 43 int identifier = -1; |
| 44 if (path == kHTMLFilename) { | 44 if (path == kHtmlFilename) { |
| 45 identifier = IDR_LOCAL_OMNIBOX_POPUP_HTML; | 45 identifier = IDR_LOCAL_OMNIBOX_POPUP_HTML; |
| 46 } else if (path == kJsFilename) { | 46 } else if (path == kJSFilename) { |
| 47 identifier = IDR_LOCAL_OMNIBOX_POPUP_JS; | 47 identifier = IDR_LOCAL_OMNIBOX_POPUP_JS; |
| 48 } else if (path == kCSSFilename) { | 48 } else if (path == kCssFilename) { |
| 49 identifier = IDR_LOCAL_OMNIBOX_POPUP_CSS; | 49 identifier = IDR_LOCAL_OMNIBOX_POPUP_CSS; |
| 50 } else if (path == kPageIconFilename) { | 50 } else if (path == kPageIconFilename) { |
| 51 identifier = IDR_LOCAL_OMNIBOX_POPUP_IMAGES_PAGE_ICON_PNG; | 51 identifier = IDR_LOCAL_OMNIBOX_POPUP_IMAGES_PAGE_ICON_PNG; |
| 52 } else if (path == kPageIcon2xFilename) { | 52 } else if (path == kPageIcon2xFilename) { |
| 53 identifier = IDR_LOCAL_OMNIBOX_POPUP_IMAGES_2X_PAGE_ICON_PNG; | 53 identifier = IDR_LOCAL_OMNIBOX_POPUP_IMAGES_2X_PAGE_ICON_PNG; |
| 54 } else if (path == kSearchIconFilename) { | 54 } else if (path == kSearchIconFilename) { |
| 55 identifier = IDR_LOCAL_OMNIBOX_POPUP_IMAGES_SEARCH_ICON_PNG; | 55 identifier = IDR_LOCAL_OMNIBOX_POPUP_IMAGES_SEARCH_ICON_PNG; |
| 56 } else if (path == kSearchIcon2xFilename) { | 56 } else if (path == kSearchIcon2xFilename) { |
| 57 identifier = IDR_LOCAL_OMNIBOX_POPUP_IMAGES_2X_SEARCH_ICON_PNG; | 57 identifier = IDR_LOCAL_OMNIBOX_POPUP_IMAGES_2X_SEARCH_ICON_PNG; |
| 58 } else { | 58 } else { |
| 59 callback.Run(NULL); | 59 callback.Run(NULL); |
| 60 return; | 60 return; |
| 61 } | 61 } |
| 62 | 62 |
| 63 scoped_refptr<base::RefCountedStaticMemory> response( | 63 scoped_refptr<base::RefCountedStaticMemory> response( |
| 64 content::GetContentClient()->GetDataResourceBytes(identifier)); | 64 content::GetContentClient()->GetDataResourceBytes(identifier)); |
| 65 callback.Run(response); | 65 callback.Run(response); |
| 66 } | 66 } |
| 67 | 67 |
| 68 std::string LocalOmniboxPopupSource::GetMimeType( | 68 std::string LocalOmniboxPopupSource::GetMimeType( |
| 69 const std::string& path) const { | 69 const std::string& path) const { |
| 70 if (path == kHTMLFilename) | 70 if (path == kHtmlFilename) |
| 71 return "text/html"; | 71 return "text/html"; |
| 72 if (path == kJsFilename) | 72 if (path == kJSFilename) |
| 73 return "application/javascript"; | 73 return "application/javascript"; |
| 74 if (path == kCSSFilename) | 74 if (path == kCssFilename) |
| 75 return "text/css"; | 75 return "text/css"; |
| 76 if (path == kPageIconFilename || path == kPageIcon2xFilename || | 76 if (path == kPageIconFilename || path == kPageIcon2xFilename || |
| 77 path == kSearchIconFilename || path == kSearchIcon2xFilename) | 77 path == kSearchIconFilename || path == kSearchIcon2xFilename) |
| 78 return "image/png"; | 78 return "image/png"; |
| 79 return ""; | 79 return ""; |
| 80 } | 80 } |
| 81 | 81 |
| 82 bool LocalOmniboxPopupSource::ShouldServiceRequest( | 82 bool LocalOmniboxPopupSource::ShouldServiceRequest( |
| 83 const net::URLRequest* request) const { | 83 const net::URLRequest* request) const { |
| 84 DCHECK(request->url().host() == chrome::kChromeSearchLocalOmniboxPopupHost); | 84 DCHECK(request->url().host() == chrome::kChromeSearchLocalOmniboxPopupHost); |
| 85 | 85 |
| 86 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) { | 86 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) { |
| 87 DCHECK(StartsWithASCII(request->url().path(), "/", true)); | 87 DCHECK(StartsWithASCII(request->url().path(), "/", true)); |
| 88 std::string filename = request->url().path().substr(1); | 88 std::string filename = request->url().path().substr(1); |
| 89 return filename == kHTMLFilename || filename == kJsFilename || | 89 return filename == kHtmlFilename || filename == kJSFilename || |
| 90 filename == kCSSFilename || filename == kPageIconFilename || | 90 filename == kCssFilename || filename == kPageIconFilename || |
| 91 filename == kPageIcon2xFilename || filename == kSearchIconFilename || | 91 filename == kPageIcon2xFilename || filename == kSearchIconFilename || |
| 92 filename == kSearchIcon2xFilename; | 92 filename == kSearchIcon2xFilename; |
| 93 } | 93 } |
| 94 return false; | 94 return false; |
| 95 } | 95 } |
| 96 | 96 |
| 97 std::string LocalOmniboxPopupSource::GetContentSecurityPolicyFrameSrc() const { | 97 std::string LocalOmniboxPopupSource::GetContentSecurityPolicyFrameSrc() const { |
| 98 // Allow embedding of chrome search suggestion host. | 98 // Allow embedding of chrome search suggestion host. |
| 99 return base::StringPrintf("frame-src %s://%s/;", | 99 return base::StringPrintf("frame-src %s://%s/;", |
| 100 chrome::kChromeSearchScheme, | 100 chrome::kChromeSearchScheme, |
| 101 chrome::kChromeSearchSuggestionHost); | 101 chrome::kChromeSearchSuggestionHost); |
| 102 } | 102 } |
| OLD | NEW |