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
|
// Copyright (c) 2009 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 "chrome/browser/dom_ui/downloads_ui.h"
#include "chrome/browser/dom_ui/debugger_ui.h"
#include "chrome/browser/dom_ui/devtools_ui.h"
#include "chrome/browser/dom_ui/history_ui.h"
#include "chrome/browser/dom_ui/html_dialog_ui.h"
#include "chrome/browser/dom_ui/new_tab_ui.h"
#include "chrome/browser/extensions/extensions_ui.h"
#include "chrome/common/url_constants.h"
#ifdef CHROME_PERSONALIZATION
#include "chrome/personalization/personalization.h"
#endif
#include "googleurl/src/gurl.h"
// Backend for both querying for and creating new DOMUI objects. If you're just
// querying whether there's a DOM UI for the given URL, pass NULL for both the
// web contents and the new_ui. The return value will indiacate whether a DOM UI
// exists for the given URL.
//
// If you want to create a DOM UI, pass non-NULL pointers for both tab_contents
// and new_ui. The *new_ui pointer will be filled with the created UI if it
// succeeds (indicated by a return value of true). The caller owns the *new_ui
// pointer.
static bool CreateDOMUI(const GURL& url, TabContents* tab_contents,
DOMUI** new_ui) {
// Currently, any gears: URL means an HTML dialog.
if (url.SchemeIs(chrome::kGearsScheme)) {
if (new_ui)
*new_ui = new HtmlDialogUI(tab_contents);
return true;
}
#ifdef CHROME_PERSONALIZATION
if (Personalization::NeedsDOMUI(url)) {
if (new_ui)
*new_ui = new HtmlDialogUI(tab_contents);
return true;
}
#endif
// 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::kChromeInternalScheme) &&
!url.SchemeIs(chrome::kChromeUIScheme))
return false;
// 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)) {
if (new_ui)
*new_ui = new NewTabUI(tab_contents);
return true;
}
// We must compare hosts only since some of the DOM UIs append extra stuff
// after the host name.
if (url.host() == chrome::kChromeUIHistoryHost) {
if (new_ui)
*new_ui = new HistoryUI(tab_contents);
return true;
}
if (url.host() == chrome::kChromeUIDownloadsHost) {
if (new_ui)
*new_ui = new DownloadsUI(tab_contents);
return true;
}
if (url.host() == chrome::kChromeUIExtensionsHost) {
if (new_ui)
*new_ui = new ExtensionsUI(tab_contents);
return true;
}
if (url.host() == chrome::kChromeUIInspectorHost) {
if (new_ui)
*new_ui = new DebuggerUI(tab_contents);
return true;
}
if (url.host() == chrome::kChromeUIDevToolsHost) {
if (new_ui)
*new_ui = new DevToolsUI(tab_contents);
return true;
}
return false;
}
// static
bool DOMUIFactory::HasDOMUIScheme(const GURL& url) {
return url.SchemeIs(chrome::kChromeInternalScheme) ||
url.SchemeIs(chrome::kChromeUIScheme);
}
// static
bool DOMUIFactory::UseDOMUIForURL(const GURL& url) {
return CreateDOMUI(url, NULL, NULL);
}
// static
DOMUI* DOMUIFactory::CreateDOMUIForURL(TabContents* tab_contents,
const GURL& url) {
DOMUI* dom_ui;
if (!CreateDOMUI(url, tab_contents, &dom_ui))
return NULL;
return dom_ui;
}
|