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