Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: chrome/browser/dom_ui/dom_ui_factory.cc

Issue 3263007: Reland r57788 - Expose Extension Bindings to Component Applications (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: don't hide gallery url in omnibar Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_factory.h" 5 #include "chrome/browser/dom_ui/dom_ui_factory.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/browser/chrome_thread.h" 8 #include "chrome/browser/chrome_thread.h"
9 #include "chrome/browser/dom_ui/bookmarks_ui.h" 9 #include "chrome/browser/dom_ui/bookmarks_ui.h"
10 #include "chrome/browser/dom_ui/bug_report_ui.h" 10 #include "chrome/browser/dom_ui/bug_report_ui.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 // Template for defining DOMUIFactoryFunction. 49 // Template for defining DOMUIFactoryFunction.
50 template<class T> 50 template<class T>
51 DOMUI* NewDOMUI(TabContents* contents, const GURL& url) { 51 DOMUI* NewDOMUI(TabContents* contents, const GURL& url) {
52 return new T(contents); 52 return new T(contents);
53 } 53 }
54 54
55 // Special case for extensions. 55 // Special case for extensions.
56 template<> 56 template<>
57 DOMUI* NewDOMUI<ExtensionDOMUI>(TabContents* contents, const GURL& url) { 57 DOMUI* NewDOMUI<ExtensionDOMUI>(TabContents* contents, const GURL& url) {
58 // Don't use a DOMUI for non-existent extensions or for incognito tabs. The 58 // Don't use a DOMUI for incognito tabs because we require extensions to run
59 // latter restriction is because we require extensions to run within a single 59 // within a single process.
60 // process.
61 ExtensionsService* service = contents->profile()->GetExtensionsService(); 60 ExtensionsService* service = contents->profile()->GetExtensionsService();
62 bool valid_extension = 61 if (service &&
63 (service && service->GetExtensionById(url.host(), false)); 62 service->ExtensionBindingsAllowed(url) &&
64 if (valid_extension && !contents->profile()->IsOffTheRecord()) 63 !contents->profile()->IsOffTheRecord()) {
65 return new ExtensionDOMUI(contents); 64 return new ExtensionDOMUI(contents, url);
65 }
66 return NULL; 66 return NULL;
67 } 67 }
68 68
69 // Returns a function that can be used to create the right type of DOMUI for a 69 // Returns a function that can be used to create the right type of DOMUI for a
70 // tab, based on its URL. Returns NULL if the URL doesn't have DOMUI associated 70 // tab, based on its URL. Returns NULL if the URL doesn't have DOMUI associated
71 // with it. Even if the factory function is valid, it may yield a NULL DOMUI 71 // with it. Even if the factory function is valid, it may yield a NULL DOMUI
72 // when invoked for a particular tab - see NewDOMUI<ExtensionDOMUI>. 72 // when invoked for a particular tab - see NewDOMUI<ExtensionDOMUI>.
73 static DOMUIFactoryFunction GetDOMUIFactoryFunction(const GURL& url) { 73 static DOMUIFactoryFunction GetDOMUIFactoryFunction(Profile* profile,
74 const GURL& url) {
74 // Currently, any gears: URL means an HTML dialog. 75 // Currently, any gears: URL means an HTML dialog.
75 if (url.SchemeIs(chrome::kGearsScheme)) 76 if (url.SchemeIs(chrome::kGearsScheme))
76 return &NewDOMUI<HtmlDialogUI>; 77 return &NewDOMUI<HtmlDialogUI>;
77 78
78 if (url.SchemeIs(chrome::kExtensionScheme)) 79 ExtensionsService* service = profile->GetExtensionsService();
80 if (service && service->ExtensionBindingsAllowed(url))
79 return &NewDOMUI<ExtensionDOMUI>; 81 return &NewDOMUI<ExtensionDOMUI>;
80 82
81 // All platform builds of Chrome will need to have a cloud printing 83 // All platform builds of Chrome will need to have a cloud printing
82 // dialog as backup. It's just that on Chrome OS, it's the only 84 // dialog as backup. It's just that on Chrome OS, it's the only
83 // print dialog. 85 // print dialog.
84 if (url.host() == chrome::kCloudPrintResourcesHost) 86 if (url.host() == chrome::kCloudPrintResourcesHost)
85 return &NewDOMUI<ExternalHtmlDialogUI>; 87 return &NewDOMUI<ExternalHtmlDialogUI>;
86 88
87 // This will get called a lot to check all URLs, so do a quick check of other 89 // This will get called a lot to check all URLs, so do a quick check of other
88 // schemes (gears was handled above) to filter out most URLs. 90 // schemes (gears was handled above) to filter out most URLs.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 switches::kEnableTabbedOptions)) { 154 switches::kEnableTabbedOptions)) {
153 return &NewDOMUI<OptionsUI>; 155 return &NewDOMUI<OptionsUI>;
154 } 156 }
155 } 157 }
156 #endif 158 #endif
157 159
158 return NULL; 160 return NULL;
159 } 161 }
160 162
161 // static 163 // static
162 DOMUITypeID DOMUIFactory::GetDOMUIType(const GURL& url) { 164 DOMUITypeID DOMUIFactory::GetDOMUIType(Profile* profile, const GURL& url) {
163 DOMUIFactoryFunction function = GetDOMUIFactoryFunction(url); 165 DOMUIFactoryFunction function = GetDOMUIFactoryFunction(profile, url);
164 return function ? reinterpret_cast<DOMUITypeID>(function) : kNoDOMUI; 166 return function ? reinterpret_cast<DOMUITypeID>(function) : kNoDOMUI;
165 } 167 }
166 168
167 // static 169 // static
168 bool DOMUIFactory::HasDOMUIScheme(const GURL& url) { 170 bool DOMUIFactory::HasDOMUIScheme(const GURL& url) {
169 return url.SchemeIs(chrome::kChromeInternalScheme) || 171 return url.SchemeIs(chrome::kChromeInternalScheme) ||
170 url.SchemeIs(chrome::kChromeUIScheme) || 172 url.SchemeIs(chrome::kChromeUIScheme) ||
171 url.SchemeIs(chrome::kExtensionScheme); 173 url.SchemeIs(chrome::kExtensionScheme);
172 } 174 }
173 175
174 // static 176 // static
175 bool DOMUIFactory::UseDOMUIForURL(const GURL& url) { 177 bool DOMUIFactory::UseDOMUIForURL(Profile* profile, const GURL& url) {
176 return GetDOMUIFactoryFunction(url) != NULL; 178 return GetDOMUIFactoryFunction(profile, url) != NULL;
177 } 179 }
178 180
179 // static 181 // static
180 DOMUI* DOMUIFactory::CreateDOMUIForURL(TabContents* tab_contents, 182 DOMUI* DOMUIFactory::CreateDOMUIForURL(TabContents* tab_contents,
181 const GURL& url) { 183 const GURL& url) {
182 DOMUIFactoryFunction function = GetDOMUIFactoryFunction(url); 184 DOMUIFactoryFunction function = GetDOMUIFactoryFunction(
185 tab_contents->profile(), url);
183 if (!function) 186 if (!function)
184 return NULL; 187 return NULL;
185 return (*function)(tab_contents, url); 188 return (*function)(tab_contents, url);
186 } 189 }
187 190
188 // static 191 // static
189 void DOMUIFactory::GetFaviconForURL(Profile* profile, 192 void DOMUIFactory::GetFaviconForURL(Profile* profile,
190 FaviconService::GetFaviconRequest* request, 193 FaviconService::GetFaviconRequest* request,
191 const GURL& page_url) { 194 const GURL& page_url) {
192 // All extensions but the bookmark manager get their favicon from the icons 195 // All extensions but the bookmark manager get their favicon from the icons
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 if (page_url.host() == chrome::kChromeUIPluginsHost) 245 if (page_url.host() == chrome::kChromeUIPluginsHost)
243 return PluginsUI::GetFaviconResourceBytes(); 246 return PluginsUI::GetFaviconResourceBytes();
244 247
245 #if defined(ENABLE_REMOTING) 248 #if defined(ENABLE_REMOTING)
246 if (page_url.host() == chrome::kChromeUIRemotingHost) 249 if (page_url.host() == chrome::kChromeUIRemotingHost)
247 return RemotingUI::GetFaviconResourceBytes(); 250 return RemotingUI::GetFaviconResourceBytes();
248 #endif 251 #endif
249 252
250 return NULL; 253 return NULL;
251 } 254 }
OLDNEW
« no previous file with comments | « chrome/browser/dom_ui/dom_ui_factory.h ('k') | chrome/browser/extensions/app_process_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698