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

Side by Side Diff: content/browser/tab_contents/interstitial_page.h

Issue 9323071: Use InterstitialPage through a delegate interface instead of deriving from it. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix cros Created 8 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_TAB_CONTENTS_INTERSTITIAL_PAGE_H_ 5 #ifndef CONTENT_BROWSER_TAB_CONTENTS_INTERSTITIAL_PAGE_H_
6 #define CONTENT_BROWSER_TAB_CONTENTS_INTERSTITIAL_PAGE_H_ 6 #define CONTENT_BROWSER_TAB_CONTENTS_INTERSTITIAL_PAGE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
11 11
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/process_util.h" 13 #include "base/process_util.h"
14 #include "content/common/content_export.h" 14 #include "content/common/content_export.h"
15 #include "content/public/browser/notification_observer.h" 15 #include "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_registrar.h" 16 #include "content/public/browser/notification_registrar.h"
17 #include "content/public/browser/render_view_host_delegate.h" 17 #include "content/public/browser/render_view_host_delegate.h"
18 #include "content/public/common/renderer_preferences.h" 18 #include "content/public/common/renderer_preferences.h"
19 #include "googleurl/src/gurl.h" 19 #include "googleurl/src/gurl.h"
20 #include "ui/gfx/size.h" 20 #include "ui/gfx/size.h"
21 21
22 class TabContents; 22 class TabContents;
23 23
24 namespace content { 24 namespace content {
25 class InterstitialPageDelegate;
25 class NavigationEntry; 26 class NavigationEntry;
26 class WebContents; 27 class WebContents;
27 class WebContentsView; 28 class WebContentsView;
28 } 29 }
29 30
30 // This class is a base class for interstitial pages, pages that show some 31 // This class is a base class for interstitial pages, pages that show some
31 // informative message asking for user validation before reaching the target 32 // informative message asking for user validation before reaching the target
32 // page. (Navigating to a page served over bad HTTPS or a page containing 33 // page. (Navigating to a page served over bad HTTPS or a page containing
33 // malware are typical cases where an interstitial is required.) 34 // malware are typical cases where an interstitial is required.)
34 // 35 //
(...skipping 19 matching lines...) Expand all
54 PROCEED_ACTION, // "Proceed" was selected. 55 PROCEED_ACTION, // "Proceed" was selected.
55 DONT_PROCEED_ACTION // "Don't proceed" was selected. 56 DONT_PROCEED_ACTION // "Don't proceed" was selected.
56 }; 57 };
57 58
58 // Creates an interstitial page to show in |tab|. |new_navigation| should be 59 // Creates an interstitial page to show in |tab|. |new_navigation| should be
59 // set to true when the interstitial is caused by loading a new page, in which 60 // set to true when the interstitial is caused by loading a new page, in which
60 // case a temporary navigation entry is created with the URL |url| and 61 // case a temporary navigation entry is created with the URL |url| and
61 // added to the navigation controller (so the interstitial page appears as a 62 // added to the navigation controller (so the interstitial page appears as a
62 // new navigation entry). |new_navigation| should be false when the 63 // new navigation entry). |new_navigation| should be false when the
63 // interstitial was triggered by a loading a sub-resource in a page. 64 // interstitial was triggered by a loading a sub-resource in a page.
65 // Takes ownership of |delegate|.
66 static InterstitialPage* Create(content::WebContents* tab,
67 bool new_navigation,
68 const GURL& url,
69 content::InterstitialPageDelegate* delegate);
70
64 InterstitialPage(content::WebContents* tab, 71 InterstitialPage(content::WebContents* tab,
65 bool new_navigation, 72 bool new_navigation,
66 const GURL& url); 73 const GURL& url,
74 content::InterstitialPageDelegate* delegate);
67 virtual ~InterstitialPage(); 75 virtual ~InterstitialPage();
68 76
69 // Shows the interstitial page in the tab. 77 // Shows the interstitial page in the tab.
70 virtual void Show(); 78 void Show();
71 79
72 // Hides the interstitial page. Warning: this deletes the InterstitialPage. 80 // Hides the interstitial page.
73 void Hide(); 81 void Hide();
74 82
75 // Retrieves the InterstitialPage if any associated with the specified 83 // Retrieves the InterstitialPage if any associated with the specified
76 // |web_contents| (used by ui tests). 84 // |web_contents| (used by ui tests).
77 static InterstitialPage* GetInterstitialPage( 85 static InterstitialPage* GetInterstitialPage(
78 content::WebContents* web_contents); 86 content::WebContents* web_contents);
79 87
80 // Sub-classes should return the HTML that should be displayed in the page.
81 virtual std::string GetHTMLContents();
82
83 // Invoked when the page sent a command through DOMAutomation.
84 virtual void CommandReceived(const std::string& command) {}
85
86 // Reverts to the page showing before the interstitial. 88 // Reverts to the page showing before the interstitial.
87 // Sub-classes should call this method when the user has chosen NOT to proceed 89 // Sub-classes should call this method when the user has chosen NOT to proceed
88 // to the target URL. 90 // to the target URL.
89 // Warning: if |new_navigation| was set to true in the constructor, 'this' 91 // Warning: if |new_navigation| was set to true in the constructor, 'this'
90 // will be deleted when this method returns. 92 // will be deleted when this method returns.
91 virtual void DontProceed(); 93 virtual void DontProceed();
92 94
93 // Sub-classes should call this method when the user has chosen to proceed to 95 // Sub-classes should call this method when the user has chosen to proceed to
94 // the target URL. 96 // the target URL.
95 // Warning: 'this' has been deleted when this method returns. 97 // Warning: 'this' has been deleted when this method returns.
96 virtual void Proceed(); 98 virtual void Proceed();
97 99
98 // Allows the user to navigate away by disabling the interstitial, canceling 100 // Allows the user to navigate away by disabling the interstitial, canceling
99 // the pending request, and unblocking the hidden renderer. The interstitial 101 // the pending request, and unblocking the hidden renderer. The interstitial
100 // will stay visible until the navigation completes. 102 // will stay visible until the navigation completes.
101 void CancelForNavigation(); 103 void CancelForNavigation();
102 104
103 // Sizes the RenderViewHost showing the actual interstitial page contents. 105 // Sizes the RenderViewHost showing the actual interstitial page contents.
104 void SetSize(const gfx::Size& size); 106 void SetSize(const gfx::Size& size);
105 107
106 ActionState action_taken() const { return action_taken_; } 108 ActionState action_taken() const { return action_taken_; }
107 109
108 // Sets the focus to the interstitial. 110 // Sets the focus to the interstitial.
109 void Focus(); 111 void Focus();
110 112
111 // Focus the first (last if reverse is true) element in the interstitial page. 113 // Focus the first (last if reverse is true) element in the interstitial page.
112 // Called when tab traversing. 114 // Called when tab traversing.
113 void FocusThroughTabTraversal(bool reverse); 115 void FocusThroughTabTraversal(bool reverse);
114 116
115 virtual content::ViewType GetRenderViewType() const OVERRIDE;
116
117 virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE;
118
119 // See description above field. 117 // See description above field.
120 void set_reload_on_dont_proceed(bool value) { 118 void set_reload_on_dont_proceed(bool value) {
121 reload_on_dont_proceed_ = value; 119 reload_on_dont_proceed_ = value;
122 } 120 }
123 bool reload_on_dont_proceed() const { return reload_on_dont_proceed_; } 121 bool reload_on_dont_proceed() const { return reload_on_dont_proceed_; }
124 122
123 RenderViewHost* render_view_host() const { return render_view_host_; }
124
125 content::InterstitialPageDelegate* GetDelegateForTesting();
126 void DontCreateViewForTesting();
127
125 protected: 128 protected:
126 // content::NotificationObserver method: 129 // content::NotificationObserver method:
127 virtual void Observe(int type, 130 virtual void Observe(int type,
128 const content::NotificationSource& source, 131 const content::NotificationSource& source,
129 const content::NotificationDetails& details) OVERRIDE; 132 const content::NotificationDetails& details) OVERRIDE;
130 133
131 // RenderViewHostDelegate implementation: 134 // RenderViewHostDelegate implementation:
132 virtual View* GetViewDelegate() OVERRIDE; 135 virtual View* GetViewDelegate() OVERRIDE;
133 virtual const GURL& GetURL() const OVERRIDE; 136 virtual const GURL& GetURL() const OVERRIDE;
134 virtual void RenderViewGone(RenderViewHost* render_view_host, 137 virtual void RenderViewGone(RenderViewHost* render_view_host,
135 base::TerminationStatus status, 138 base::TerminationStatus status,
136 int error_code) OVERRIDE; 139 int error_code) OVERRIDE;
137 virtual void DidNavigate( 140 virtual void DidNavigate(
138 RenderViewHost* render_view_host, 141 RenderViewHost* render_view_host,
139 const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE; 142 const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE;
140 virtual void UpdateTitle(RenderViewHost* render_view_host, 143 virtual void UpdateTitle(RenderViewHost* render_view_host,
141 int32 page_id, 144 int32 page_id,
142 const string16& title, 145 const string16& title,
143 base::i18n::TextDirection title_direction) OVERRIDE; 146 base::i18n::TextDirection title_direction) OVERRIDE;
144 virtual content::RendererPreferences GetRendererPrefs( 147 virtual content::RendererPreferences GetRendererPrefs(
145 content::BrowserContext* browser_context) const OVERRIDE; 148 content::BrowserContext* browser_context) const OVERRIDE;
146 virtual WebPreferences GetWebkitPrefs() OVERRIDE; 149 virtual WebPreferences GetWebkitPrefs() OVERRIDE;
147 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, 150 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
148 bool* is_keyboard_shortcut) OVERRIDE; 151 bool* is_keyboard_shortcut) OVERRIDE;
149 virtual void HandleKeyboardEvent( 152 virtual void HandleKeyboardEvent(
150 const NativeWebKeyboardEvent& event) OVERRIDE; 153 const NativeWebKeyboardEvent& event) OVERRIDE;
151 154 virtual content::ViewType GetRenderViewType() const OVERRIDE;
152 // Invoked with the NavigationEntry that is going to be added to the 155 virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE;
153 // navigation controller.
154 // Gives an opportunity to sub-classes to set states on the |entry|.
155 // Note that this is only called if the InterstitialPage was constructed with
156 // |create_navigation_entry| set to true.
157 virtual void UpdateEntry(content::NavigationEntry* entry) {}
158 156
159 bool enabled() const { return enabled_; } 157 bool enabled() const { return enabled_; }
160 content::WebContents* tab() const; 158 content::WebContents* tab() const;
161 const GURL& url() const { return url_; } 159 const GURL& url() const { return url_; }
162 RenderViewHost* render_view_host() const { return render_view_host_; }
163 void set_renderer_preferences(const content::RendererPreferences& prefs) {
164 renderer_preferences_ = prefs;
165 }
166 160
167 // Creates the RenderViewHost containing the interstitial content. 161 // Creates the RenderViewHost containing the interstitial content.
168 // Overriden in unit tests. 162 // Overriden in unit tests.
169 virtual RenderViewHost* CreateRenderViewHost(); 163 virtual RenderViewHost* CreateRenderViewHost();
170 164
171 // Creates the WebContentsView that shows the interstitial RVH. 165 // Creates the WebContentsView that shows the interstitial RVH.
172 // Overriden in unit tests. 166 // Overriden in unit tests.
173 virtual content::WebContentsView* CreateWebContentsView(); 167 virtual content::WebContentsView* CreateWebContentsView();
174 168
175 // Notification magic. 169 // Notification magic.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 243
250 // Our RenderViewHostViewDelegate, necessary for accelerators to work. 244 // Our RenderViewHostViewDelegate, necessary for accelerators to work.
251 scoped_ptr<InterstitialPageRVHViewDelegate> rvh_view_delegate_; 245 scoped_ptr<InterstitialPageRVHViewDelegate> rvh_view_delegate_;
252 246
253 // We keep a map of the various blocking pages shown as the UI tests need to 247 // We keep a map of the various blocking pages shown as the UI tests need to
254 // be able to retrieve them. 248 // be able to retrieve them.
255 typedef std::map<TabContents*, InterstitialPage*> InterstitialPageMap; 249 typedef std::map<TabContents*, InterstitialPage*> InterstitialPageMap;
256 static InterstitialPageMap* tab_to_interstitial_page_; 250 static InterstitialPageMap* tab_to_interstitial_page_;
257 251
258 // Settings passed to the renderer. 252 // Settings passed to the renderer.
259 content::RendererPreferences renderer_preferences_; 253 mutable content::RendererPreferences renderer_preferences_;
254
255 bool create_view_;
256
257 scoped_ptr<content::InterstitialPageDelegate> delegate_;
260 258
261 DISALLOW_COPY_AND_ASSIGN(InterstitialPage); 259 DISALLOW_COPY_AND_ASSIGN(InterstitialPage);
262 }; 260 };
263 261
264 #endif // CONTENT_BROWSER_TAB_CONTENTS_INTERSTITIAL_PAGE_H_ 262 #endif // CONTENT_BROWSER_TAB_CONTENTS_INTERSTITIAL_PAGE_H_
OLDNEW
« no previous file with comments | « chrome/renderer/content_settings_observer_browsertest.cc ('k') | content/browser/tab_contents/interstitial_page.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698