diff options
author | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-14 00:38:12 +0000 |
---|---|---|
committer | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-14 00:38:12 +0000 |
commit | 73852b8f9c03c6b7a27436f828ed888f71232257 (patch) | |
tree | da07fd53317f13964f93383f9591fcdfdfa61ea7 /chrome/browser/dom_ui | |
parent | 564551a2ece790b22fd2a70aeb8591805fe943be (diff) | |
download | chromium_src-73852b8f9c03c6b7a27436f828ed888f71232257.zip chromium_src-73852b8f9c03c6b7a27436f828ed888f71232257.tar.gz chromium_src-73852b8f9c03c6b7a27436f828ed888f71232257.tar.bz2 |
[Large; Chromium OS] Work to host the cloud print dialog when built
for Chromium OS. Currently disabled by default behind a command line
switch, and containing a non-real URL for now, this code is at
prototype level. It works (when enabled and pointed at a functioning
cloud print service URL), has the beginnings of some unit tests, and
has the beginnings of deeper communication with the dialog contents,
and it shuts off the DOM UI access from the dialog contents.
Patch contributed by Scott Byer
Review URL: http://codereview.chromium.org/1769006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47228 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_factory.cc | 7 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_util.cc | 37 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_util.h | 34 | ||||
-rw-r--r-- | chrome/browser/dom_ui/html_dialog_ui.cc | 42 | ||||
-rw-r--r-- | chrome/browser/dom_ui/html_dialog_ui.h | 17 |
5 files changed, 113 insertions, 24 deletions
diff --git a/chrome/browser/dom_ui/dom_ui_factory.cc b/chrome/browser/dom_ui/dom_ui_factory.cc index bdbfa9a..b9af9ee 100644 --- a/chrome/browser/dom_ui/dom_ui_factory.cc +++ b/chrome/browser/dom_ui/dom_ui_factory.cc @@ -19,6 +19,7 @@ #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/url_constants.h" @@ -69,6 +70,12 @@ static DOMUIFactoryFunction GetDOMUIFactoryFunction(const GURL& url) { return &NewDOMUI<PrintUI>; #endif + // 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::kChromeInternalScheme) && diff --git a/chrome/browser/dom_ui/dom_ui_util.cc b/chrome/browser/dom_ui/dom_ui_util.cc new file mode 100644 index 0000000..e247655 --- /dev/null +++ b/chrome/browser/dom_ui/dom_ui_util.cc @@ -0,0 +1,37 @@ +// 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_util.h" + +#include "base/logging.h" +#include "base/values.h" + +namespace dom_ui_util { + +std::string GetJsonResponseFromFirstArgumentInList(const Value* content) { + return GetJsonResponseFromArgumentList(content, 0); +} + +std::string GetJsonResponseFromArgumentList(const Value* content, + size_t list_index) { + std::string result; + + if (!content || !content->IsType(Value::TYPE_LIST)) { + NOTREACHED(); + return result; + } + const ListValue* args = static_cast<const ListValue*>(content); + if (args->GetSize() <= list_index) { + NOTREACHED(); + return result; + } + + Value* value = NULL; + if (args->Get(list_index, &value)) + value->GetAsString(&result); + + return result; +} + +} // end of namespace dom_ui_util diff --git a/chrome/browser/dom_ui/dom_ui_util.h b/chrome/browser/dom_ui/dom_ui_util.h new file mode 100644 index 0000000..48c68a1 --- /dev/null +++ b/chrome/browser/dom_ui/dom_ui_util.h @@ -0,0 +1,34 @@ +// 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. + +#ifndef CHROME_BROWSER_DOM_UI_DOM_UI_UTIL_H_ +#define CHROME_BROWSER_DOM_UI_DOM_UI_UTIL_H_ + +#include <string> + +class Value; + +namespace dom_ui_util { + +// Convenience routine to get the response string from an argument +// list. Typically used when supporting a DOMUI and getting calls +// from the hosted code. Content must be a ListValue with at least +// one entry in it, and that first entry must be a string, which is +// returned. The parameter is a Value for convenience. Returns an +// empty string on error or if the parameter is not a ListValue. +std::string GetJsonResponseFromFirstArgumentInList(const Value* content); + +// Convenience routine to get one of the response strings from an +// argument list. content must be a ListValue, with at least +// (list_index+1) entries in it. list_index is the 0-based index of +// the entry to pull from that list, and that entry must be a string, +// which is returned. The parameter is a Value for convenience. +// Returns an empty string on error or if the parameter is not a +// ListValue. +std::string GetJsonResponseFromArgumentList(const Value* content, + size_t list_index); + +} // end of namespace + +#endif // CHROME_BROWSER_DOM_UI_DOM_UI_UTIL_H_ diff --git a/chrome/browser/dom_ui/html_dialog_ui.cc b/chrome/browser/dom_ui/html_dialog_ui.cc index 739a4c4..f93e9ca 100644 --- a/chrome/browser/dom_ui/html_dialog_ui.cc +++ b/chrome/browser/dom_ui/html_dialog_ui.cc @@ -7,8 +7,10 @@ #include "base/callback.h" #include "base/singleton.h" #include "base/values.h" +#include "chrome/browser/dom_ui/dom_ui_util.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/renderer_host/render_view_host.h" +#include "chrome/common/bindings_policy.h" HtmlDialogUI::HtmlDialogUI(TabContents* tab_contents) : DOMUI(tab_contents) { } @@ -32,28 +34,6 @@ PropertyAccessor<HtmlDialogUIDelegate*>& HtmlDialogUI::GetPropertyAccessor() { //////////////////////////////////////////////////////////////////////////////// // Private: -// Helper function to read the JSON string from the Value parameter. -static std::string GetJsonResponse(const Value* content) { - if (!content || !content->IsType(Value::TYPE_LIST)) { - NOTREACHED(); - return std::string(); - } - const ListValue* args = static_cast<const ListValue*>(content); - if (args->GetSize() != 1) { - NOTREACHED(); - return std::string(); - } - - std::string result; - Value* value = NULL; - if (!args->Get(0, &value) || !value->GetAsString(&result)) { - NOTREACHED(); - return std::string(); - } - - return result; -} - void HtmlDialogUI::RenderViewCreated(RenderViewHost* render_view_host) { // Hook up the javascript function calls, also known as chrome.send("foo") // calls in the HTML, to the actual C++ functions. @@ -70,7 +50,8 @@ void HtmlDialogUI::RenderViewCreated(RenderViewHost* render_view_host) { (*delegate)->GetDOMMessageHandlers(&handlers); } - render_view_host->SetDOMUIProperty("dialogArguments", dialog_args); + if (0 != (bindings_ & BindingsPolicy::DOM_UI)) + render_view_host->SetDOMUIProperty("dialogArguments", dialog_args); for (std::vector<DOMMessageHandler*>::iterator it = handlers.begin(); it != handlers.end(); ++it) { (*it)->Attach(this); @@ -82,5 +63,18 @@ void HtmlDialogUI::OnDialogClosed(const Value* content) { HtmlDialogUIDelegate** delegate = GetPropertyAccessor().GetProperty( tab_contents()->property_bag()); if (delegate) - (*delegate)->OnDialogClosed(GetJsonResponse(content)); + (*delegate)->OnDialogClosed( + dom_ui_util::GetJsonResponseFromFirstArgumentInList(content)); +} + +ExternalHtmlDialogUI::ExternalHtmlDialogUI(TabContents* tab_contents) + : HtmlDialogUI(tab_contents) { + // Non-file based UI needs to not have access to the DOM UI bindings + // for security reasons. The code hosting the dialog should provide + // dialog specific functionality through other bindings and methods + // that are scoped in duration to the dialogs existence. + bindings_ &= ~BindingsPolicy::DOM_UI; +} + +ExternalHtmlDialogUI::~ExternalHtmlDialogUI() { } diff --git a/chrome/browser/dom_ui/html_dialog_ui.h b/chrome/browser/dom_ui/html_dialog_ui.h index ffc5196..be2df7f 100644 --- a/chrome/browser/dom_ui/html_dialog_ui.h +++ b/chrome/browser/dom_ui/html_dialog_ui.h @@ -44,6 +44,12 @@ class HtmlDialogUIDelegate { // A callback to notify the delegate that the dialog closed. virtual void OnDialogClosed(const std::string& json_retval) = 0; + // A callback to notify the delegate that the contents have gone + // away. Only relevant if your dialog hosts code that calls + // windows.close() and you've allowed that. If the output parameter + // is set to true, then the dialog is closed. The default is false. + virtual void OnCloseContents(TabContents* source, bool* out_close_dialog) = 0; + protected: ~HtmlDialogUIDelegate() {} }; @@ -89,4 +95,15 @@ class HtmlDialogUI : public DOMUI { DISALLOW_COPY_AND_ASSIGN(HtmlDialogUI); }; +// Displays external URL contents inside a modal HTML dialog. +// +// Intended to be the place to collect the settings and lockdowns +// necessary for running external UI conponents securely (e.g., the +// cloud print dialog). +class ExternalHtmlDialogUI : public HtmlDialogUI { + public: + explicit ExternalHtmlDialogUI(TabContents* tab_contents); + virtual ~ExternalHtmlDialogUI(); +}; + #endif // CHROME_BROWSER_DOM_UI_HTML_DIALOG_UI_H_ |