Chromium Code Reviews| 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/instant/local_omnibox_popup_source.h" | 5 #include "chrome/browser/instant/local_ntp_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 "chrome/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" | 
| 11 #include "content/public/common/content_client.h" | 11 #include "content/public/common/content_client.h" | 
| 12 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" | 
| 13 #include "grit/browser_resources.h" | 13 #include "grit/browser_resources.h" | 
| 14 #include "grit/ui_resources.h" | |
| 14 #include "net/url_request/url_request.h" | 15 #include "net/url_request/url_request.h" | 
| 15 | 16 | 
| 16 namespace { | 17 namespace { | 
| 17 | 18 | 
| 18 const char kHTMLFilename[] = "local-omnibox-popup.html"; | 19 const char kHTMLFilename[] = "local-ntp.html"; | 
| 19 const char kJsFilename[] = "local-omnibox-popup.js"; | 20 const char kJsFilename[] = "local-ntp.js"; | 
| 
 
samarth
2013/03/18 22:09:19
nit: kJSFilename
 
jeremycho
2013/03/18 23:18:52
Done.
 
 | |
| 20 const char kCSSFilename[] = "local-omnibox-popup.css"; | 21 const char kCSSFilename[] = "local-ntp.css"; | 
| 22 const char kCloseBarFilename[] = "images/close_bar.png"; | |
| 23 const char kCloseBarHoverFilename[] = "images/close_bar_hover.png"; | |
| 24 const char kCloseBarActiveFilename[] = "images/close_bar_active.png"; | |
| 21 | 25 | 
| 22 } // namespace | 26 } // namespace | 
| 23 | 27 | 
| 24 LocalOmniboxPopupSource::LocalOmniboxPopupSource() { | 28 LocalNTPSource::LocalNTPSource() { | 
| 25 } | 29 } | 
| 26 | 30 | 
| 27 LocalOmniboxPopupSource::~LocalOmniboxPopupSource() { | 31 LocalNTPSource::~LocalNTPSource() { | 
| 28 } | 32 } | 
| 29 | 33 | 
| 30 std::string LocalOmniboxPopupSource::GetSource() { | 34 std::string LocalNTPSource::GetSource() { | 
| 31 return chrome::kChromeSearchLocalOmniboxPopupHost; | 35 return chrome::kChromeSearchLocalNTPHost; | 
| 32 } | 36 } | 
| 33 | 37 | 
| 34 void LocalOmniboxPopupSource::StartDataRequest( | 38 void LocalNTPSource::StartDataRequest( | 
| 35 const std::string& path, | 39 const std::string& path, | 
| 36 bool is_incognito, | 40 bool is_incognito, | 
| 37 const content::URLDataSource::GotDataCallback& callback) { | 41 const content::URLDataSource::GotDataCallback& callback) { | 
| 38 int identifier = -1; | 42 int identifier = -1; | 
| 39 if (path == kHTMLFilename) { | 43 if (path == kHTMLFilename) { | 
| 40 identifier = IDR_LOCAL_OMNIBOX_POPUP_HTML; | 44 identifier = IDR_LOCAL_NTP_HTML; | 
| 41 } else if (path == kJsFilename) { | 45 } else if (path == kJsFilename) { | 
| 42 identifier = IDR_LOCAL_OMNIBOX_POPUP_JS; | 46 identifier = IDR_LOCAL_NTP_JS; | 
| 43 } else if (path == kCSSFilename) { | 47 } else if (path == kCSSFilename) { | 
| 44 identifier = IDR_LOCAL_OMNIBOX_POPUP_CSS; | 48 identifier = IDR_LOCAL_NTP_CSS; | 
| 49 } else if (path == kCloseBarFilename) { | |
| 50 identifier = IDR_CLOSE_BAR; | |
| 51 } else if (path == kCloseBarHoverFilename) { | |
| 52 identifier = IDR_CLOSE_BAR_H; | |
| 53 } else if (path == kCloseBarActiveFilename) { | |
| 54 identifier = IDR_CLOSE_BAR_P; | |
| 45 } else { | 55 } else { | 
| 46 callback.Run(NULL); | 56 callback.Run(NULL); | 
| 47 return; | 57 return; | 
| 48 } | 58 } | 
| 49 | 59 | 
| 50 scoped_refptr<base::RefCountedStaticMemory> response( | 60 scoped_refptr<base::RefCountedStaticMemory> response( | 
| 51 content::GetContentClient()->GetDataResourceBytes(identifier)); | 61 content::GetContentClient()->GetDataResourceBytes(identifier)); | 
| 52 callback.Run(response); | 62 callback.Run(response); | 
| 53 } | 63 } | 
| 54 | 64 | 
| 55 std::string LocalOmniboxPopupSource::GetMimeType( | 65 std::string LocalNTPSource::GetMimeType( | 
| 56 const std::string& path) const { | 66 const std::string& path) const { | 
| 57 if (path == kHTMLFilename) | 67 if (path == kHTMLFilename) | 
| 58 return "text/html"; | 68 return "text/html"; | 
| 59 if (path == kJsFilename) | 69 if (path == kJsFilename) | 
| 60 return "application/javascript"; | 70 return "application/javascript"; | 
| 61 if (path == kCSSFilename) | 71 if (path == kCSSFilename) | 
| 62 return "text/css"; | 72 return "text/css"; | 
| 73 if (path == kCloseBarFilename || path == kCloseBarHoverFilename || | |
| 74 path == kCloseBarActiveFilename) | |
| 75 return "image/png"; | |
| 63 return ""; | 76 return ""; | 
| 64 } | 77 } | 
| 65 | 78 | 
| 66 bool LocalOmniboxPopupSource::ShouldServiceRequest( | 79 bool LocalNTPSource::ShouldServiceRequest( | 
| 67 const net::URLRequest* request) const { | 80 const net::URLRequest* request) const { | 
| 68 DCHECK(request->url().host() == chrome::kChromeSearchLocalOmniboxPopupHost); | 81 DCHECK_EQ(request->url().host(), chrome::kChromeSearchLocalNTPHost); | 
| 69 | 82 | 
| 70 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) { | 83 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) { | 
| 71 DCHECK(StartsWithASCII(request->url().path(), "/", true)); | 84 DCHECK(StartsWithASCII(request->url().path(), "/", true)); | 
| 72 std::string filename = request->url().path().substr(1); | 85 std::string filename = request->url().path().substr(1); | 
| 73 return filename == kHTMLFilename || filename == kJsFilename || | 86 return filename == kHTMLFilename || filename == kJsFilename || | 
| 74 filename == kCSSFilename; | 87 filename == kCSSFilename || filename == kCloseBarFilename || | 
| 88 filename == kCloseBarHoverFilename || | |
| 89 filename == kCloseBarActiveFilename; | |
| 75 } | 90 } | 
| 76 return false; | 91 return false; | 
| 77 } | 92 } | 
| OLD | NEW |