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 "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 "net/url_request/url_request.h" | 14 #include "net/url_request/url_request.h" |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 const char kHTMLFilename[] = "local-omnibox-popup.html"; | 18 const char kHTMLFilename[] = "local-omnibox-popup.html"; |
19 const char kJsFilename[] = "local-omnibox-popup.js"; | 19 const char kJSFilename[] = "local-omnibox-popup.js"; |
20 const char kCSSFilename[] = "local-omnibox-popup.css"; | 20 const char kCSSFilename[] = "local-omnibox-popup.css"; |
21 | 21 |
22 } // namespace | 22 } // namespace |
23 | 23 |
24 LocalOmniboxPopupSource::LocalOmniboxPopupSource() { | 24 LocalOmniboxPopupSource::LocalOmniboxPopupSource() { |
25 } | 25 } |
26 | 26 |
27 LocalOmniboxPopupSource::~LocalOmniboxPopupSource() { | 27 LocalOmniboxPopupSource::~LocalOmniboxPopupSource() { |
28 } | 28 } |
29 | 29 |
30 std::string LocalOmniboxPopupSource::GetSource() { | 30 std::string LocalOmniboxPopupSource::GetSource() { |
31 return chrome::kChromeSearchLocalOmniboxPopupHost; | 31 return chrome::kChromeSearchLocalOmniboxPopupHost; |
32 } | 32 } |
33 | 33 |
34 void LocalOmniboxPopupSource::StartDataRequest( | 34 void LocalOmniboxPopupSource::StartDataRequest( |
35 const std::string& path, | 35 const std::string& path, |
36 bool is_incognito, | 36 bool is_incognito, |
37 const content::URLDataSource::GotDataCallback& callback) { | 37 const content::URLDataSource::GotDataCallback& callback) { |
38 int identifier = -1; | 38 int identifier = -1; |
39 if (path == kHTMLFilename) { | 39 if (path == kHTMLFilename) { |
40 identifier = IDR_LOCAL_OMNIBOX_POPUP_HTML; | 40 identifier = IDR_LOCAL_OMNIBOX_POPUP_HTML; |
41 } else if (path == kJsFilename) { | 41 } else if (path == kJSFilename) { |
42 identifier = IDR_LOCAL_OMNIBOX_POPUP_JS; | 42 identifier = IDR_LOCAL_OMNIBOX_POPUP_JS; |
43 } else if (path == kCSSFilename) { | 43 } else if (path == kCSSFilename) { |
44 identifier = IDR_LOCAL_OMNIBOX_POPUP_CSS; | 44 identifier = IDR_LOCAL_OMNIBOX_POPUP_CSS; |
45 } else { | 45 } else { |
46 callback.Run(NULL); | 46 callback.Run(NULL); |
47 return; | 47 return; |
48 } | 48 } |
49 | 49 |
50 scoped_refptr<base::RefCountedStaticMemory> response( | 50 scoped_refptr<base::RefCountedStaticMemory> response( |
51 content::GetContentClient()->GetDataResourceBytes(identifier)); | 51 content::GetContentClient()->GetDataResourceBytes(identifier)); |
52 callback.Run(response); | 52 callback.Run(response); |
53 } | 53 } |
54 | 54 |
55 std::string LocalOmniboxPopupSource::GetMimeType( | 55 std::string LocalOmniboxPopupSource::GetMimeType( |
56 const std::string& path) const { | 56 const std::string& path) const { |
57 if (path == kHTMLFilename) | 57 if (path == kHTMLFilename) |
58 return "text/html"; | 58 return "text/html"; |
59 if (path == kJsFilename) | 59 if (path == kJSFilename) |
60 return "application/javascript"; | 60 return "application/javascript"; |
61 if (path == kCSSFilename) | 61 if (path == kCSSFilename) |
62 return "text/css"; | 62 return "text/css"; |
63 return ""; | 63 return ""; |
64 } | 64 } |
65 | 65 |
66 bool LocalOmniboxPopupSource::ShouldServiceRequest( | 66 bool LocalOmniboxPopupSource::ShouldServiceRequest( |
67 const net::URLRequest* request) const { | 67 const net::URLRequest* request) const { |
68 DCHECK(request->url().host() == chrome::kChromeSearchLocalOmniboxPopupHost); | 68 DCHECK(request->url().host() == chrome::kChromeSearchLocalOmniboxPopupHost); |
69 | 69 |
70 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) { | 70 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) { |
71 DCHECK(StartsWithASCII(request->url().path(), "/", true)); | 71 DCHECK(StartsWithASCII(request->url().path(), "/", true)); |
72 std::string filename = request->url().path().substr(1); | 72 std::string filename = request->url().path().substr(1); |
73 return filename == kHTMLFilename || filename == kJsFilename || | 73 return filename == kHTMLFilename || filename == kJSFilename || |
74 filename == kCSSFilename; | 74 filename == kCSSFilename; |
75 } | 75 } |
76 return false; | 76 return false; |
77 } | 77 } |
OLD | NEW |