Home | History | Annotate | Download | only in web_dialogs
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef UI_WEB_DIALOGS_WEB_DIALOG_UI_H_
      6 #define UI_WEB_DIALOGS_WEB_DIALOG_UI_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "base/compiler_specific.h"
     12 #include "base/strings/string16.h"
     13 #include "content/public/browser/web_contents_delegate.h"
     14 #include "content/public/browser/web_ui_controller.h"
     15 #include "ui/base/ui_base_types.h"
     16 #include "ui/web_dialogs/web_dialogs_export.h"
     17 #include "url/gurl.h"
     18 
     19 namespace content {
     20 class WebContents;
     21 class WebUIMessageHandler;
     22 struct ContextMenuParams;
     23 }
     24 
     25 namespace gfx {
     26 class Size;
     27 }
     28 
     29 namespace ui {
     30 
     31 class WebDialogDelegate;
     32 
     33 // Displays file URL contents inside a modal web dialog.
     34 //
     35 // This application really should not use WebContents + WebUI. It should instead
     36 // just embed a RenderView in a dialog and be done with it.
     37 //
     38 // Before loading a URL corresponding to this WebUI, the caller should set its
     39 // delegate as user data on the WebContents by calling SetDelegate(). This WebUI
     40 // will pick it up from there and call it back. This is a bit of a hack to allow
     41 // the dialog to pass its delegate to the Web UI without having nasty accessors
     42 // on the WebContents. The correct design using RVH directly would avoid all of
     43 // this.
     44 class WEB_DIALOGS_EXPORT WebDialogUI : public content::WebUIController {
     45  public:
     46   struct WebDialogParams {
     47     // The URL for the content that will be loaded in the dialog.
     48     GURL url;
     49     // Width of the dialog.
     50     int width;
     51     // Height of the dialog.
     52     int height;
     53     // The JSON input to pass to the dialog when showing it.
     54     std::string json_input;
     55   };
     56 
     57   // When created, the delegate should already be set as user data on the
     58   // WebContents.
     59   explicit WebDialogUI(content::WebUI* web_ui);
     60   virtual ~WebDialogUI();
     61 
     62   // Close the dialog, passing the specified arguments to the close handler.
     63   void CloseDialog(const base::ListValue* args);
     64 
     65   // Sets the delegate on the WebContents.
     66   static void SetDelegate(content::WebContents* web_contents,
     67                           WebDialogDelegate* delegate);
     68 
     69  private:
     70   // WebUIController
     71   virtual void RenderViewCreated(
     72       content::RenderViewHost* render_view_host) OVERRIDE;
     73 
     74   // Gets the delegate for the WebContent set with SetDelegate.
     75   static WebDialogDelegate* GetDelegate(content::WebContents* web_contents);
     76 
     77   // JS message handler.
     78   void OnDialogClosed(const base::ListValue* args);
     79 
     80   DISALLOW_COPY_AND_ASSIGN(WebDialogUI);
     81 };
     82 
     83 // Displays external URL contents inside a modal web dialog.
     84 //
     85 // Intended to be the place to collect the settings and lockdowns
     86 // necessary for running external UI components securely (e.g., the
     87 // cloud print dialog).
     88 class WEB_DIALOGS_EXPORT ExternalWebDialogUI : public WebDialogUI {
     89  public:
     90   explicit ExternalWebDialogUI(content::WebUI* web_ui);
     91   virtual ~ExternalWebDialogUI();
     92 };
     93 
     94 }  // namespace ui
     95 
     96 #endif  // UI_WEB_DIALOGS_WEB_DIALOG_UI_H_
     97