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

Unified Diff: ui/web_dialogs/web_dialog_ui.h

Issue 10353007: Extract a minimal subset of WebDialogUI/WebDialogDelegate from src/chrome -> src/ui/web_dialogs Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 8 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: ui/web_dialogs/web_dialog_ui.h
===================================================================
--- ui/web_dialogs/web_dialog_ui.h (revision 0)
+++ ui/web_dialogs/web_dialog_ui.h (revision 0)
@@ -0,0 +1,168 @@
+// Copyright (c) 2012 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 UI_WEB_DIALOGS_WEB_DIALOG_UI_H_
+#define UI_WEB_DIALOGS_WEB_DIALOG_UI_H_
+#pragma once
+
+#include <string>
+#include <vector>
+
+#include "ui/views/views_export.h"
mazda 2012/05/03 22:56:22 You need to create "ui/web_dialogs/web_dialogs_exp
+
+#include "base/compiler_specific.h"
+#include "base/string16.h"
+#include "content/public/browser/web_contents_delegate.h"
+#include "content/public/browser/web_ui_controller.h"
+#include "googleurl/src/gurl.h"
+#include "ui/base/ui_base_types.h"
+
+
+namespace base {
+class ListValue;
+template<class T> class PropertyAccessor;
+}
+
+namespace content {
+class WebContents;
+class WebUIMessageHandler;
+struct ContextMenuParams;
+}
+
+namespace gfx {
+class Size;
+}
+
+namespace views {
mazda 2012/05/03 22:56:22 This should not be in views namespace.
tfarina 2012/05/03 23:17:29 either ui or web_dialogs. My preference is for ui
+// Implement this class to receive notifications.
+class VIEWS_EXPORT WebDialogDelegate {
mazda 2012/05/03 22:56:22 WEB_DIALOGS_EXPORT
tfarina 2012/05/03 22:59:53 And this class should be in its own header file pe
+ public:
+ // Returns true if the contents needs to be run in a modal dialog.
+ virtual ui::ModalType GetDialogModalType() const = 0;
+
+ // Returns the title of the dialog.
+ virtual string16 GetDialogTitle() const = 0;
+
+ // Returns the dialog's name identifier. Used to identify this dialog for
+ // state restoration.
+ virtual std::string GetDialogName() const;
+
+ // Get the HTML file path for the content to load in the dialog.
+ virtual GURL GetDialogContentURL() const = 0;
+
+ // Get WebUIMessageHandler objects to handle messages from the HTML/JS page.
+ // The handlers are used to send and receive messages from the page while it
+ // is still open. Ownership of each handler is taken over by the WebUI
+ // hosting the page.
+ virtual void GetWebUIMessageHandlers(
+ std::vector<content::WebUIMessageHandler*>* handlers) const = 0;
+
+ // Get the size of the dialog.
+ virtual void GetDialogSize(gfx::Size* size) const = 0;
+
+ // Get the size of the dialog.
+ virtual void GetMinimumDialogSize(gfx::Size* size) const;
+
+ // Gets the JSON string input to use when showing the dialog.
+ virtual std::string GetDialogArgs() const = 0;
+
+ // A callback to notify the delegate that |source|'s loading state has
+ // changed.
+ virtual void OnLoadingStateChanged(content::WebContents* source) {}
+
+ // A callback to notify the delegate that the dialog closed.
+ // IMPORTANT: Implementations should delete |this| here (unless they've
+ // arranged for the delegate to be deleted in some other way, e.g. by
+ // registering it as a message handler in the WebUI object).
+ 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(content::WebContents* source,
+ bool* out_close_dialog) = 0;
+
+ // A callback to allow the delegate to dictate that the window should not
+ // have a title bar. This is useful when presenting branded interfaces.
+ virtual bool ShouldShowDialogTitle() const = 0;
+
+ // A callback to allow the delegate to inhibit context menu or show
+ // customized menu.
+ // Returns true iff you do NOT want the standard context menu to be
+ // shown (because you want to handle it yourself).
+ virtual bool HandleContextMenu(const content::ContextMenuParams& params);
+
+ // A callback to allow the delegate to open a new URL inside |source|.
+ // On return |out_new_contents| should contain the WebContents the URL
+ // is opened in. Return false to use the default handler.
+ virtual bool HandleOpenURLFromTab(content::WebContents* source,
+ const content::OpenURLParams& params,
+ content::WebContents** out_new_contents);
+
+ // A callback to create a new tab with |new_contents|. |source| is the
+ // WebContent where the operation originated. |disposition| controls how the
+ // new tab should be opened. |initial_pos| is the position of the window if a
+ // new window is created. |user_gesture| is true if the operation was started
+ // by a user gesture. Return false to use the default handler.
+ virtual bool HandleAddNewContents(content::WebContents* source,
+ content::WebContents* new_contents,
+ WindowOpenDisposition disposition,
+ const gfx::Rect& initial_pos,
+ bool user_gesture);
+
+ // Stores the dialog bounds.
+ virtual void StoreDialogSize(const gfx::Size& dialog_size) {}
+
+ protected:
+ virtual ~WebDialogDelegate() {}
+};
+
+// Displays file URL contents inside a modal web dialog.
+//
+// This application really should not use WebContents + WebUI. It should instead
+// just embed a RenderView in a dialog and be done with it.
+//
+// Before loading a URL corresponding to this WebUI, the caller should set its
+// delegate as a property on the WebContents. This WebUI will pick it up from
+// there and call it back. This is a bit of a hack to allow the dialog to pass
+// its delegate to the Web UI without having nasty accessors on the WebContents.
+// The correct design using RVH directly would avoid all of this.
+class VIEWS_EXPORT WebDialogUI : public content::WebUIController {
+ public:
+ struct WebDialogParams {
+ // The URL for the content that will be loaded in the dialog.
+ GURL url;
+ // Width of the dialog.
+ int width;
+ // Height of the dialog.
+ int height;
+ // The JSON input to pass to the dialog when showing it.
+ std::string json_input;
+ };
+
+ // When created, the property should already be set on the WebContents.
+ explicit WebDialogUI(content::WebUI* web_ui);
+ virtual ~WebDialogUI();
+
+ // Close the dialog, passing the specified arguments to the close handler.
+ void CloseDialog(const base::ListValue* args);
+
+ // Returns the PropertyBag accessor object used to write the delegate pointer
+ // into the WebContents (see class-level comment above).
+ static base::PropertyAccessor<WebDialogDelegate*>& GetPropertyAccessor();
+
+ private:
+ // WebUIController
+ virtual void RenderViewCreated(
+ content::RenderViewHost* render_view_host) OVERRIDE;
+
+ // JS message handler.
+ void OnDialogClosed(const base::ListValue* args);
+
+ DISALLOW_COPY_AND_ASSIGN(WebDialogUI);
+};
+
+} //namespace views
+#endif // UI_WEB_DIALOGS_WEB_DIALOG_UI_H_
« ui/views/views.gyp ('K') | « ui/views/views.gyp ('k') | ui/web_dialogs/web_dialog_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698