| 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/browser_url_handler.h" | 5 #include "content/browser/browser_url_handler.h" |
| 6 #include "content/browser/renderer_host/test_backing_store.h" | 6 #include "content/browser/renderer_host/test_backing_store.h" |
| 7 #include "content/browser/renderer_host/test_render_view_host.h" | 7 #include "content/browser/renderer_host/test_render_view_host.h" |
| 8 #include "content/browser/site_instance_impl.h" | 8 #include "content/browser/site_instance_impl.h" |
| 9 #include "content/browser/tab_contents/navigation_controller_impl.h" | 9 #include "content/browser/tab_contents/navigation_controller_impl.h" |
| 10 #include "content/browser/tab_contents/navigation_entry_impl.h" | 10 #include "content/browser/tab_contents/navigation_entry_impl.h" |
| 11 #include "content/browser/tab_contents/test_tab_contents.h" | 11 #include "content/browser/tab_contents/test_tab_contents.h" |
| 12 #include "content/common/dom_storage_common.h" | 12 #include "content/common/dom_storage_common.h" |
| 13 #include "content/common/view_messages.h" | 13 #include "content/common/view_messages.h" |
| 14 #include "content/public/browser/navigation_controller.h" | 14 #include "content/public/browser/navigation_controller.h" |
| 15 #include "content/public/common/content_client.h" | 15 #include "content/public/common/content_client.h" |
| 16 #include "content/test/test_browser_context.h" | 16 #include "content/test/test_browser_context.h" |
| 17 #include "ui/gfx/rect.h" | 17 #include "ui/gfx/rect.h" |
| 18 #include "webkit/forms/password_form.h" | 18 #include "webkit/forms/password_form.h" |
| 19 #include "webkit/glue/webkit_glue.h" | 19 #include "webkit/glue/webkit_glue.h" |
| 20 #include "webkit/glue/webpreferences.h" | 20 #include "webkit/glue/webpreferences.h" |
| 21 | 21 |
| 22 #if defined(USE_AURA) | 22 #if defined(USE_AURA) |
| 23 #include "ui/aura/root_window.h" | 23 #include "ui/aura/root_window.h" |
| 24 #include "ui/aura/test/test_stacking_client.h" | 24 #include "ui/aura/test/test_stacking_client.h" |
| 25 #endif | 25 #endif |
| 26 | 26 |
| 27 using content::NavigationController; | 27 using content::NavigationController; |
| 28 using content::NavigationEntry; | 28 using content::NavigationEntry; |
| 29 using content::RenderViewHostDelegate; | 29 using content::RenderViewHostDelegate; |
| 30 using content::RenderWidgetHost; |
| 30 using content::SessionStorageNamespace; | 31 using content::SessionStorageNamespace; |
| 31 using content::SiteInstance; | 32 using content::SiteInstance; |
| 33 using content::TestRenderViewHost; |
| 32 using webkit::forms::PasswordForm; | 34 using webkit::forms::PasswordForm; |
| 33 | 35 |
| 36 namespace content { |
| 37 |
| 34 void InitNavigateParams(ViewHostMsg_FrameNavigate_Params* params, | 38 void InitNavigateParams(ViewHostMsg_FrameNavigate_Params* params, |
| 35 int page_id, | 39 int page_id, |
| 36 const GURL& url, | 40 const GURL& url, |
| 37 content::PageTransition transition) { | 41 PageTransition transition) { |
| 38 params->page_id = page_id; | 42 params->page_id = page_id; |
| 39 params->url = url; | 43 params->url = url; |
| 40 params->referrer = content::Referrer(); | 44 params->referrer = Referrer(); |
| 41 params->transition = transition; | 45 params->transition = transition; |
| 42 params->redirects = std::vector<GURL>(); | 46 params->redirects = std::vector<GURL>(); |
| 43 params->should_update_history = false; | 47 params->should_update_history = false; |
| 44 params->searchable_form_url = GURL(); | 48 params->searchable_form_url = GURL(); |
| 45 params->searchable_form_encoding = std::string(); | 49 params->searchable_form_encoding = std::string(); |
| 46 params->password_form = PasswordForm(); | 50 params->password_form = PasswordForm(); |
| 47 params->security_info = std::string(); | 51 params->security_info = std::string(); |
| 48 params->gesture = NavigationGestureUser; | 52 params->gesture = NavigationGestureUser; |
| 49 params->was_within_same_page = false; | 53 params->was_within_same_page = false; |
| 50 params->is_post = false; | 54 params->is_post = false; |
| 51 params->content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); | 55 params->content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); |
| 52 } | 56 } |
| 53 | 57 |
| 54 TestRenderViewHost* TestRenderViewHost::GetPendingForController( | 58 TestRenderViewHost* TestRenderViewHost::GetPendingForController( |
| 55 content::NavigationController* controller) { | 59 NavigationController* controller) { |
| 56 TabContents* tab_contents = static_cast<TabContents*>( | 60 TabContents* tab_contents = static_cast<TabContents*>( |
| 57 controller->GetWebContents()); | 61 controller->GetWebContents()); |
| 58 return static_cast<TestRenderViewHost*>( | 62 return static_cast<TestRenderViewHost*>( |
| 59 tab_contents->GetRenderManagerForTesting()->pending_render_view_host()); | 63 tab_contents->GetRenderManagerForTesting()->pending_render_view_host()); |
| 60 } | 64 } |
| 61 | 65 |
| 62 TestRenderViewHost::TestRenderViewHost(SiteInstance* instance, | 66 TestRenderViewHost::TestRenderViewHost(SiteInstance* instance, |
| 63 RenderViewHostDelegate* delegate, | 67 RenderViewHostDelegate* delegate, |
| 64 int routing_id) | 68 int routing_id) |
| 65 : RenderViewHostImpl(instance, | 69 : RenderViewHostImpl(instance, |
| 66 delegate, | 70 delegate, |
| 67 routing_id, | 71 routing_id, |
| 68 kInvalidSessionStorageNamespaceId), | 72 kInvalidSessionStorageNamespaceId), |
| 69 render_view_created_(false), | 73 render_view_created_(false), |
| 70 delete_counter_(NULL), | 74 delete_counter_(NULL), |
| 71 simulate_fetch_via_proxy_(false), | 75 simulate_fetch_via_proxy_(false), |
| 72 contents_mime_type_("text/html") { | 76 contents_mime_type_("text/html") { |
| 73 // For normal RenderViewHosts, this is freed when |Shutdown()| is called. | 77 // For normal RenderViewHosts, this is freed when |Shutdown()| is called. |
| 74 // For TestRenderViewHost, the view is explicitly deleted in the destructor | 78 // For TestRenderViewHost, the view is explicitly deleted in the destructor |
| 75 // below, because TestRenderWidgetHostView::Destroy() doesn't |delete this|. | 79 // below, because TestRenderWidgetHostView::Destroy() doesn't |delete this|. |
| 76 SetView(new content::TestRenderWidgetHostView(this)); | 80 SetView(new TestRenderWidgetHostView(this)); |
| 77 } | 81 } |
| 78 | 82 |
| 79 TestRenderViewHost::~TestRenderViewHost() { | 83 TestRenderViewHost::~TestRenderViewHost() { |
| 80 if (delete_counter_) | 84 if (delete_counter_) |
| 81 ++*delete_counter_; | 85 ++*delete_counter_; |
| 82 | 86 |
| 83 // Since this isn't a traditional view, we have to delete it. | 87 // Since this isn't a traditional view, we have to delete it. |
| 84 delete GetView(); | 88 delete GetView(); |
| 85 } | 89 } |
| 86 | 90 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 105 RenderViewHost* rvh) { | 109 RenderViewHost* rvh) { |
| 106 static_cast<RenderViewHostImpl*>( | 110 static_cast<RenderViewHostImpl*>( |
| 107 rvh)->set_send_accessibility_updated_notifications(true); | 111 rvh)->set_send_accessibility_updated_notifications(true); |
| 108 } | 112 } |
| 109 | 113 |
| 110 bool TestRenderViewHost::TestOnMessageReceived(const IPC::Message& msg) { | 114 bool TestRenderViewHost::TestOnMessageReceived(const IPC::Message& msg) { |
| 111 return OnMessageReceived(msg); | 115 return OnMessageReceived(msg); |
| 112 } | 116 } |
| 113 | 117 |
| 114 void TestRenderViewHost::SendNavigate(int page_id, const GURL& url) { | 118 void TestRenderViewHost::SendNavigate(int page_id, const GURL& url) { |
| 115 SendNavigateWithTransition(page_id, url, content::PAGE_TRANSITION_LINK); | 119 SendNavigateWithTransition(page_id, url, PAGE_TRANSITION_LINK); |
| 116 } | 120 } |
| 117 | 121 |
| 118 void TestRenderViewHost::SendNavigateWithTransition( | 122 void TestRenderViewHost::SendNavigateWithTransition( |
| 119 int page_id, const GURL& url, content::PageTransition transition) { | 123 int page_id, const GURL& url, PageTransition transition) { |
| 120 ViewHostMsg_FrameNavigate_Params params; | 124 ViewHostMsg_FrameNavigate_Params params; |
| 121 | 125 |
| 122 params.page_id = page_id; | 126 params.page_id = page_id; |
| 123 params.url = url; | 127 params.url = url; |
| 124 params.referrer = content::Referrer(); | 128 params.referrer = Referrer(); |
| 125 params.transition = transition; | 129 params.transition = transition; |
| 126 params.redirects = std::vector<GURL>(); | 130 params.redirects = std::vector<GURL>(); |
| 127 params.should_update_history = true; | 131 params.should_update_history = true; |
| 128 params.searchable_form_url = GURL(); | 132 params.searchable_form_url = GURL(); |
| 129 params.searchable_form_encoding = std::string(); | 133 params.searchable_form_encoding = std::string(); |
| 130 params.password_form = PasswordForm(); | 134 params.password_form = PasswordForm(); |
| 131 params.security_info = std::string(); | 135 params.security_info = std::string(); |
| 132 params.gesture = NavigationGestureUser; | 136 params.gesture = NavigationGestureUser; |
| 133 params.contents_mime_type = contents_mime_type_; | 137 params.contents_mime_type = contents_mime_type_; |
| 134 params.is_post = false; | 138 params.is_post = false; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 153 } | 157 } |
| 154 | 158 |
| 155 void TestRenderViewHost::set_simulate_fetch_via_proxy(bool proxy) { | 159 void TestRenderViewHost::set_simulate_fetch_via_proxy(bool proxy) { |
| 156 simulate_fetch_via_proxy_ = proxy; | 160 simulate_fetch_via_proxy_ = proxy; |
| 157 } | 161 } |
| 158 | 162 |
| 159 void TestRenderViewHost::set_contents_mime_type(const std::string& mime_type) { | 163 void TestRenderViewHost::set_contents_mime_type(const std::string& mime_type) { |
| 160 contents_mime_type_ = mime_type; | 164 contents_mime_type_ = mime_type; |
| 161 } | 165 } |
| 162 | 166 |
| 163 namespace content { | |
| 164 | |
| 165 TestRenderWidgetHostView::TestRenderWidgetHostView(RenderWidgetHost* rwh) | 167 TestRenderWidgetHostView::TestRenderWidgetHostView(RenderWidgetHost* rwh) |
| 166 : rwh_(RenderWidgetHostImpl::From(rwh)), | 168 : rwh_(RenderWidgetHostImpl::From(rwh)), |
| 167 is_showing_(false) { | 169 is_showing_(false) { |
| 168 } | 170 } |
| 169 | 171 |
| 170 TestRenderWidgetHostView::~TestRenderWidgetHostView() { | 172 TestRenderWidgetHostView::~TestRenderWidgetHostView() { |
| 171 } | 173 } |
| 172 | 174 |
| 173 RenderWidgetHost* TestRenderWidgetHostView::GetRenderWidgetHost() const { | 175 RenderWidgetHost* TestRenderWidgetHostView::GetRenderWidgetHost() const { |
| 174 return NULL; | 176 return NULL; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 | 326 |
| 325 TestRenderViewHostFactory::~TestRenderViewHostFactory() { | 327 TestRenderViewHostFactory::~TestRenderViewHostFactory() { |
| 326 RenderViewHostFactory::UnregisterFactory(); | 328 RenderViewHostFactory::UnregisterFactory(); |
| 327 } | 329 } |
| 328 | 330 |
| 329 void TestRenderViewHostFactory::set_render_process_host_factory( | 331 void TestRenderViewHostFactory::set_render_process_host_factory( |
| 330 content::RenderProcessHostFactory* rph_factory) { | 332 content::RenderProcessHostFactory* rph_factory) { |
| 331 render_process_host_factory_ = rph_factory; | 333 render_process_host_factory_ = rph_factory; |
| 332 } | 334 } |
| 333 | 335 |
| 334 RenderViewHost* TestRenderViewHostFactory::CreateRenderViewHost( | 336 content::RenderViewHost* TestRenderViewHostFactory::CreateRenderViewHost( |
| 335 SiteInstance* instance, | 337 SiteInstance* instance, |
| 336 RenderViewHostDelegate* delegate, | 338 RenderViewHostDelegate* delegate, |
| 337 int routing_id, | 339 int routing_id, |
| 338 SessionStorageNamespace* session_storage) { | 340 SessionStorageNamespace* session_storage) { |
| 339 // See declaration of render_process_host_factory_ below. | 341 // See declaration of render_process_host_factory_ below. |
| 340 static_cast<SiteInstanceImpl*>(instance)-> | 342 static_cast<SiteInstanceImpl*>(instance)-> |
| 341 set_render_process_host_factory(render_process_host_factory_); | 343 set_render_process_host_factory(render_process_host_factory_); |
| 342 return new TestRenderViewHost(instance, delegate, routing_id); | 344 return new TestRenderViewHost(instance, delegate, routing_id); |
| 343 } | 345 } |
| 344 | 346 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 #endif | 431 #endif |
| 430 | 432 |
| 431 // Make sure that we flush any messages related to TabContents destruction | 433 // Make sure that we flush any messages related to TabContents destruction |
| 432 // before we destroy the browser context. | 434 // before we destroy the browser context. |
| 433 MessageLoop::current()->RunAllPending(); | 435 MessageLoop::current()->RunAllPending(); |
| 434 | 436 |
| 435 // Release the browser context on the UI thread. | 437 // Release the browser context on the UI thread. |
| 436 message_loop_.DeleteSoon(FROM_HERE, browser_context_.release()); | 438 message_loop_.DeleteSoon(FROM_HERE, browser_context_.release()); |
| 437 message_loop_.RunAllPending(); | 439 message_loop_.RunAllPending(); |
| 438 } | 440 } |
| OLD | NEW |