Home | History | Annotate | Download | only in ui
      1 // Copyright 2014 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 CHROME_BROWSER_CHROMEOS_LOGIN_UI_SIMPLE_WEB_VIEW_DIALOG_H_
      6 #define CHROME_BROWSER_CHROMEOS_LOGIN_UI_SIMPLE_WEB_VIEW_DIALOG_H_
      7 
      8 #include <string>
      9 #include "base/memory/scoped_ptr.h"
     10 #include "chrome/browser/command_updater_delegate.h"
     11 #include "chrome/browser/ui/toolbar/toolbar_model_delegate.h"
     12 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
     13 #include "content/public/browser/page_navigator.h"
     14 #include "content/public/browser/web_contents_delegate.h"
     15 #include "ui/views/controls/button/image_button.h"
     16 #include "ui/views/widget/widget_delegate.h"
     17 #include "url/gurl.h"
     18 
     19 class CommandUpdater;
     20 class Profile;
     21 class ReloadButton;
     22 class ToolbarModel;
     23 
     24 namespace views {
     25 class WebView;
     26 class Widget;
     27 }
     28 
     29 namespace chromeos {
     30 
     31 class StubBubbleModelDelegate;
     32 
     33 // View class which shows the light version of the toolbar and the web contents.
     34 // Light version of the toolbar includes back, forward buttons and location
     35 // bar. Location bar is shown in read only mode, because this view is designed
     36 // to be used for sign in to captive portal on login screen (when Browser
     37 // isn't running).
     38 class SimpleWebViewDialog : public views::ButtonListener,
     39                             public views::WidgetDelegateView,
     40                             public LocationBarView::Delegate,
     41                             public ToolbarModelDelegate,
     42                             public CommandUpdaterDelegate,
     43                             public content::PageNavigator,
     44                             public content::WebContentsDelegate {
     45  public:
     46   explicit SimpleWebViewDialog(Profile* profile);
     47   virtual ~SimpleWebViewDialog();
     48 
     49   // Starts loading.
     50   void StartLoad(const GURL& gurl);
     51 
     52   // Inits view. Should be attached to a Widget before call.
     53   void Init();
     54 
     55   // Overridden from views::View:
     56   virtual void Layout() OVERRIDE;
     57 
     58   // Overridden from views::WidgetDelegate:
     59   virtual views::View* GetContentsView() OVERRIDE;
     60   virtual views::View* GetInitiallyFocusedView() OVERRIDE;
     61 
     62   // Implements views::ButtonListener:
     63   virtual void ButtonPressed(views::Button* sender,
     64                              const ui::Event& event) OVERRIDE;
     65 
     66   // Implements content::PageNavigator:
     67   virtual content::WebContents* OpenURL(
     68       const content::OpenURLParams& params) OVERRIDE;
     69 
     70   // Implements content::WebContentsDelegate:
     71   virtual void NavigationStateChanged(const content::WebContents* source,
     72                                       unsigned changed_flags) OVERRIDE;
     73   virtual void LoadingStateChanged(content::WebContents* source,
     74                                    bool to_different_document) OVERRIDE;
     75 
     76   // Implements LocationBarView::Delegate:
     77   virtual content::WebContents* GetWebContents() OVERRIDE;
     78   virtual ToolbarModel* GetToolbarModel() OVERRIDE;
     79   virtual const ToolbarModel* GetToolbarModel() const OVERRIDE;
     80   virtual InstantController* GetInstant() OVERRIDE;
     81   virtual views::Widget* CreateViewsBubble(
     82       views::BubbleDelegateView* bubble_delegate) OVERRIDE;
     83   virtual PageActionImageView* CreatePageActionImageView(
     84       LocationBarView* owner,
     85       ExtensionAction* action) OVERRIDE;
     86   virtual ContentSettingBubbleModelDelegate*
     87   GetContentSettingBubbleModelDelegate() OVERRIDE;
     88   virtual void ShowWebsiteSettings(content::WebContents* web_contents,
     89                                    const GURL& url,
     90                                    const content::SSLStatus& ssl) OVERRIDE;
     91 
     92   // Implements ToolbarModelDelegate:
     93   virtual content::WebContents* GetActiveWebContents() const OVERRIDE;
     94   virtual bool InTabbedBrowser() const OVERRIDE;
     95 
     96   // Implements CommandUpdaterDelegate:
     97   virtual void ExecuteCommandWithDisposition(
     98       int id,
     99       WindowOpenDisposition) OVERRIDE;
    100 
    101  private:
    102   friend class SimpleWebViewDialogTest;
    103 
    104   void LoadImages();
    105   void UpdateButtons();
    106   void UpdateReload(bool is_loading, bool force);
    107 
    108   Profile* profile_;
    109   scoped_ptr<ToolbarModel> toolbar_model_;
    110   scoped_ptr<CommandUpdater> command_updater_;
    111 
    112   // Controls
    113   views::ImageButton* back_;
    114   views::ImageButton* forward_;
    115   ReloadButton* reload_;
    116   LocationBarView* location_bar_;
    117   views::WebView* web_view_;
    118 
    119   // Contains |web_view_| while it isn't owned by the view.
    120   scoped_ptr<views::WebView> web_view_container_;
    121 
    122   scoped_ptr<StubBubbleModelDelegate> bubble_model_delegate_;
    123 
    124   DISALLOW_COPY_AND_ASSIGN(SimpleWebViewDialog);
    125 };
    126 
    127 }  // namespace chromeos
    128 
    129 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_UI_SIMPLE_WEB_VIEW_DIALOG_H_
    130