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

Side by Side Diff: chrome/renderer/render_view.cc

Issue 16482: Refactor the render widget unittest so it can be reused to create a render vi... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 11 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
« no previous file with comments | « chrome/renderer/render_view.h ('k') | chrome/renderer/render_view_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "chrome/renderer/render_view.h" 5 #include "chrome/renderer/render_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 // Delay in milliseconds that we'll wait before capturing the page contents 82 // Delay in milliseconds that we'll wait before capturing the page contents
83 // and thumbnail. 83 // and thumbnail.
84 static const int kDelayForCaptureMs = 500; 84 static const int kDelayForCaptureMs = 500;
85 85
86 // Typically, we capture the page data once the page is loaded. 86 // Typically, we capture the page data once the page is loaded.
87 // Sometimes, the page never finishes to load, preventing the page capture 87 // Sometimes, the page never finishes to load, preventing the page capture
88 // To workaround this problem, we always perform a capture after the following 88 // To workaround this problem, we always perform a capture after the following
89 // delay. 89 // delay.
90 static const int kDelayForForcedCaptureMs = 6000; 90 static const int kDelayForForcedCaptureMs = 6000;
91 91
92 // How often we will sync the navigation state when the user is changing form 92 // The default value for RenderView.delay_seconds_for_form_state_sync_, see
93 // elements or scroll position. 93 // that variable for more.
94 const TimeDelta kDelayForNavigationSync = TimeDelta::FromSeconds(5); 94 const int kDefaultDelaySecondsForFormStateSync = 5;
95 95
96 // The next available page ID to use. This ensures that the page IDs are 96 // The next available page ID to use. This ensures that the page IDs are
97 // globally unique in the renderer. 97 // globally unique in the renderer.
98 static int32 next_page_id_ = 1; 98 static int32 next_page_id_ = 1;
99 99
100 // The maximum number of popups that can be spawned from one page. 100 // The maximum number of popups that can be spawned from one page.
101 static const int kMaximumNumberOfUnacknowledgedPopups = 25; 101 static const int kMaximumNumberOfUnacknowledgedPopups = 25;
102 102
103 static const char* const kUnreachableWebDataURL = 103 static const char* const kUnreachableWebDataURL =
104 "chrome://chromewebdata/"; 104 "chrome://chromewebdata/";
(...skipping 30 matching lines...) Expand all
135 private: 135 private:
136 int32 pending_page_id_; 136 int32 pending_page_id_;
137 137
138 DISALLOW_EVIL_CONSTRUCTORS(RenderViewExtraRequestData); 138 DISALLOW_EVIL_CONSTRUCTORS(RenderViewExtraRequestData);
139 }; 139 };
140 140
141 } // namespace 141 } // namespace
142 142
143 /////////////////////////////////////////////////////////////////////////////// 143 ///////////////////////////////////////////////////////////////////////////////
144 144
145 RenderView::RenderView() 145 RenderView::RenderView(RenderThreadBase* render_thread)
146 : RenderWidget(g_render_thread, true), 146 : RenderWidget(render_thread, true),
147 is_loading_(false), 147 is_loading_(false),
148 page_id_(-1), 148 page_id_(-1),
149 last_page_id_sent_to_browser_(-1), 149 last_page_id_sent_to_browser_(-1),
150 last_indexed_page_id_(-1), 150 last_indexed_page_id_(-1),
151 method_factory_(this), 151 method_factory_(this),
152 opened_by_user_gesture_(true), 152 opened_by_user_gesture_(true),
153 enable_dom_automation_(false), 153 enable_dom_automation_(false),
154 enable_dom_ui_bindings_(false), 154 enable_dom_ui_bindings_(false),
155 target_url_status_(TARGET_NONE), 155 target_url_status_(TARGET_NONE),
156 printed_document_width_(0), 156 printed_document_width_(0),
157 first_default_plugin_(NULL), 157 first_default_plugin_(NULL),
158 navigation_gesture_(NavigationGestureUnknown), 158 navigation_gesture_(NavigationGestureUnknown),
159 history_back_list_count_(0), 159 history_back_list_count_(0),
160 history_forward_list_count_(0), 160 history_forward_list_count_(0),
161 disable_popup_blocking_(false), 161 disable_popup_blocking_(false),
162 has_unload_listener_(false), 162 has_unload_listener_(false),
163 decrement_shared_popup_at_destruction_(false), 163 decrement_shared_popup_at_destruction_(false),
164 greasemonkey_enabled_(false), 164 greasemonkey_enabled_(false),
165 waiting_for_create_window_ack_(false), 165 waiting_for_create_window_ack_(false),
166 form_field_autofill_request_id_(0), 166 form_field_autofill_request_id_(0),
167 popup_notification_visible_(false) { 167 popup_notification_visible_(false),
168 delay_seconds_for_form_state_sync_(kDefaultDelaySecondsForFormStateSync) {
168 resource_dispatcher_ = new ResourceDispatcher(this); 169 resource_dispatcher_ = new ResourceDispatcher(this);
169 #ifdef CHROME_PERSONALIZATION 170 #ifdef CHROME_PERSONALIZATION
170 personalization_ = Personalization::CreateRendererPersonalization(); 171 personalization_ = Personalization::CreateRendererPersonalization();
171 #endif 172 #endif
172 } 173 }
173 174
174 RenderView::~RenderView() { 175 RenderView::~RenderView() {
175 if (decrement_shared_popup_at_destruction_) 176 if (decrement_shared_popup_at_destruction_)
176 shared_popup_counter_->data--; 177 shared_popup_counter_->data--;
177 178
178 resource_dispatcher_->ClearMessageSender(); 179 resource_dispatcher_->ClearMessageSender();
179 // Clear any back-pointers that might still be held by plugins. 180 // Clear any back-pointers that might still be held by plugins.
180 PluginDelegateList::iterator it = plugin_delegates_.begin(); 181 PluginDelegateList::iterator it = plugin_delegates_.begin();
181 while (it != plugin_delegates_.end()) { 182 while (it != plugin_delegates_.end()) {
182 (*it)->DropRenderView(); 183 (*it)->DropRenderView();
183 it = plugin_delegates_.erase(it); 184 it = plugin_delegates_.erase(it);
184 } 185 }
185 186
186 g_render_thread->RemoveFilter(debug_message_handler_); 187 render_thread_->RemoveFilter(debug_message_handler_);
187 188
188 #ifdef CHROME_PERSONALIZATION 189 #ifdef CHROME_PERSONALIZATION
189 Personalization::CleanupRendererPersonalization(personalization_); 190 Personalization::CleanupRendererPersonalization(personalization_);
190 personalization_ = NULL; 191 personalization_ = NULL;
191 #endif 192 #endif
192 } 193 }
193 194
194 /*static*/ 195 /*static*/
195 RenderView* RenderView::Create( 196 RenderView* RenderView::Create(
197 RenderThreadBase* render_thread,
196 HWND parent_hwnd, 198 HWND parent_hwnd,
197 HANDLE modal_dialog_event, 199 HANDLE modal_dialog_event,
198 int32 opener_id, 200 int32 opener_id,
199 const WebPreferences& webkit_prefs, 201 const WebPreferences& webkit_prefs,
200 SharedRenderViewCounter* counter, 202 SharedRenderViewCounter* counter,
201 int32 routing_id) { 203 int32 routing_id) {
202 DCHECK(routing_id != MSG_ROUTING_NONE); 204 DCHECK(routing_id != MSG_ROUTING_NONE);
203 scoped_refptr<RenderView> view = new RenderView(); 205 scoped_refptr<RenderView> view = new RenderView(render_thread);
204 view->Init(parent_hwnd, 206 view->Init(parent_hwnd,
205 modal_dialog_event, 207 modal_dialog_event,
206 opener_id, 208 opener_id,
207 webkit_prefs, 209 webkit_prefs,
208 counter, 210 counter,
209 routing_id); // adds reference 211 routing_id); // adds reference
210 return view; 212 return view;
211 } 213 }
212 214
213 /*static*/ 215 /*static*/
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 // Avoid a leak here by not assigning, since WebView::Create addrefs for us. 266 // Avoid a leak here by not assigning, since WebView::Create addrefs for us.
265 WebWidget* view = WebView::Create(this, webkit_prefs); 267 WebWidget* view = WebView::Create(this, webkit_prefs);
266 webwidget_.swap(&view); 268 webwidget_.swap(&view);
267 269
268 // Don't let WebCore keep a B/F list - we have our own. 270 // Don't let WebCore keep a B/F list - we have our own.
269 // We let it keep 1 entry because FrameLoader::goToItem expects an item in the 271 // We let it keep 1 entry because FrameLoader::goToItem expects an item in the
270 // backForwardList, which is used only in ASSERTs. 272 // backForwardList, which is used only in ASSERTs.
271 webview()->SetBackForwardListSize(1); 273 webview()->SetBackForwardListSize(1);
272 274
273 routing_id_ = routing_id; 275 routing_id_ = routing_id;
274 g_render_thread->AddRoute(routing_id_, this); 276 render_thread_->AddRoute(routing_id_, this);
275 // Take a reference on behalf of the RenderThread. This will be balanced 277 // Take a reference on behalf of the RenderThread. This will be balanced
276 // when we receive ViewMsg_Close. 278 // when we receive ViewMsg_Close.
277 AddRef(); 279 AddRef();
278 280
279 // If this is a popup, we must wait for the CreatingNew_ACK message before 281 // If this is a popup, we must wait for the CreatingNew_ACK message before
280 // completing initialization. Otherwise, we can finish it now. 282 // completing initialization. Otherwise, we can finish it now.
281 if (opener_id == MSG_ROUTING_NONE) { 283 if (opener_id == MSG_ROUTING_NONE) {
282 did_show_ = true; 284 did_show_ = true;
283 CompleteInit(parent_hwnd); 285 CompleteInit(parent_hwnd);
284 } 286 }
285 287
286 host_window_ = parent_hwnd; 288 host_window_ = parent_hwnd;
287 modal_dialog_event_.Set(modal_dialog_event); 289 modal_dialog_event_.Set(modal_dialog_event);
288 290
289 CommandLine command_line; 291 CommandLine command_line;
290 enable_dom_automation_ = 292 enable_dom_automation_ =
291 command_line.HasSwitch(switches::kDomAutomationController); 293 command_line.HasSwitch(switches::kDomAutomationController);
292 disable_popup_blocking_ = 294 disable_popup_blocking_ =
293 command_line.HasSwitch(switches::kDisablePopupBlocking); 295 command_line.HasSwitch(switches::kDisablePopupBlocking);
294 greasemonkey_enabled_ = 296 greasemonkey_enabled_ =
295 command_line.HasSwitch(switches::kEnableGreasemonkey); 297 command_line.HasSwitch(switches::kEnableGreasemonkey);
296 298
297 debug_message_handler_ = new DebugMessageHandler(this); 299 debug_message_handler_ = new DebugMessageHandler(this);
298 g_render_thread->AddFilter(debug_message_handler_); 300 render_thread_->AddFilter(debug_message_handler_);
299 } 301 }
300 302
301 void RenderView::OnMessageReceived(const IPC::Message& message) { 303 void RenderView::OnMessageReceived(const IPC::Message& message) {
302 // If the current RenderView instance represents a popup, then we 304 // If the current RenderView instance represents a popup, then we
303 // need to wait for ViewMsg_CreatingNew_ACK to be sent by the browser. 305 // need to wait for ViewMsg_CreatingNew_ACK to be sent by the browser.
304 // As part of this ack we also receive the browser window handle, which 306 // As part of this ack we also receive the browser window handle, which
305 // parents any plugins instantiated in this RenderView instance. 307 // parents any plugins instantiated in this RenderView instance.
306 // Plugins can be instantiated only when we receive the parent window 308 // Plugins can be instantiated only when we receive the parent window
307 // handle as they are child windows. 309 // handle as they are child windows.
308 if (waiting_for_create_window_ack_ && 310 if (waiting_for_create_window_ack_ &&
(...skipping 1142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1451 1453
1452 void RenderView::DidFinishDocumentLoadForFrame(WebView* webview, 1454 void RenderView::DidFinishDocumentLoadForFrame(WebView* webview,
1453 WebFrame* frame) { 1455 WebFrame* frame) {
1454 // Check whether we have new encoding name. 1456 // Check whether we have new encoding name.
1455 UpdateEncoding(frame, webview->GetMainFrameEncodingName()); 1457 UpdateEncoding(frame, webview->GetMainFrameEncodingName());
1456 1458
1457 // Inject any Greasemonkey scripts. Do not inject into chrome UI pages, but 1459 // Inject any Greasemonkey scripts. Do not inject into chrome UI pages, but
1458 // do inject into any other document. 1460 // do inject into any other document.
1459 if (greasemonkey_enabled_) { 1461 if (greasemonkey_enabled_) {
1460 const GURL &gurl = frame->GetURL(); 1462 const GURL &gurl = frame->GetURL();
1461 if (gurl.SchemeIs("file") || 1463 if (g_render_thread && // Will be NULL when testing.
1462 gurl.SchemeIs("http") || 1464 (gurl.SchemeIs("file") ||
1463 gurl.SchemeIs("https")) { 1465 gurl.SchemeIs("http") ||
1466 gurl.SchemeIs("https"))) {
1464 g_render_thread->greasemonkey_slave()->InjectScripts(frame); 1467 g_render_thread->greasemonkey_slave()->InjectScripts(frame);
1465 } 1468 }
1466 } 1469 }
1467 } 1470 }
1468 1471
1469 void RenderView::DidHandleOnloadEventsForFrame(WebView* webview, 1472 void RenderView::DidHandleOnloadEventsForFrame(WebView* webview,
1470 WebFrame* frame) { 1473 WebFrame* frame) {
1471 } 1474 }
1472 1475
1473 void RenderView::DidChangeLocationWithinPageForFrame(WebView* webview, 1476 void RenderView::DidChangeLocationWithinPageForFrame(WebView* webview,
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1778 // Check to make sure we aren't overloading on popups. 1781 // Check to make sure we aren't overloading on popups.
1779 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups) 1782 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1780 return NULL; 1783 return NULL;
1781 1784
1782 // This window can't be closed from a window.close() call until we receive a 1785 // This window can't be closed from a window.close() call until we receive a
1783 // message from the Browser process explicitly allowing it. 1786 // message from the Browser process explicitly allowing it.
1784 popup_notification_visible_ = true; 1787 popup_notification_visible_ = true;
1785 1788
1786 int32 routing_id = MSG_ROUTING_NONE; 1789 int32 routing_id = MSG_ROUTING_NONE;
1787 HANDLE modal_dialog_event = NULL; 1790 HANDLE modal_dialog_event = NULL;
1788 bool result = g_render_thread->Send( 1791 bool result = render_thread_->Send(
1789 new ViewHostMsg_CreateWindow(routing_id_, user_gesture, &routing_id, 1792 new ViewHostMsg_CreateWindow(routing_id_, user_gesture, &routing_id,
1790 &modal_dialog_event)); 1793 &modal_dialog_event));
1791 if (routing_id == MSG_ROUTING_NONE) { 1794 if (routing_id == MSG_ROUTING_NONE) {
1792 DCHECK(modal_dialog_event == NULL); 1795 DCHECK(modal_dialog_event == NULL);
1793 return NULL; 1796 return NULL;
1794 } 1797 }
1795 1798
1796 // The WebView holds a reference to this new RenderView 1799 // The WebView holds a reference to this new RenderView
1797 const WebPreferences& prefs = webview->GetPreferences(); 1800 const WebPreferences& prefs = webview->GetPreferences();
1798 RenderView* view = RenderView::Create(NULL, modal_dialog_event, routing_id_, 1801 RenderView* view = RenderView::Create(render_thread_,
1802 NULL, modal_dialog_event, routing_id_,
1799 prefs, shared_popup_counter_, 1803 prefs, shared_popup_counter_,
1800 routing_id); 1804 routing_id);
1801 view->set_opened_by_user_gesture(user_gesture); 1805 view->set_opened_by_user_gesture(user_gesture);
1802 view->set_waiting_for_create_window_ack(true); 1806 view->set_waiting_for_create_window_ack(true);
1803 1807
1804 // Copy over the alternate error page URL so we can have alt error pages in 1808 // Copy over the alternate error page URL so we can have alt error pages in
1805 // the new render view (we don't need the browser to send the URL back down). 1809 // the new render view (we don't need the browser to send the URL back down).
1806 view->alternate_error_page_url_ = alternate_error_page_url_; 1810 view->alternate_error_page_url_ = alternate_error_page_url_;
1807 1811
1808 return view->webview(); 1812 return view->webview();
1809 } 1813 }
1810 1814
1811 WebWidget* RenderView::CreatePopupWidget(WebView* webview, 1815 WebWidget* RenderView::CreatePopupWidget(WebView* webview,
1812 bool focus_on_show) { 1816 bool focus_on_show) {
1813 RenderWidget* widget = RenderWidget::Create(routing_id_, 1817 RenderWidget* widget = RenderWidget::Create(routing_id_,
1814 g_render_thread, 1818 render_thread_,
1815 focus_on_show); 1819 focus_on_show);
1816 return widget->webwidget(); 1820 return widget->webwidget();
1817 } 1821 }
1818 1822
1819 static bool ShouldLoadPluginInProcess(const std::string& mime_type, 1823 static bool ShouldLoadPluginInProcess(const std::string& mime_type,
1820 bool* is_gears) { 1824 bool* is_gears) {
1821 if (RenderProcess::ShouldLoadPluginsInProcess()) 1825 if (RenderProcess::ShouldLoadPluginsInProcess())
1822 return true; 1826 return true;
1823 1827
1824 if (mime_type == "application/x-googlegears") { 1828 if (mime_type == "application/x-googlegears") {
1825 *is_gears = true; 1829 *is_gears = true;
1826 CommandLine cmd; 1830 CommandLine cmd;
1827 return cmd.HasSwitch(switches::kGearsInRenderer); 1831 return cmd.HasSwitch(switches::kGearsInRenderer);
1828 } 1832 }
1829 1833
1830 return false; 1834 return false;
1831 } 1835 }
1832 1836
1833 WebPluginDelegate* RenderView::CreatePluginDelegate( 1837 WebPluginDelegate* RenderView::CreatePluginDelegate(
1834 WebView* webview, 1838 WebView* webview,
1835 const GURL& url, 1839 const GURL& url,
1836 const std::string& mime_type, 1840 const std::string& mime_type,
1837 const std::string& clsid, 1841 const std::string& clsid,
1838 std::string* actual_mime_type) { 1842 std::string* actual_mime_type) {
1839 bool is_gears = false; 1843 bool is_gears = false;
1840 if (ShouldLoadPluginInProcess(mime_type, &is_gears)) { 1844 if (ShouldLoadPluginInProcess(mime_type, &is_gears)) {
1841 std::wstring path; 1845 std::wstring path;
1842 g_render_thread->Send( 1846 render_thread_->Send(
1843 new ViewHostMsg_GetPluginPath(url, mime_type, clsid, &path, 1847 new ViewHostMsg_GetPluginPath(url, mime_type, clsid, &path,
1844 actual_mime_type)); 1848 actual_mime_type));
1845 if (path.empty()) 1849 if (path.empty())
1846 return NULL; 1850 return NULL;
1847 1851
1848 std::string mime_type_to_use; 1852 std::string mime_type_to_use;
1849 if (actual_mime_type && !actual_mime_type->empty()) 1853 if (actual_mime_type && !actual_mime_type->empty())
1850 mime_type_to_use = *actual_mime_type; 1854 mime_type_to_use = *actual_mime_type;
1851 else 1855 else
1852 mime_type_to_use = mime_type; 1856 mime_type_to_use = mime_type;
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
2362 2366
2363 int RenderView::GetHistoryBackListCount() { 2367 int RenderView::GetHistoryBackListCount() {
2364 return history_back_list_count_; 2368 return history_back_list_count_;
2365 } 2369 }
2366 2370
2367 int RenderView::GetHistoryForwardListCount() { 2371 int RenderView::GetHistoryForwardListCount() {
2368 return history_forward_list_count_; 2372 return history_forward_list_count_;
2369 } 2373 }
2370 2374
2371 void RenderView::OnNavStateChanged(WebView* webview) { 2375 void RenderView::OnNavStateChanged(WebView* webview) {
2372 if (!nav_state_sync_timer_.IsRunning()) 2376 if (!nav_state_sync_timer_.IsRunning()) {
2373 nav_state_sync_timer_.Start(kDelayForNavigationSync, this, 2377 nav_state_sync_timer_.Start(
2374 &RenderView::SyncNavigationState); 2378 TimeDelta::FromSeconds(delay_seconds_for_form_state_sync_), this,
2379 &RenderView::SyncNavigationState);
2380 }
2375 } 2381 }
2376 2382
2377 void RenderView::SetTooltipText(WebView* webview, 2383 void RenderView::SetTooltipText(WebView* webview,
2378 const std::wstring& tooltip_text) { 2384 const std::wstring& tooltip_text) {
2379 Send(new ViewHostMsg_SetTooltipText(routing_id_, tooltip_text)); 2385 Send(new ViewHostMsg_SetTooltipText(routing_id_, tooltip_text));
2380 } 2386 }
2381 2387
2382 void RenderView::DownloadUrl(const GURL& url, const GURL& referrer) { 2388 void RenderView::DownloadUrl(const GURL& url, const GURL& referrer) {
2383 Send(new ViewHostMsg_DownloadUrl(routing_id_, url, referrer)); 2389 Send(new ViewHostMsg_DownloadUrl(routing_id_, url, referrer));
2384 } 2390 }
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
2754 template_resource_id)); 2760 template_resource_id));
2755 2761
2756 if (template_html.empty()) { 2762 if (template_html.empty()) {
2757 NOTREACHED() << "unable to load template. ID: " << template_resource_id; 2763 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
2758 return ""; 2764 return "";
2759 } 2765 }
2760 // "t" is the id of the templates root node. 2766 // "t" is the id of the templates root node.
2761 return jstemplate_builder::GetTemplateHtml( 2767 return jstemplate_builder::GetTemplateHtml(
2762 template_html, &error_strings, "t"); 2768 template_html, &error_strings, "t");
2763 } 2769 }
OLDNEW
« no previous file with comments | « chrome/renderer/render_view.h ('k') | chrome/renderer/render_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698