diff options
author | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-02 22:40:20 +0000 |
---|---|---|
committer | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-02 22:40:20 +0000 |
commit | bce1e59121a045815e47060dbb3525d4fea7b4fb (patch) | |
tree | 60201058b1ed256654176aaa6e092488303ee088 /chrome/browser/dom_ui | |
parent | 5f507c9644ada6a6d2856c6920767c5f2cedd7b8 (diff) | |
download | chromium_src-bce1e59121a045815e47060dbb3525d4fea7b4fb.zip chromium_src-bce1e59121a045815e47060dbb3525d4fea7b4fb.tar.gz chromium_src-bce1e59121a045815e47060dbb3525d4fea7b4fb.tar.bz2 |
Revert r25250: "Allow DOMUI pages to call window.open(), giving DOMUI privileges to the new"
Review URL: http://codereview.chromium.org/171127
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25256 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_factory.cc | 139 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_factory.h | 13 |
2 files changed, 79 insertions, 73 deletions
diff --git a/chrome/browser/dom_ui/dom_ui_factory.cc b/chrome/browser/dom_ui/dom_ui_factory.cc index cdfbd7f..f776baa 100644 --- a/chrome/browser/dom_ui/dom_ui_factory.cc +++ b/chrome/browser/dom_ui/dom_ui_factory.cc @@ -18,83 +18,102 @@ #include "chrome/common/url_constants.h" #include "googleurl/src/gurl.h" -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 non-existent extensions. - ExtensionsService* service = contents->profile()->GetExtensionsService(); - bool valid_extension = (service && service->GetExtensionById(url.host())); - if (valid_extension) - return new ExtensionDOMUI(contents); - 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(const GURL& url) { +// 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)) - return &NewDOMUI<HtmlDialogUI>; - - if (url.SchemeIs(chrome::kExtensionScheme)) - return &NewDOMUI<ExtensionDOMUI>; + if (url.SchemeIs(chrome::kGearsScheme)) { + if (new_ui) + *new_ui = new HtmlDialogUI(tab_contents); + return true; + } + + if (url.SchemeIs(chrome::kExtensionScheme)) { + // We assume we have a valid extension unless we have a TabContents which + // can prove us wrong. This can can happen if the user types in a URL + // manually. + bool valid_extension = true; + if (tab_contents) { + // TabContents can be NULL if we're doing a quick UseDOMUIForURL check. + ExtensionsService* service = + tab_contents->profile()->GetExtensionsService(); + valid_extension = (service && service->GetExtensionById(url.host())); + } + if (valid_extension) { + if (new_ui) + *new_ui = new ExtensionDOMUI(tab_contents); + return true; + } + return false; + } // TODO(mhm) Make sure this ifdef is removed once print is complete. #if !defined(GOOGLE_CHROME_BUILD) - if (url.SchemeIs(chrome::kPrintScheme)) - return &NewDOMUI<PrintUI>; + if (url.SchemeIs(chrome::kPrintScheme)) { + if (new_ui) + *new_ui = new PrintUI(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 NULL; + return false; - if (url.host() == chrome::kSyncResourcesHost) - return &NewDOMUI<HtmlDialogUI>; + if (url.host() == chrome::kSyncResourcesHost) { + if (new_ui) + *new_ui = new HtmlDialogUI(tab_contents); + return true; + } // 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>; + 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) - return &NewDOMUI<HistoryUI>; - if (url.host() == chrome::kChromeUIDownloadsHost) - return &NewDOMUI<DownloadsUI>; - if (url.host() == chrome::kChromeUIExtensionsHost) - return &NewDOMUI<ExtensionsUI>; - if (url.host() == chrome::kChromeUIDevToolsHost) - return &NewDOMUI<DevToolsUI>; - - return NULL; -} + 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::kChromeUIDevToolsHost) { + if (new_ui) + *new_ui = new DevToolsUI(tab_contents); + return true; + } -// static -DOMUITypeID DOMUIFactory::GetDOMUIType(const GURL& url) { - DOMUIFactoryFunction function = GetDOMUIFactoryFunction(url); - return function ? reinterpret_cast<DOMUITypeID>(function) : kNoDOMUI; + return false; } // static @@ -107,16 +126,16 @@ bool DOMUIFactory::HasDOMUIScheme(const GURL& url) { // static bool DOMUIFactory::UseDOMUIForURL(const GURL& url) { - return GetDOMUIFactoryFunction(url) != NULL; + return CreateDOMUI(url, NULL, NULL); } // static DOMUI* DOMUIFactory::CreateDOMUIForURL(TabContents* tab_contents, const GURL& url) { - DOMUIFactoryFunction function = GetDOMUIFactoryFunction(url); - if (!function) + DOMUI* dom_ui; + if (!CreateDOMUI(url, tab_contents, &dom_ui)) return NULL; - return (*function)(tab_contents, url); + return dom_ui; } // static diff --git a/chrome/browser/dom_ui/dom_ui_factory.h b/chrome/browser/dom_ui/dom_ui_factory.h index db1500c..e4e36c3 100644 --- a/chrome/browser/dom_ui/dom_ui_factory.h +++ b/chrome/browser/dom_ui/dom_ui_factory.h @@ -11,21 +11,8 @@ class DOMUI; class GURL; class TabContents; -// An opaque identifier used to identify a DOMUI. This can only be compared to -// kNoDOMUI or other DOMUI types. See GetDOMUIType. -typedef void* DOMUITypeID; - class DOMUIFactory { public: - // A special DOMUI type that signifies that a given page would not use the - // DOM UI system. - static const DOMUITypeID kNoDOMUI; - - // Returns a type identifier indicating what DOMUI we would use for the - // given URL. This is useful for comparing the potential DOMUIs for two URLs. - // Returns kNoDOMUI if the given URL will not use the DOM UI system. - static DOMUITypeID GetDOMUIType(const GURL& url); - // Returns true if the given URL's scheme would trigger the DOM UI system. // This is a less precise test than UseDONUIForURL, which tells you whether // that specific URL matches a known one. This one is faster and can be used |