OLD | NEW |
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 #include "content/browser/tab_contents/interstitial_page.h" | 5 #include "content/browser/tab_contents/interstitial_page.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "content/browser/renderer_host/render_process_host_impl.h" | 15 #include "content/browser/renderer_host/render_process_host_impl.h" |
16 #include "content/browser/renderer_host/render_view_host.h" | 16 #include "content/browser/renderer_host/render_view_host.h" |
17 #include "content/browser/renderer_host/render_widget_host_view.h" | 17 #include "content/browser/renderer_host/render_widget_host_view.h" |
18 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 18 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
19 #include "content/browser/site_instance_impl.h" | 19 #include "content/browser/site_instance_impl.h" |
20 #include "content/browser/tab_contents/navigation_controller_impl.h" | 20 #include "content/browser/tab_contents/navigation_controller_impl.h" |
21 #include "content/browser/tab_contents/navigation_entry_impl.h" | 21 #include "content/browser/tab_contents/navigation_entry_impl.h" |
22 #include "content/browser/tab_contents/tab_contents.h" | 22 #include "content/browser/tab_contents/tab_contents.h" |
23 #include "content/common/dom_storage_common.h" | 23 #include "content/common/dom_storage_common.h" |
24 #include "content/common/view_messages.h" | 24 #include "content/common/view_messages.h" |
25 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
26 #include "content/public/browser/dom_operation_notification_details.h" | 26 #include "content/public/browser/dom_operation_notification_details.h" |
| 27 #include "content/public/browser/interstitial_page_delegate.h" |
27 #include "content/public/browser/invalidate_type.h" | 28 #include "content/public/browser/invalidate_type.h" |
28 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
29 #include "content/public/browser/notification_source.h" | 30 #include "content/public/browser/notification_source.h" |
30 #include "content/public/browser/web_contents_view.h" | 31 #include "content/public/browser/web_contents_view.h" |
31 #include "content/public/common/bindings_policy.h" | 32 #include "content/public/common/bindings_policy.h" |
32 #include "content/public/common/page_transition_types.h" | 33 #include "content/public/common/page_transition_types.h" |
33 #include "content/public/common/view_type.h" | 34 #include "content/public/common/view_type.h" |
34 #include "net/base/escape.h" | 35 #include "net/base/escape.h" |
35 #include "net/url_request/url_request_context_getter.h" | 36 #include "net/url_request/url_request_context_getter.h" |
36 | 37 |
37 using content::BrowserThread; | 38 using content::BrowserThread; |
38 using content::DomOperationNotificationDetails; | 39 using content::DomOperationNotificationDetails; |
| 40 using content::InterstitialPageDelegate; |
39 using content::NavigationController; | 41 using content::NavigationController; |
40 using content::NavigationEntry; | 42 using content::NavigationEntry; |
41 using content::NavigationEntryImpl; | 43 using content::NavigationEntryImpl; |
42 using content::RenderViewHostDelegate; | 44 using content::RenderViewHostDelegate; |
43 using content::SiteInstance; | 45 using content::SiteInstance; |
44 using content::WebContents; | 46 using content::WebContents; |
45 using content::WebContentsView; | 47 using content::WebContentsView; |
46 using WebKit::WebDragOperation; | 48 using WebKit::WebDragOperation; |
47 using WebKit::WebDragOperationsMask; | 49 using WebKit::WebDragOperationsMask; |
48 | 50 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 const gfx::Rect& selection_rect, | 112 const gfx::Rect& selection_rect, |
111 int active_match_ordinal, | 113 int active_match_ordinal, |
112 bool final_update); | 114 bool final_update); |
113 | 115 |
114 private: | 116 private: |
115 InterstitialPage* interstitial_page_; | 117 InterstitialPage* interstitial_page_; |
116 | 118 |
117 DISALLOW_COPY_AND_ASSIGN(InterstitialPageRVHViewDelegate); | 119 DISALLOW_COPY_AND_ASSIGN(InterstitialPageRVHViewDelegate); |
118 }; | 120 }; |
119 | 121 |
| 122 InterstitialPage* InterstitialPage::Create(WebContents* tab, |
| 123 bool new_navigation, |
| 124 const GURL& url, |
| 125 InterstitialPageDelegate* delegate) { |
| 126 return new InterstitialPage(tab, new_navigation, url, delegate); |
| 127 } |
| 128 |
120 // static | 129 // static |
121 InterstitialPage::InterstitialPageMap* | 130 InterstitialPage::InterstitialPageMap* |
122 InterstitialPage::tab_to_interstitial_page_ = NULL; | 131 InterstitialPage::tab_to_interstitial_page_ = NULL; |
123 | 132 |
124 InterstitialPage::InterstitialPage(WebContents* tab, | 133 InterstitialPage::InterstitialPage(WebContents* tab, |
125 bool new_navigation, | 134 bool new_navigation, |
126 const GURL& url) | 135 const GURL& url, |
| 136 InterstitialPageDelegate* delegate) |
127 : tab_(static_cast<TabContents*>(tab)), | 137 : tab_(static_cast<TabContents*>(tab)), |
128 url_(url), | 138 url_(url), |
129 new_navigation_(new_navigation), | 139 new_navigation_(new_navigation), |
130 should_discard_pending_nav_entry_(new_navigation), | 140 should_discard_pending_nav_entry_(new_navigation), |
131 reload_on_dont_proceed_(false), | 141 reload_on_dont_proceed_(false), |
132 enabled_(true), | 142 enabled_(true), |
133 action_taken_(NO_ACTION), | 143 action_taken_(NO_ACTION), |
134 render_view_host_(NULL), | 144 render_view_host_(NULL), |
135 original_child_id_(tab->GetRenderProcessHost()->GetID()), | 145 original_child_id_(tab->GetRenderProcessHost()->GetID()), |
136 original_rvh_id_(tab->GetRenderViewHost()->routing_id()), | 146 original_rvh_id_(tab->GetRenderViewHost()->routing_id()), |
137 should_revert_tab_title_(false), | 147 should_revert_tab_title_(false), |
138 tab_was_loading_(false), | 148 tab_was_loading_(false), |
139 resource_dispatcher_host_notified_(false), | 149 resource_dispatcher_host_notified_(false), |
140 ALLOW_THIS_IN_INITIALIZER_LIST(rvh_view_delegate_( | 150 ALLOW_THIS_IN_INITIALIZER_LIST(rvh_view_delegate_( |
141 new InterstitialPageRVHViewDelegate(this))) { | 151 new InterstitialPageRVHViewDelegate(this))), |
| 152 delegate_(delegate) { |
142 InitInterstitialPageMap(); | 153 InitInterstitialPageMap(); |
143 // It would be inconsistent to create an interstitial with no new navigation | 154 // It would be inconsistent to create an interstitial with no new navigation |
144 // (which is the case when the interstitial was triggered by a sub-resource on | 155 // (which is the case when the interstitial was triggered by a sub-resource on |
145 // a page) when we have a pending entry (in the process of loading a new top | 156 // a page) when we have a pending entry (in the process of loading a new top |
146 // frame). | 157 // frame). |
147 DCHECK(new_navigation || !tab->GetController().GetPendingEntry()); | 158 DCHECK(new_navigation || !tab->GetController().GetPendingEntry()); |
148 } | 159 } |
149 | 160 |
150 InterstitialPage::~InterstitialPage() { | 161 InterstitialPage::~InterstitialPage() { |
151 InterstitialPageMap::iterator iter = tab_to_interstitial_page_->find(tab_); | 162 InterstitialPageMap::iterator iter = tab_to_interstitial_page_->find(tab_); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 iter = tab_to_interstitial_page_->find(tab_); | 203 iter = tab_to_interstitial_page_->find(tab_); |
193 DCHECK(iter == tab_to_interstitial_page_->end()); | 204 DCHECK(iter == tab_to_interstitial_page_->end()); |
194 (*tab_to_interstitial_page_)[tab_] = this; | 205 (*tab_to_interstitial_page_)[tab_] = this; |
195 | 206 |
196 if (new_navigation_) { | 207 if (new_navigation_) { |
197 NavigationEntryImpl* entry = new NavigationEntryImpl; | 208 NavigationEntryImpl* entry = new NavigationEntryImpl; |
198 entry->SetURL(url_); | 209 entry->SetURL(url_); |
199 entry->SetVirtualURL(url_); | 210 entry->SetVirtualURL(url_); |
200 entry->set_page_type(content::PAGE_TYPE_INTERSTITIAL); | 211 entry->set_page_type(content::PAGE_TYPE_INTERSTITIAL); |
201 | 212 |
202 // Give sub-classes a chance to set some states on the navigation entry. | 213 // Give delegates a chance to set some states on the navigation entry. |
203 UpdateEntry(entry); | 214 delegate_->OverrideEntry(entry); |
204 | 215 |
205 tab_->GetControllerImpl().AddTransientEntry(entry); | 216 tab_->GetControllerImpl().AddTransientEntry(entry); |
206 } | 217 } |
207 | 218 |
208 DCHECK(!render_view_host_); | 219 DCHECK(!render_view_host_); |
209 render_view_host_ = CreateRenderViewHost(); | 220 render_view_host_ = CreateRenderViewHost(); |
210 CreateWebContentsView(); | 221 CreateWebContentsView(); |
211 | 222 |
212 std::string data_url = "data:text/html;charset=utf-8," + | 223 std::string data_url = "data:text/html;charset=utf-8," + |
213 net::EscapePath(GetHTMLContents()); | 224 net::EscapePath(delegate_->GetHTMLContents()); |
214 render_view_host_->NavigateToURL(GURL(data_url)); | 225 render_view_host_->NavigateToURL(GURL(data_url)); |
215 | 226 |
216 notification_registrar_.Add(this, | 227 notification_registrar_.Add(this, |
217 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 228 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
218 content::Source<WebContents>(tab_)); | 229 content::Source<WebContents>(tab_)); |
219 notification_registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 230 notification_registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
220 content::Source<NavigationController>(&tab_->GetController())); | 231 content::Source<NavigationController>(&tab_->GetController())); |
221 notification_registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, | 232 notification_registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, |
222 content::Source<NavigationController>(&tab_->GetController())); | 233 content::Source<NavigationController>(&tab_->GetController())); |
223 notification_registrar_.Add( | 234 notification_registrar_.Add( |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 // User decided to proceed and either the navigation was committed or | 314 // User decided to proceed and either the navigation was committed or |
304 // the tab was closed before that. | 315 // the tab was closed before that. |
305 Hide(); | 316 Hide(); |
306 // WARNING: we are now deleted! | 317 // WARNING: we are now deleted! |
307 } | 318 } |
308 break; | 319 break; |
309 case content::NOTIFICATION_DOM_OPERATION_RESPONSE: | 320 case content::NOTIFICATION_DOM_OPERATION_RESPONSE: |
310 if (enabled()) { | 321 if (enabled()) { |
311 content::Details<DomOperationNotificationDetails> dom_op_details( | 322 content::Details<DomOperationNotificationDetails> dom_op_details( |
312 details); | 323 details); |
313 CommandReceived(dom_op_details->json); | 324 delegate_->CommandReceived(dom_op_details->json); |
314 } | 325 } |
315 break; | 326 break; |
316 default: | 327 default: |
317 NOTREACHED(); | 328 NOTREACHED(); |
318 } | 329 } |
319 } | 330 } |
320 | 331 |
321 RenderViewHostDelegate::View* InterstitialPage::GetViewDelegate() { | 332 RenderViewHostDelegate::View* InterstitialPage::GetViewDelegate() { |
322 return rvh_view_delegate_.get(); | 333 return rvh_view_delegate_.get(); |
323 } | 334 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 should_revert_tab_title_ = true; | 420 should_revert_tab_title_ = true; |
410 } | 421 } |
411 // TODO(evan): make use of title_direction. | 422 // TODO(evan): make use of title_direction. |
412 // http://code.google.com/p/chromium/issues/detail?id=27094 | 423 // http://code.google.com/p/chromium/issues/detail?id=27094 |
413 entry->SetTitle(title); | 424 entry->SetTitle(title); |
414 tab_->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE); | 425 tab_->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE); |
415 } | 426 } |
416 | 427 |
417 content::RendererPreferences InterstitialPage::GetRendererPrefs( | 428 content::RendererPreferences InterstitialPage::GetRendererPrefs( |
418 content::BrowserContext* browser_context) const { | 429 content::BrowserContext* browser_context) const { |
| 430 delegate_->OverrideRendererPrefs(&renderer_preferences_); |
419 return renderer_preferences_; | 431 return renderer_preferences_; |
420 } | 432 } |
421 | 433 |
422 WebPreferences InterstitialPage::GetWebkitPrefs() { | 434 WebPreferences InterstitialPage::GetWebkitPrefs() { |
423 return tab_->GetWebkitPrefs(render_view_host(), url_); | 435 return tab_->GetWebkitPrefs(render_view_host(), url_); |
424 } | 436 } |
425 | 437 |
426 bool InterstitialPage::PreHandleKeyboardEvent( | 438 bool InterstitialPage::PreHandleKeyboardEvent( |
427 const NativeWebKeyboardEvent& event, | 439 const NativeWebKeyboardEvent& event, |
428 bool* is_keyboard_shortcut) { | 440 bool* is_keyboard_shortcut) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 TakeActionOnResourceDispatcher(RESUME); | 495 TakeActionOnResourceDispatcher(RESUME); |
484 | 496 |
485 // No need to hide if we are a new navigation, we'll get hidden when the | 497 // No need to hide if we are a new navigation, we'll get hidden when the |
486 // navigation is committed. | 498 // navigation is committed. |
487 if (!new_navigation_) { | 499 if (!new_navigation_) { |
488 Hide(); | 500 Hide(); |
489 // WARNING: we are now deleted! | 501 // WARNING: we are now deleted! |
490 } | 502 } |
491 } | 503 } |
492 | 504 |
493 std::string InterstitialPage::GetHTMLContents() { | |
494 return std::string(); | |
495 } | |
496 | |
497 void InterstitialPage::DontProceed() { | 505 void InterstitialPage::DontProceed() { |
498 DCHECK(action_taken_ != DONT_PROCEED_ACTION); | 506 DCHECK(action_taken_ != DONT_PROCEED_ACTION); |
499 | 507 |
500 Disable(); | 508 Disable(); |
501 action_taken_ = DONT_PROCEED_ACTION; | 509 action_taken_ = DONT_PROCEED_ACTION; |
502 | 510 |
503 // If this is a new navigation, we are returning to the original page, so we | 511 // If this is a new navigation, we are returning to the original page, so we |
504 // resume blocked requests for it. If it is not a new navigation, then it | 512 // resume blocked requests for it. If it is not a new navigation, then it |
505 // means the interstitial was shown as a result of a resource loading in the | 513 // means the interstitial was shown as a result of a resource loading in the |
506 // page and we won't return to the original page, so we cancel blocked | 514 // page and we won't return to the original page, so we cancel blocked |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 | 561 |
554 void InterstitialPage::Focus() { | 562 void InterstitialPage::Focus() { |
555 // Focus the native window. | 563 // Focus the native window. |
556 render_view_host_->view()->Focus(); | 564 render_view_host_->view()->Focus(); |
557 } | 565 } |
558 | 566 |
559 void InterstitialPage::FocusThroughTabTraversal(bool reverse) { | 567 void InterstitialPage::FocusThroughTabTraversal(bool reverse) { |
560 render_view_host_->SetInitialFocus(reverse); | 568 render_view_host_->SetInitialFocus(reverse); |
561 } | 569 } |
562 | 570 |
| 571 content::InterstitialPageDelegate* InterstitialPage::GetDelegateForTesting() { |
| 572 return delegate_.get(); |
| 573 } |
| 574 |
563 content::ViewType InterstitialPage::GetRenderViewType() const { | 575 content::ViewType InterstitialPage::GetRenderViewType() const { |
564 return content::VIEW_TYPE_INTERSTITIAL_PAGE; | 576 return content::VIEW_TYPE_INTERSTITIAL_PAGE; |
565 } | 577 } |
566 | 578 |
567 gfx::Rect InterstitialPage::GetRootWindowResizerRect() const { | 579 gfx::Rect InterstitialPage::GetRootWindowResizerRect() const { |
568 return gfx::Rect(); | 580 return gfx::Rect(); |
569 } | 581 } |
570 | 582 |
571 void InterstitialPage::Disable() { | 583 void InterstitialPage::Disable() { |
572 enabled_ = false; | 584 enabled_ = false; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 if (!tab->GetViewDelegate()) | 713 if (!tab->GetViewDelegate()) |
702 return; | 714 return; |
703 | 715 |
704 tab->GetViewDelegate()->TakeFocus(reverse); | 716 tab->GetViewDelegate()->TakeFocus(reverse); |
705 } | 717 } |
706 | 718 |
707 void InterstitialPage::InterstitialPageRVHViewDelegate::OnFindReply( | 719 void InterstitialPage::InterstitialPageRVHViewDelegate::OnFindReply( |
708 int request_id, int number_of_matches, const gfx::Rect& selection_rect, | 720 int request_id, int number_of_matches, const gfx::Rect& selection_rect, |
709 int active_match_ordinal, bool final_update) { | 721 int active_match_ordinal, bool final_update) { |
710 } | 722 } |
OLD | NEW |