1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/dom_ui/dom_ui_factory.h"
#include "base/command_line.h"
#include "chrome/browser/about_flags.h"
#include "chrome/browser/browser_thread.h"
#include "chrome/browser/dom_ui/bookmarks_ui.h"
#include "chrome/browser/dom_ui/bug_report_ui.h"
#include "chrome/browser/dom_ui/constrained_html_ui.h"
#include "chrome/browser/dom_ui/downloads_ui.h"
#include "chrome/browser/dom_ui/devtools_ui.h"
#include "chrome/browser/dom_ui/history_ui.h"
#include "chrome/browser/dom_ui/history2_ui.h"
#include "chrome/browser/dom_ui/html_dialog_ui.h"
#if defined(TOUCH_UI)
#include "chrome/browser/dom_ui/keyboard_ui.h"
#endif
#include "chrome/browser/dom_ui/flags_ui.h"
#include "chrome/browser/dom_ui/net_internals_ui.h"
#include "chrome/browser/dom_ui/new_tab_ui.h"
#include "chrome/browser/dom_ui/plugins_ui.h"
#include "chrome/browser/dom_ui/print_preview_ui.h"
#include "chrome/browser/dom_ui/remoting_ui.h"
#include "chrome/browser/dom_ui/options/options_ui.h"
#include "chrome/browser/dom_ui/slideshow_ui.h"
#include "chrome/browser/dom_ui/textfields_ui.h"
#include "chrome/browser/extensions/extension_dom_ui.h"
#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/browser/extensions/extensions_ui.h"
#include "chrome/browser/printing/print_dialog_cloud.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/url_constants.h"
#include "googleurl/src/gurl.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/dom_ui/imageburner_ui.h"
#include "chrome/browser/chromeos/dom_ui/keyboard_overlay_ui.h"
#include "chrome/browser/chromeos/dom_ui/menu_ui.h"
#include "chrome/browser/chromeos/dom_ui/mobile_setup_ui.h"
#include "chrome/browser/chromeos/dom_ui/register_page_ui.h"
#include "chrome/browser/chromeos/dom_ui/system_info_ui.h"
#include "chrome/browser/chromeos/dom_ui/wrench_menu_ui.h"
#include "chrome/browser/chromeos/dom_ui/network_menu_ui.h"
#include "chrome/browser/dom_ui/filebrowse_ui.h"
#include "chrome/browser/dom_ui/mediaplayer_ui.h"
#endif
#if defined(OS_WIN)
#include "chrome/browser/dom_ui/conflicts_ui.h"
#endif
const DOMUITypeID DOMUIFactory::kNoDOMUI = NULL;
// A function for creating a new DOMUI. The caller owns the return value, which
// may be NULL (for example, if the URL refers to an non-existent extension).
typedef DOMUI* (*DOMUIFactoryFunction)(TabContents* tab_contents,
const GURL& url);
// Template for defining DOMUIFactoryFunction.
template<class T>
DOMUI* NewDOMUI(TabContents* contents, const GURL& url) {
return new T(contents);
}
// Special case for extensions.
template<>
DOMUI* NewDOMUI<ExtensionDOMUI>(TabContents* contents, const GURL& url) {
// Don't use a DOMUI for incognito tabs because we require extensions to run
// within a single process.
ExtensionsService* service = contents->profile()->GetExtensionsService();
if (service &&
service->ExtensionBindingsAllowed(url)) {
return new ExtensionDOMUI(contents, url);
}
return NULL;
}
// Returns a function that can be used to create the right type of DOMUI for a
// tab, based on its URL. Returns NULL if the URL doesn't have DOMUI associated
// with it. Even if the factory function is valid, it may yield a NULL DOMUI
// when invoked for a particular tab - see NewDOMUI<ExtensionDOMUI>.
static DOMUIFactoryFunction GetDOMUIFactoryFunction(Profile* profile,
const GURL& url) {
// Currently, any gears: URL means an HTML dialog.
if (url.SchemeIs(chrome::kGearsScheme))
return &NewDOMUI<HtmlDialogUI>;
if (url.host() == chrome::kChromeUIDialogHost)
return &NewDOMUI<ConstrainedHtmlUI>;
ExtensionsService* service = profile->GetExtensionsService();
if (service && service->ExtensionBindingsAllowed(url))
return &NewDOMUI<ExtensionDOMUI>;
// All platform builds of Chrome will need to have a cloud printing
// dialog as backup. It's just that on Chrome OS, it's the only
// print dialog.
if (url.host() == chrome::kCloudPrintResourcesHost)
return &NewDOMUI<ExternalHtmlDialogUI>;
// This will get called a lot to check all URLs, so do a quick check of other
// schemes (gears was handled above) to filter out most URLs.
if (!url.SchemeIs(chrome::kChromeDevToolsScheme) &&
!url.SchemeIs(chrome::kChromeInternalScheme) &&
!url.SchemeIs(chrome::kChromeUIScheme))
return NULL;
if (url.host() == chrome::kChromeUISyncResourcesHost ||
url.host() == chrome::kChromeUIRemotingResourcesHost)
return &NewDOMUI<HtmlDialogUI>;
// Special case the new tab page. In older versions of Chrome, the new tab
// page was hosted at chrome-internal:<blah>. This might be in people's saved
// sessions or bookmarks, so we say any URL with that scheme triggers the new
// tab page.
if (url.host() == chrome::kChromeUINewTabHost ||
url.SchemeIs(chrome::kChromeInternalScheme))
return &NewDOMUI<NewTabUI>;
// Give about:about a generic DOM UI so it can navigate to pages with DOM UIs.
if (url.spec() == chrome::kChromeUIAboutAboutURL)
return &NewDOMUI<DOMUI>;
// We must compare hosts only since some of the DOM UIs append extra stuff
// after the host name.
if (url.host() == chrome::kChromeUIBookmarksHost)
return &NewDOMUI<BookmarksUI>;
if (url.host() == chrome::kChromeUIBugReportHost)
return &NewDOMUI<BugReportUI>;
if (url.host() == chrome::kChromeUIDevToolsHost)
return &NewDOMUI<DevToolsUI>;
#if defined(OS_WIN)
if (url.host() == chrome::kChromeUIConflictsHost)
return &NewDOMUI<ConflictsUI>;
#endif
if (url.host() == chrome::kChromeUIDownloadsHost)
return &NewDOMUI<DownloadsUI>;
if (url.host() == chrome::kChromeUITextfieldsHost)
return &NewDOMUI<TextfieldsUI>;
if (url.host() == chrome::kChromeUIExtensionsHost)
return &NewDOMUI<ExtensionsUI>;
if (url.host() == chrome::kChromeUIHistoryHost)
return &NewDOMUI<HistoryUI>;
if (url.host() == chrome::kChromeUIHistory2Host)
return &NewDOMUI<HistoryUI2>;
if (url.host() == chrome::kChromeUIFlagsHost)
return &NewDOMUI<FlagsUI>;
#if defined(TOUCH_UI)
if (url.host() == chrome::kChromeUIKeyboardHost)
return &NewDOMUI<KeyboardUI>;
#endif
if (url.host() == chrome::kChromeUINetInternalsHost)
return &NewDOMUI<NetInternalsUI>;
if (url.host() == chrome::kChromeUIPluginsHost)
return &NewDOMUI<PluginsUI>;
#if defined(ENABLE_REMOTING)
if (url.host() == chrome::kChromeUIRemotingHost) {
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableRemoting)) {
return &NewDOMUI<RemotingUI>;
}
}
#endif
#if defined(OS_CHROMEOS)
if (url.host() == chrome::kChromeUIFileBrowseHost)
return &NewDOMUI<FileBrowseUI>;
if (url.host() == chrome::kChromeUIImageBurnerHost)
return &NewDOMUI<ImageBurnUI>;
if (url.host() == chrome::kChromeUIKeyboardOverlayHost)
return &NewDOMUI<KeyboardOverlayUI>;
if (url.host() == chrome::kChromeUIMediaplayerHost)
return &NewDOMUI<MediaplayerUI>;
if (url.host() == chrome::kChromeUIMobileSetupHost)
return &NewDOMUI<MobileSetupUI>;
if (url.host() == chrome::kChromeUIRegisterPageHost)
return &NewDOMUI<RegisterPageUI>;
if (url.host() == chrome::kChromeUISettingsHost)
return &NewDOMUI<OptionsUI>;
if (url.host() == chrome::kChromeUISlideshowHost)
return &NewDOMUI<SlideshowUI>;
if (url.host() == chrome::kChromeUISystemInfoHost)
return &NewDOMUI<SystemInfoUI>;
if (url.host() == chrome::kChromeUIMenu)
return &NewDOMUI<chromeos::MenuUI>;
if (url.host() == chrome::kChromeUIWrenchMenu)
return &NewDOMUI<chromeos::WrenchMenuUI>;
if (url.host() == chrome::kChromeUINetworkMenu)
return &NewDOMUI<chromeos::NetworkMenuUI>;
#else
if (url.host() == chrome::kChromeUISettingsHost) {
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableTabbedOptions)) {
return &NewDOMUI<OptionsUI>;
}
}
if (url.host() == chrome::kChromeUIPrintHost) {
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnablePrintPreview)) {
return &NewDOMUI<PrintPreviewUI>;
}
}
#endif
if (url.spec() == chrome::kChromeUIConstrainedHTMLTestURL)
return &NewDOMUI<ConstrainedHtmlUI>;
return NULL;
}
// static
DOMUITypeID DOMUIFactory::GetDOMUIType(Profile* profile, const GURL& url) {
DOMUIFactoryFunction function = GetDOMUIFactoryFunction(profile, url);
return function ? reinterpret_cast<DOMUITypeID>(function) : kNoDOMUI;
}
// static
bool DOMUIFactory::HasDOMUIScheme(const GURL& url) {
return url.SchemeIs(chrome::kChromeDevToolsScheme) ||
url.SchemeIs(chrome::kChromeInternalScheme) ||
url.SchemeIs(chrome::kChromeUIScheme) ||
url.SchemeIs(chrome::kExtensionScheme);
}
// static
bool DOMUIFactory::UseDOMUIForURL(Profile* profile, const GURL& url) {
return GetDOMUIFactoryFunction(profile, url) != NULL;
}
// static
bool DOMUIFactory::IsURLAcceptableForDOMUI(Profile* profile, const GURL& url) {
return UseDOMUIForURL(profile, url) ||
// javacsript: URLs are allowed to run in DOM UI pages
url.SchemeIs(chrome::kJavaScriptScheme) ||
// It's possible to load about:blank in a DOM UI renderer.
// See http://crbug.com/42547
url.spec() == chrome::kAboutBlankURL ||
// about:crash, about:hang, and about:shorthang are allowed.
url.spec() == chrome::kAboutCrashURL ||
url.spec() == chrome::kAboutHangURL ||
url.spec() == chrome::kAboutShorthangURL;
}
// static
DOMUI* DOMUIFactory::CreateDOMUIForURL(TabContents* tab_contents,
const GURL& url) {
DOMUIFactoryFunction function = GetDOMUIFactoryFunction(
tab_contents->profile(), url);
if (!function)
return NULL;
return (*function)(tab_contents, url);
}
// static
void DOMUIFactory::GetFaviconForURL(Profile* profile,
FaviconService::GetFaviconRequest* request,
const GURL& page_url) {
// All extensions but the bookmark manager get their favicon from the icons
// part of the manifest.
if (page_url.SchemeIs(chrome::kExtensionScheme) &&
page_url.host() != extension_misc::kBookmarkManagerId) {
ExtensionDOMUI::GetFaviconForURL(profile, request, page_url);
} else {
scoped_refptr<RefCountedMemory> icon_data(
DOMUIFactory::GetFaviconResourceBytes(profile, page_url));
bool know_icon = icon_data.get() != NULL && icon_data->size() > 0;
request->ForwardResultAsync(
FaviconService::FaviconDataCallback::TupleType(request->handle(),
know_icon, icon_data, false, GURL()));
}
}
// static
RefCountedMemory* DOMUIFactory::GetFaviconResourceBytes(Profile* profile,
const GURL& page_url) {
// The bookmark manager is a chrome extension, so we have to check for it
// before we check for extension scheme.
if (page_url.host() == extension_misc::kBookmarkManagerId)
return BookmarksUI::GetFaviconResourceBytes();
// The extension scheme is handled in GetFaviconForURL.
if (page_url.SchemeIs(chrome::kExtensionScheme)) {
NOTREACHED();
return NULL;
}
if (!HasDOMUIScheme(page_url))
return NULL;
#if defined(OS_WIN)
if (page_url.host() == chrome::kChromeUIConflictsHost)
return ConflictsUI::GetFaviconResourceBytes();
#endif
if (page_url.host() == chrome::kChromeUIDownloadsHost)
return DownloadsUI::GetFaviconResourceBytes();
if (page_url.host() == chrome::kChromeUIExtensionsHost)
return ExtensionsUI::GetFaviconResourceBytes();
if (page_url.host() == chrome::kChromeUIHistoryHost)
return HistoryUI::GetFaviconResourceBytes();
if (page_url.host() == chrome::kChromeUIHistory2Host)
return HistoryUI2::GetFaviconResourceBytes();
if (page_url.host() == chrome::kChromeUIFlagsHost)
return FlagsUI::GetFaviconResourceBytes();
if (page_url.host() == chrome::kChromeUISettingsHost)
return OptionsUI::GetFaviconResourceBytes();
if (page_url.host() == chrome::kChromeUIPluginsHost)
return PluginsUI::GetFaviconResourceBytes();
#if defined(ENABLE_REMOTING)
if (page_url.host() == chrome::kChromeUIRemotingHost)
return RemotingUI::GetFaviconResourceBytes();
#endif
return NULL;
}
|