| OLD | NEW |
| (Empty) |
| 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 CONTENT_BROWSER_TAB_CONTENTS_INTERSTITIAL_PAGE_IMPL_H_ | |
| 6 #define CONTENT_BROWSER_TAB_CONTENTS_INTERSTITIAL_PAGE_IMPL_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "base/compiler_specific.h" | |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/process_util.h" | |
| 12 #include "content/public/browser/interstitial_page.h" | |
| 13 #include "content/public/browser/notification_observer.h" | |
| 14 #include "content/public/browser/notification_registrar.h" | |
| 15 #include "content/public/browser/render_view_host_delegate.h" | |
| 16 #include "content/public/common/renderer_preferences.h" | |
| 17 #include "googleurl/src/gurl.h" | |
| 18 | |
| 19 class WebContentsImpl; | |
| 20 | |
| 21 namespace content { | |
| 22 class NavigationEntry; | |
| 23 class RenderViewHostImpl; | |
| 24 class WebContentsView; | |
| 25 } | |
| 26 | |
| 27 enum ResourceRequestAction { | |
| 28 BLOCK, | |
| 29 RESUME, | |
| 30 CANCEL | |
| 31 }; | |
| 32 | |
| 33 class CONTENT_EXPORT InterstitialPageImpl | |
| 34 : public NON_EXPORTED_BASE(content::InterstitialPage), | |
| 35 public content::NotificationObserver, | |
| 36 public content::RenderViewHostDelegate { | |
| 37 public: | |
| 38 // The different state of actions the user can take in an interstitial. | |
| 39 enum ActionState { | |
| 40 NO_ACTION, // No action has been taken yet. | |
| 41 PROCEED_ACTION, // "Proceed" was selected. | |
| 42 DONT_PROCEED_ACTION // "Don't proceed" was selected. | |
| 43 }; | |
| 44 | |
| 45 InterstitialPageImpl(content::WebContents* tab, | |
| 46 bool new_navigation, | |
| 47 const GURL& url, | |
| 48 content::InterstitialPageDelegate* delegate); | |
| 49 virtual ~InterstitialPageImpl(); | |
| 50 | |
| 51 // InterstitialPage implementation: | |
| 52 virtual void Show() OVERRIDE; | |
| 53 virtual void Hide() OVERRIDE; | |
| 54 virtual void DontProceed() OVERRIDE; | |
| 55 virtual void Proceed() OVERRIDE; | |
| 56 virtual content::RenderViewHost* GetRenderViewHostForTesting() const OVERRIDE; | |
| 57 virtual content::InterstitialPageDelegate* GetDelegateForTesting() OVERRIDE; | |
| 58 virtual void DontCreateViewForTesting() OVERRIDE; | |
| 59 virtual void SetSize(const gfx::Size& size) OVERRIDE; | |
| 60 virtual void Focus() OVERRIDE; | |
| 61 | |
| 62 // Allows the user to navigate away by disabling the interstitial, canceling | |
| 63 // the pending request, and unblocking the hidden renderer. The interstitial | |
| 64 // will stay visible until the navigation completes. | |
| 65 void CancelForNavigation(); | |
| 66 | |
| 67 // Focus the first (last if reverse is true) element in the interstitial page. | |
| 68 // Called when tab traversing. | |
| 69 void FocusThroughTabTraversal(bool reverse); | |
| 70 | |
| 71 // See description above field. | |
| 72 void set_reload_on_dont_proceed(bool value) { | |
| 73 reload_on_dont_proceed_ = value; | |
| 74 } | |
| 75 bool reload_on_dont_proceed() const { return reload_on_dont_proceed_; } | |
| 76 | |
| 77 protected: | |
| 78 // content::NotificationObserver method: | |
| 79 virtual void Observe(int type, | |
| 80 const content::NotificationSource& source, | |
| 81 const content::NotificationDetails& details) OVERRIDE; | |
| 82 | |
| 83 // RenderViewHostDelegate implementation: | |
| 84 virtual View* GetViewDelegate() OVERRIDE; | |
| 85 virtual const GURL& GetURL() const OVERRIDE; | |
| 86 virtual void RenderViewGone(content::RenderViewHost* render_view_host, | |
| 87 base::TerminationStatus status, | |
| 88 int error_code) OVERRIDE; | |
| 89 virtual void DidNavigate( | |
| 90 content::RenderViewHost* render_view_host, | |
| 91 const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE; | |
| 92 virtual void UpdateTitle(content::RenderViewHost* render_view_host, | |
| 93 int32 page_id, | |
| 94 const string16& title, | |
| 95 base::i18n::TextDirection title_direction) OVERRIDE; | |
| 96 virtual content::RendererPreferences GetRendererPrefs( | |
| 97 content::BrowserContext* browser_context) const OVERRIDE; | |
| 98 virtual WebPreferences GetWebkitPrefs() OVERRIDE; | |
| 99 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, | |
| 100 bool* is_keyboard_shortcut) OVERRIDE; | |
| 101 virtual void HandleKeyboardEvent( | |
| 102 const NativeWebKeyboardEvent& event) OVERRIDE; | |
| 103 virtual content::ViewType GetRenderViewType() const OVERRIDE; | |
| 104 virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE; | |
| 105 | |
| 106 bool enabled() const { return enabled_; } | |
| 107 content::WebContents* tab() const; | |
| 108 const GURL& url() const { return url_; } | |
| 109 | |
| 110 // Creates the RenderViewHost containing the interstitial content. | |
| 111 // Overriden in unit tests. | |
| 112 virtual content::RenderViewHost* CreateRenderViewHost(); | |
| 113 | |
| 114 // Creates the WebContentsView that shows the interstitial RVH. | |
| 115 // Overriden in unit tests. | |
| 116 virtual content::WebContentsView* CreateWebContentsView(); | |
| 117 | |
| 118 // Notification magic. | |
| 119 content::NotificationRegistrar notification_registrar_; | |
| 120 | |
| 121 private: | |
| 122 class InterstitialPageRVHViewDelegate; | |
| 123 | |
| 124 // Disable the interstitial: | |
| 125 // - if it is not yet showing, then it won't be shown. | |
| 126 // - any command sent by the RenderViewHost will be ignored. | |
| 127 void Disable(); | |
| 128 | |
| 129 // Executes the passed action on the ResourceDispatcher (on the IO thread). | |
| 130 // Used to block/resume/cancel requests for the RenderViewHost hidden by this | |
| 131 // interstitial. | |
| 132 void TakeActionOnResourceDispatcher(ResourceRequestAction action); | |
| 133 | |
| 134 // The contents in which we are displayed. | |
| 135 WebContentsImpl* tab_; | |
| 136 | |
| 137 // The URL that is shown when the interstitial is showing. | |
| 138 GURL url_; | |
| 139 | |
| 140 // Whether this interstitial is shown as a result of a new navigation (in | |
| 141 // which case a transient navigation entry is created). | |
| 142 bool new_navigation_; | |
| 143 | |
| 144 // Whether we should discard the pending navigation entry when not proceeding. | |
| 145 // This is to deal with cases where |new_navigation_| is true but a new | |
| 146 // pending entry was created since this interstitial was shown and we should | |
| 147 // not discard it. | |
| 148 bool should_discard_pending_nav_entry_; | |
| 149 | |
| 150 // If true and the user chooses not to proceed the target NavigationController | |
| 151 // is reloaded. This is used when two NavigationControllers are merged | |
| 152 // (CopyStateFromAndPrune). | |
| 153 // The default is false. | |
| 154 bool reload_on_dont_proceed_; | |
| 155 | |
| 156 // Whether this interstitial is enabled. See Disable() for more info. | |
| 157 bool enabled_; | |
| 158 | |
| 159 // Whether the Proceed or DontProceed methods have been called yet. | |
| 160 ActionState action_taken_; | |
| 161 | |
| 162 // The RenderViewHost displaying the interstitial contents. | |
| 163 content::RenderViewHostImpl* render_view_host_; | |
| 164 | |
| 165 // The IDs for the Render[View|Process]Host hidden by this interstitial. | |
| 166 int original_child_id_; | |
| 167 int original_rvh_id_; | |
| 168 | |
| 169 // Whether or not we should change the title of the tab when hidden (to revert | |
| 170 // it to its original value). | |
| 171 bool should_revert_tab_title_; | |
| 172 | |
| 173 // Whether or not the tab was loading resources when the interstitial was | |
| 174 // shown. We restore this state if the user proceeds from the interstitial. | |
| 175 bool tab_was_loading_; | |
| 176 | |
| 177 // Whether the ResourceDispatcherHost has been notified to cancel/resume the | |
| 178 // resource requests blocked for the RenderViewHost. | |
| 179 bool resource_dispatcher_host_notified_; | |
| 180 | |
| 181 // The original title of the tab that should be reverted to when the | |
| 182 // interstitial is hidden. | |
| 183 string16 original_tab_title_; | |
| 184 | |
| 185 // Our RenderViewHostViewDelegate, necessary for accelerators to work. | |
| 186 scoped_ptr<InterstitialPageRVHViewDelegate> rvh_view_delegate_; | |
| 187 | |
| 188 // Settings passed to the renderer. | |
| 189 mutable content::RendererPreferences renderer_preferences_; | |
| 190 | |
| 191 bool create_view_; | |
| 192 | |
| 193 scoped_ptr<content::InterstitialPageDelegate> delegate_; | |
| 194 | |
| 195 DISALLOW_COPY_AND_ASSIGN(InterstitialPageImpl); | |
| 196 }; | |
| 197 | |
| 198 #endif // CONTENT_BROWSER_TAB_CONTENTS_INTERSTITIAL_PAGE_IMPL_H_ | |
| OLD | NEW |