1 // Copyright (c) 2011 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_WEB_PAGE_VIEW_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_WEB_PAGE_VIEW_H_ 7 #pragma once 8 9 #include <string> 10 11 #include "base/timer.h" 12 #include "chrome/browser/ui/views/dom_view.h" 13 #include "content/browser/tab_contents/tab_contents.h" 14 #include "views/view.h" 15 16 class Profile; 17 class SiteContents; 18 class TabContentsDelegate; 19 20 namespace views { 21 class Label; 22 class Throbber; 23 } // namespace views 24 25 namespace chromeos { 26 27 // Delegate interface for listening to common events during page load. 28 class WebPageDelegate { 29 public: 30 virtual ~WebPageDelegate() {} 31 32 // Notify about document load event. 33 virtual void OnPageLoaded() = 0; 34 35 // Notify about navigation errors. 36 virtual void OnPageLoadFailed(const std::string& url) = 0; 37 }; 38 39 // Base class for tab contents for pages rendered on wizard screens. 40 class WizardWebPageViewTabContents : public TabContents { 41 public: 42 WizardWebPageViewTabContents(Profile* profile, 43 SiteInstance* site_instance, 44 WebPageDelegate* page_delegate); 45 46 virtual void DidFailProvisionalLoadWithError( 47 RenderViewHost* render_view_host, 48 bool is_main_frame, 49 int error_code, 50 const GURL& url, 51 bool showing_repost_interstitial); 52 53 virtual void DidDisplayInsecureContent(); 54 virtual void DidRunInsecureContent(const std::string& security_origin); 55 virtual void DocumentLoadedInFrame(long long frame_id); 56 virtual void DidFinishLoad(long long frame_id); 57 virtual void OnContentBlocked(ContentSettingsType type); 58 59 private: 60 WebPageDelegate* page_delegate_; 61 62 DISALLOW_COPY_AND_ASSIGN(WizardWebPageViewTabContents); 63 }; 64 65 // WebPageDomView is the view that is rendering the page. 66 class WebPageDomView : public DOMView { 67 public: 68 WebPageDomView() : page_delegate_(NULL) {} 69 70 // Set delegate that will be notified about tab contents changes. 71 void SetTabContentsDelegate(TabContentsDelegate* delegate); 72 73 // Set delegate that will be notified about page events. 74 void set_web_page_delegate(WebPageDelegate* delegate) { 75 page_delegate_ = delegate; 76 } 77 78 protected: 79 // Overriden from DOMView: 80 virtual TabContents* CreateTabContents(Profile* profile, 81 SiteInstance* instance) = 0; 82 WebPageDelegate* page_delegate_; 83 84 private: 85 DISALLOW_COPY_AND_ASSIGN(WebPageDomView); 86 }; 87 88 // WebPageView represents the view that holds WebPageDomView with 89 // page rendered in it. While page is loaded spinner overlay is shown. 90 class WebPageView : public views::View { 91 public: 92 WebPageView() : throbber_(NULL), connecting_label_(NULL) {} 93 94 // Initialize view layout. 95 void Init(); 96 97 // Initialize the DOM view, creating the contents. This should be 98 // called once the view has been added to a container. 99 void InitDOM(Profile* profile, SiteInstance* site_instance); 100 101 // Loads the given URL into the page. 102 // You must have previously called Init() and SetTabContentsDelegate. 103 void LoadURL(const GURL& url); 104 105 // Sets delegate for tab contents changes. 106 void SetTabContentsDelegate(TabContentsDelegate* delegate); 107 108 // Set delegate that will be notified about page events. 109 void SetWebPageDelegate(WebPageDelegate* delegate); 110 111 // Stops throbber and shows page content (starts renderer_timer_ for that). 112 void ShowPageContent(); 113 114 protected: 115 virtual WebPageDomView* dom_view() = 0; 116 117 private: 118 // Overriden from views::View: 119 virtual void Layout(); 120 121 // Called by stop_timer_. Shows rendered page. 122 void ShowRenderedPage(); 123 124 // Called by start_timer_. Shows throbber and waiting label. 125 void ShowWaitingControls(); 126 127 // Throbber shown during page load. 128 views::Throbber* throbber_; 129 130 // "Connecting..." label shown while waiting for the page to load/render. 131 views::Label* connecting_label_; 132 133 // Timer used when waiting for network response. 134 base::OneShotTimer<WebPageView> start_timer_; 135 136 // Timer used before toggling loaded page visibility. 137 base::OneShotTimer<WebPageView> stop_timer_; 138 139 DISALLOW_COPY_AND_ASSIGN(WebPageView); 140 }; 141 142 } // namespace chromeos 143 144 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WEB_PAGE_VIEW_H_ 145