OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/dom_ui/dom_ui_contents.h" | 5 #include "chrome/browser/dom_ui/dom_ui_contents.h" |
6 | 6 |
| 7 #include "chrome/browser/debugger/debugger_contents.h" |
7 #include "chrome/browser/dom_ui/dom_ui.h" | 8 #include "chrome/browser/dom_ui/dom_ui.h" |
| 9 #include "chrome/browser/dom_ui/downloads_ui.h" |
8 #include "chrome/browser/dom_ui/history_ui.h" | 10 #include "chrome/browser/dom_ui/history_ui.h" |
9 #include "chrome/browser/dom_ui/downloads_ui.h" | 11 #include "chrome/browser/dom_ui/new_tab_ui.h" |
10 #include "chrome/browser/renderer_host/render_view_host.h" | 12 #include "chrome/browser/renderer_host/render_view_host.h" |
11 #include "chrome/browser/tab_contents/navigation_entry.h" | 13 #include "chrome/browser/tab_contents/navigation_entry.h" |
12 #include "chrome/common/resource_bundle.h" | 14 #include "chrome/common/resource_bundle.h" |
13 | 15 |
14 // The scheme used for DOMUIContentses | 16 // The scheme used for DOMUIContentses |
15 // TODO(glen): Merge this with the scheme in chrome_url_data_manager | 17 // TODO(glen): Merge this with the scheme in chrome_url_data_manager |
16 static const char kURLScheme[] = "chrome-ui"; | 18 static const char kURLScheme[] = "chrome-ui"; |
17 | 19 |
18 // The path used in internal URLs to thumbnail data. | 20 // The path used in internal URLs to thumbnail data. |
19 static const char kThumbnailPath[] = "thumb"; | 21 static const char kThumbnailPath[] = "thumb"; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 default_favicon_ = new RefCountedBytes; | 69 default_favicon_ = new RefCountedBytes; |
68 ResourceBundle::GetSharedInstance().LoadImageResourceBytes( | 70 ResourceBundle::GetSharedInstance().LoadImageResourceBytes( |
69 IDR_DEFAULT_FAVICON, &default_favicon_->data); | 71 IDR_DEFAULT_FAVICON, &default_favicon_->data); |
70 } | 72 } |
71 | 73 |
72 SendResponse(request_id, default_favicon_); | 74 SendResponse(request_id, default_favicon_); |
73 } | 75 } |
74 } | 76 } |
75 | 77 |
76 /////////////////////////////////////////////////////////////////////////////// | 78 /////////////////////////////////////////////////////////////////////////////// |
77 // ThumbnailSource | 79 // ThumbnailSource |
78 | 80 |
79 ThumbnailSource::ThumbnailSource(Profile* profile) | 81 ThumbnailSource::ThumbnailSource(Profile* profile) |
80 : DataSource(kThumbnailPath, MessageLoop::current()), profile_(profile) {} | 82 : DataSource(kThumbnailPath, MessageLoop::current()), profile_(profile) {} |
81 | 83 |
82 void ThumbnailSource::StartDataRequest(const std::string& path, | 84 void ThumbnailSource::StartDataRequest(const std::string& path, |
83 int request_id) { | 85 int request_id) { |
84 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 86 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
85 if (hs) { | 87 if (hs) { |
86 HistoryService::Handle handle = hs->GetPageThumbnail( | 88 HistoryService::Handle handle = hs->GetPageThumbnail( |
87 GURL(path), | 89 GURL(path), |
(...skipping 28 matching lines...) Expand all Loading... |
116 } | 118 } |
117 | 119 |
118 /////////////////////////////////////////////////////////////////////////////// | 120 /////////////////////////////////////////////////////////////////////////////// |
119 // DOMUIContents | 121 // DOMUIContents |
120 | 122 |
121 // This is the top-level URL handler for chrome-ui: URLs, and exposed in | 123 // This is the top-level URL handler for chrome-ui: URLs, and exposed in |
122 // our header file. The individual DOMUIs provide a chrome-ui:// HTML source | 124 // our header file. The individual DOMUIs provide a chrome-ui:// HTML source |
123 // at the same host/path. | 125 // at the same host/path. |
124 bool DOMUIContentsCanHandleURL(GURL* url, | 126 bool DOMUIContentsCanHandleURL(GURL* url, |
125 TabContentsType* result_type) { | 127 TabContentsType* result_type) { |
126 if (!url->SchemeIs(kURLScheme)) | 128 // chrome-internal is a scheme we used to use for the new tab page. |
127 return false; | 129 if (!url->SchemeIs(kURLScheme) && !url->SchemeIs("chrome-internal")) |
128 | |
129 // TODO: remove once the debugger is using DOMContentsUI | |
130 if (url->host().compare("inspector") == 0 && | |
131 url->path().compare("/debugger.html") == 0) | |
132 return false; | 130 return false; |
133 | 131 |
134 *result_type = TAB_CONTENTS_DOM_UI; | 132 *result_type = TAB_CONTENTS_DOM_UI; |
135 return true; | 133 return true; |
136 } | 134 } |
137 | 135 |
138 DOMUIContents::DOMUIContents(Profile* profile, | 136 DOMUIContents::DOMUIContents(Profile* profile, |
139 SiteInstance* instance, | 137 SiteInstance* instance, |
140 RenderViewHostFactory* render_view_factory) | 138 RenderViewHostFactory* render_view_factory) |
141 : WebContents(profile, | 139 : WebContents(profile, |
(...skipping 22 matching lines...) Expand all Loading... |
164 | 162 |
165 WebPreferences DOMUIContents::GetWebkitPrefs() { | 163 WebPreferences DOMUIContents::GetWebkitPrefs() { |
166 // Get the users preferences then force image loading to always be on. | 164 // Get the users preferences then force image loading to always be on. |
167 WebPreferences web_prefs = WebContents::GetWebkitPrefs(); | 165 WebPreferences web_prefs = WebContents::GetWebkitPrefs(); |
168 web_prefs.loads_images_automatically = true; | 166 web_prefs.loads_images_automatically = true; |
169 web_prefs.javascript_enabled = true; | 167 web_prefs.javascript_enabled = true; |
170 | 168 |
171 return web_prefs; | 169 return web_prefs; |
172 } | 170 } |
173 | 171 |
| 172 bool DOMUIContents::ShouldDisplayFavIcon() { |
| 173 if (current_ui_) |
| 174 return current_ui_->ShouldDisplayFavIcon(); |
| 175 return true; |
| 176 } |
| 177 |
| 178 bool DOMUIContents::IsBookmarkBarAlwaysVisible() { |
| 179 if (current_ui_) |
| 180 return current_ui_->IsBookmarkBarAlwaysVisible(); |
| 181 return false; |
| 182 } |
| 183 |
| 184 void DOMUIContents::SetInitialFocus() { |
| 185 if (current_ui_) |
| 186 current_ui_->SetInitialFocus(); |
| 187 } |
| 188 |
| 189 bool DOMUIContents::ShouldDisplayURL() { |
| 190 if (current_ui_) |
| 191 return current_ui_->ShouldDisplayURL(); |
| 192 return true; |
| 193 } |
| 194 |
| 195 void DOMUIContents::RequestOpenURL(const GURL& url, const GURL& referrer, |
| 196 WindowOpenDisposition disposition) { |
| 197 if (current_ui_) |
| 198 current_ui_->RequestOpenURL(url, referrer, disposition); |
| 199 } |
| 200 |
174 bool DOMUIContents::NavigateToPendingEntry(bool reload) { | 201 bool DOMUIContents::NavigateToPendingEntry(bool reload) { |
175 if (current_ui_) { | 202 if (current_ui_) { |
176 // Shut down our existing DOMUI. | 203 // Shut down our existing DOMUI. |
177 delete current_ui_; | 204 delete current_ui_; |
178 current_ui_ = NULL; | 205 current_ui_ = NULL; |
179 } | 206 } |
180 | 207 |
181 // Set up a new DOMUI. | 208 // Set up a new DOMUI. |
182 NavigationEntry* pending_entry = controller()->GetPendingEntry(); | 209 NavigationEntry* pending_entry = controller()->GetPendingEntry(); |
183 current_ui_ = GetDOMUIForURL(pending_entry->url()); | 210 current_ui_ = GetDOMUIForURL(pending_entry->url()); |
184 if (current_ui_) | 211 if (current_ui_) |
185 current_ui_->Init(); | 212 current_ui_->Init(); |
186 else | 213 else |
187 return false; | 214 return false; |
188 | 215 |
189 // Let WebContents do whatever it's meant to do. | 216 // Let WebContents do whatever it's meant to do. |
190 return WebContents::NavigateToPendingEntry(reload); | 217 return WebContents::NavigateToPendingEntry(reload); |
191 } | 218 } |
192 | 219 |
193 DOMUI* DOMUIContents::GetDOMUIForURL(const GURL &url) { | |
194 #if defined(OS_WIN) | |
195 // TODO(port): Include when history and downloads are HTML UI. | |
196 if (url.host() == HistoryUI::GetBaseURL().host()) | |
197 return new HistoryUI(this); | |
198 else if (url.host() == DownloadsUI::GetBaseURL().host()) | |
199 return new DownloadsUI(this); | |
200 #else | |
201 NOTIMPLEMENTED(); | |
202 #endif | |
203 | |
204 return NULL; | |
205 } | |
206 | |
207 void DOMUIContents::ProcessDOMUIMessage(const std::string& message, | 220 void DOMUIContents::ProcessDOMUIMessage(const std::string& message, |
208 const std::string& content) { | 221 const std::string& content) { |
209 DCHECK(current_ui_); | 222 DCHECK(current_ui_); |
210 current_ui_->ProcessDOMUIMessage(message, content); | 223 current_ui_->ProcessDOMUIMessage(message, content); |
211 } | 224 } |
212 | 225 |
213 // static | 226 // static |
214 const std::string DOMUIContents::GetScheme() { | 227 const std::string DOMUIContents::GetScheme() { |
215 return kURLScheme; | 228 return kURLScheme; |
216 } | 229 } |
217 | 230 |
| 231 DOMUI* DOMUIContents::GetDOMUIForURL(const GURL &url) { |
| 232 #if defined(OS_WIN) |
| 233 // TODO(port): include this once these are converted to HTML |
| 234 if (url.host() == NewTabUI::GetBaseURL().host() || |
| 235 url.SchemeIs("chrome-internal")) { |
| 236 return new NewTabUI(this); |
| 237 } else if (url.host() == HistoryUI::GetBaseURL().host()) { |
| 238 return new HistoryUI(this); |
| 239 } else if (url.host() == DownloadsUI::GetBaseURL().host()) { |
| 240 return new DownloadsUI(this); |
| 241 } else if (url.host() == DebuggerContents::GetBaseURL().host()) { |
| 242 return new DebuggerContents(this); |
| 243 } |
| 244 #else |
| 245 NOTIMPLEMENTED(); |
| 246 #endif |
| 247 return NULL; |
| 248 } |
OLD | NEW |