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

Side by Side Diff: webkit/glue/webframe_impl.cc

Issue 335019: Replace MessageLoop+ScopedRunnableMethodFactory with WebCore::Timer+Vector... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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 | « webkit/glue/webframe_impl.h ('k') | webkit/glue/webview_impl.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 /* 1 /*
2 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) 2 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
3 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. 3 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 #include "SelectionController.h" 121 #include "SelectionController.h"
122 #include "Settings.h" 122 #include "Settings.h"
123 #include "SkiaUtils.h" 123 #include "SkiaUtils.h"
124 #include "SubstituteData.h" 124 #include "SubstituteData.h"
125 #include "TextIterator.h" 125 #include "TextIterator.h"
126 #include "TextAffinity.h" 126 #include "TextAffinity.h"
127 #include "XPathResult.h" 127 #include "XPathResult.h"
128 #include <wtf/CurrentTime.h> 128 #include <wtf/CurrentTime.h>
129 #undef LOG 129 #undef LOG
130 130
131 #include "base/message_loop.h"
132 #include "webkit/api/public/WebConsoleMessage.h" 131 #include "webkit/api/public/WebConsoleMessage.h"
133 #include "webkit/api/public/WebFindOptions.h" 132 #include "webkit/api/public/WebFindOptions.h"
134 #include "webkit/api/public/WebForm.h" 133 #include "webkit/api/public/WebForm.h"
135 #include "webkit/api/public/WebFrameClient.h" 134 #include "webkit/api/public/WebFrameClient.h"
136 #include "webkit/api/public/WebHistoryItem.h" 135 #include "webkit/api/public/WebHistoryItem.h"
137 #include "webkit/api/public/WebRange.h" 136 #include "webkit/api/public/WebRange.h"
138 #include "webkit/api/public/WebRect.h" 137 #include "webkit/api/public/WebRect.h"
139 #include "webkit/api/public/WebScriptSource.h" 138 #include "webkit/api/public/WebScriptSource.h"
140 #include "webkit/api/public/WebSecurityOrigin.h" 139 #include "webkit/api/public/WebSecurityOrigin.h"
141 #include "webkit/api/public/WebSize.h" 140 #include "webkit/api/public/WebSize.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 using WebCore::ResourceHandle; 181 using WebCore::ResourceHandle;
183 using WebCore::ResourceRequest; 182 using WebCore::ResourceRequest;
184 using WebCore::ResourceResponse; 183 using WebCore::ResourceResponse;
185 using WebCore::VisibleSelection; 184 using WebCore::VisibleSelection;
186 using WebCore::ScriptValue; 185 using WebCore::ScriptValue;
187 using WebCore::SecurityOrigin; 186 using WebCore::SecurityOrigin;
188 using WebCore::SharedBuffer; 187 using WebCore::SharedBuffer;
189 using WebCore::String; 188 using WebCore::String;
190 using WebCore::SubstituteData; 189 using WebCore::SubstituteData;
191 using WebCore::TextIterator; 190 using WebCore::TextIterator;
191 using WebCore::Timer;
192 using WebCore::VisiblePosition; 192 using WebCore::VisiblePosition;
193 using WebCore::XPathResult; 193 using WebCore::XPathResult;
194 194
195 using WebKit::PasswordAutocompleteListener; 195 using WebKit::PasswordAutocompleteListener;
196 using WebKit::WebCanvas; 196 using WebKit::WebCanvas;
197 using WebKit::WebConsoleMessage; 197 using WebKit::WebConsoleMessage;
198 using WebKit::WebData; 198 using WebKit::WebData;
199 using WebKit::WebDataSource; 199 using WebKit::WebDataSource;
200 using WebKit::WebDataSourceImpl; 200 using WebKit::WebDataSourceImpl;
201 using WebKit::WebFindOptions; 201 using WebKit::WebFindOptions;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 float printed_page_width_; 341 float printed_page_width_;
342 342
343 private: 343 private:
344 DISALLOW_COPY_AND_ASSIGN(ChromePrintContext); 344 DISALLOW_COPY_AND_ASSIGN(ChromePrintContext);
345 }; 345 };
346 346
347 static WebDataSource* DataSourceForDocLoader(DocumentLoader* loader) { 347 static WebDataSource* DataSourceForDocLoader(DocumentLoader* loader) {
348 return loader ? WebDataSourceImpl::fromDocumentLoader(loader) : NULL; 348 return loader ? WebDataSourceImpl::fromDocumentLoader(loader) : NULL;
349 } 349 }
350 350
351
352 // WebFrame -------------------------------------------------------------------
353
354 class WebFrameImpl::DeferredScopeStringMatches {
355 public:
356 DeferredScopeStringMatches(WebFrameImpl* webframe,
357 int identifier,
358 const WebString& search_text,
359 const WebFindOptions& options,
360 bool reset)
361 : timer_(this, &DeferredScopeStringMatches::DoTimeout),
362 webframe_(webframe),
363 identifier_(identifier),
364 search_text_(search_text),
365 options_(options),
366 reset_(reset) {
367 timer_.startOneShot(0.0);
368 }
369
370 private:
371 void DoTimeout(Timer<DeferredScopeStringMatches>*) {
372 webframe_->CallScopeStringMatches(
373 this, identifier_, search_text_, options_, reset_);
374 }
375
376 Timer<DeferredScopeStringMatches> timer_;
377 RefPtr<WebFrameImpl> webframe_;
378 int identifier_;
379 WebString search_text_;
380 WebFindOptions options_;
381 bool reset_;
382 };
383
384
351 // WebFrame ------------------------------------------------------------------- 385 // WebFrame -------------------------------------------------------------------
352 386
353 // static 387 // static
354 WebFrame* WebFrame::frameForEnteredContext() { 388 WebFrame* WebFrame::frameForEnteredContext() {
355 Frame* frame = 389 Frame* frame =
356 WebCore::ScriptController::retrieveFrameForEnteredContext(); 390 WebCore::ScriptController::retrieveFrameForEnteredContext();
357 return WebFrameImpl::FromFrame(frame); 391 return WebFrameImpl::FromFrame(frame);
358 } 392 }
359 393
360 // static 394 // static
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 frame()->page()->unmarkAllTextMatches(); 1254 frame()->page()->unmarkAllTextMatches();
1221 // Clear the counters from last operation. 1255 // Clear the counters from last operation.
1222 last_match_count_ = 0; 1256 last_match_count_ = 0;
1223 next_invalidate_after_ = 0; 1257 next_invalidate_after_ = 0;
1224 1258
1225 resume_scoping_from_range_ = NULL; 1259 resume_scoping_from_range_ = NULL;
1226 1260
1227 main_frame_impl->frames_scoping_count_++; 1261 main_frame_impl->frames_scoping_count_++;
1228 1262
1229 // Now, defer scoping until later to allow find operation to finish quickly. 1263 // Now, defer scoping until later to allow find operation to finish quickly.
1230 // TODO(darin): Replace with a WebCore Timer. 1264 ScopeStringMatchesSoon(
1231 MessageLoop::current()->PostTask(FROM_HERE, 1265 request_id,
1232 scope_matches_factory_.NewRunnableMethod( 1266 search_text,
1233 &WebFrameImpl::scopeStringMatches, 1267 options,
1234 request_id, 1268 false); // false=we just reset, so don't do it again.
1235 search_text,
1236 options,
1237 false)); // false=we just reset, so don't do it again.
1238 return; 1269 return;
1239 } 1270 }
1240 1271
1241 WebCore::String webcore_string = webkit_glue::String16ToString(search_text); 1272 WebCore::String webcore_string = webkit_glue::String16ToString(search_text);
1242 1273
1243 RefPtr<Range> search_range(rangeOfContents(frame()->document())); 1274 RefPtr<Range> search_range(rangeOfContents(frame()->document()));
1244 1275
1245 ExceptionCode ec = 0, ec2 = 0; 1276 ExceptionCode ec = 0, ec2 = 0;
1246 if (resume_scoping_from_range_.get()) { 1277 if (resume_scoping_from_range_.get()) {
1247 // This is a continuation of a scoping operation that timed out and didn't 1278 // This is a continuation of a scoping operation that timed out and didn't
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 } 1390 }
1360 1391
1361 if (timeout) { 1392 if (timeout) {
1362 // If we found anything during this pass, we should redraw. However, we 1393 // If we found anything during this pass, we should redraw. However, we
1363 // don't want to spam too much if the page is extremely long, so if we 1394 // don't want to spam too much if the page is extremely long, so if we
1364 // reach a certain point we start throttling the redraw requests. 1395 // reach a certain point we start throttling the redraw requests.
1365 if (match_count > 0) 1396 if (match_count > 0)
1366 InvalidateIfNecessary(); 1397 InvalidateIfNecessary();
1367 1398
1368 // Scoping effort ran out of time, lets ask for another time-slice. 1399 // Scoping effort ran out of time, lets ask for another time-slice.
1369 // TODO(darin): Replace with a WebCore Timer. 1400 ScopeStringMatchesSoon(
1370 MessageLoop::current()->PostTask(FROM_HERE, 1401 request_id,
1371 scope_matches_factory_.NewRunnableMethod( 1402 search_text,
1372 &WebFrameImpl::scopeStringMatches, 1403 options,
1373 request_id, 1404 false); // don't reset.
1374 search_text,
1375 options,
1376 false)); // don't reset.
1377
1378 return; // Done for now, resume work later. 1405 return; // Done for now, resume work later.
1379 } 1406 }
1380 1407
1381 // This frame has no further scoping left, so it is done. Other frames might, 1408 // This frame has no further scoping left, so it is done. Other frames might,
1382 // of course, continue to scope matches. 1409 // of course, continue to scope matches.
1383 scoping_complete_ = true; 1410 scoping_complete_ = true;
1384 main_frame_impl->frames_scoping_count_--; 1411 main_frame_impl->frames_scoping_count_--;
1385 1412
1386 // If this is the last frame to finish scoping we need to trigger the final 1413 // If this is the last frame to finish scoping we need to trigger the final
1387 // update to be sent. 1414 // update to be sent.
1388 if (main_frame_impl->frames_scoping_count_ == 0) 1415 if (main_frame_impl->frames_scoping_count_ == 0)
1389 main_frame_impl->increaseMatchCount(0, request_id); 1416 main_frame_impl->increaseMatchCount(0, request_id);
1390 1417
1391 // This frame is done, so show any scrollbar tickmarks we haven't drawn yet. 1418 // This frame is done, so show any scrollbar tickmarks we haven't drawn yet.
1392 InvalidateArea(INVALIDATE_SCROLLBAR); 1419 InvalidateArea(INVALIDATE_SCROLLBAR);
1393 } 1420 }
1394 1421
1395 void WebFrameImpl::cancelPendingScopingEffort() { 1422 void WebFrameImpl::cancelPendingScopingEffort() {
1396 scope_matches_factory_.RevokeAll(); 1423 deleteAllValues(deferred_scoping_work_);
1424 deferred_scoping_work_.clear();
1425
1397 active_match_index_ = -1; 1426 active_match_index_ = -1;
1398 } 1427 }
1399 1428
1400 void WebFrameImpl::increaseMatchCount(int count, int request_id) { 1429 void WebFrameImpl::increaseMatchCount(int count, int request_id) {
1401 // This function should only be called on the mainframe. 1430 // This function should only be called on the mainframe.
1402 ASSERT(!parent()); 1431 ASSERT(!parent());
1403 1432
1404 total_matchcount_ += count; 1433 total_matchcount_ += count;
1405 1434
1406 // Update the UI with the latest findings. 1435 // Update the UI with the latest findings.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1450 // WebFrameImpl public --------------------------------------------------------- 1479 // WebFrameImpl public ---------------------------------------------------------
1451 1480
1452 int WebFrameImpl::live_object_count_ = 0; 1481 int WebFrameImpl::live_object_count_ = 0;
1453 1482
1454 PassRefPtr<WebFrameImpl> WebFrameImpl::create(WebFrameClient* client) { 1483 PassRefPtr<WebFrameImpl> WebFrameImpl::create(WebFrameClient* client) {
1455 return adoptRef(new WebFrameImpl(ClientHandle::create(client))); 1484 return adoptRef(new WebFrameImpl(ClientHandle::create(client)));
1456 } 1485 }
1457 1486
1458 WebFrameImpl::WebFrameImpl(PassRefPtr<ClientHandle> client_handle) 1487 WebFrameImpl::WebFrameImpl(PassRefPtr<ClientHandle> client_handle)
1459 : ALLOW_THIS_IN_INITIALIZER_LIST(frame_loader_client_(this)), 1488 : ALLOW_THIS_IN_INITIALIZER_LIST(frame_loader_client_(this)),
1460 ALLOW_THIS_IN_INITIALIZER_LIST(scope_matches_factory_(this)),
1461 client_handle_(client_handle), 1489 client_handle_(client_handle),
1462 active_match_frame_(NULL), 1490 active_match_frame_(NULL),
1463 active_match_index_(-1), 1491 active_match_index_(-1),
1464 locating_active_rect_(false), 1492 locating_active_rect_(false),
1465 resume_scoping_from_range_(NULL), 1493 resume_scoping_from_range_(NULL),
1466 last_match_count_(-1), 1494 last_match_count_(-1),
1467 total_matchcount_(-1), 1495 total_matchcount_(-1),
1468 frames_scoping_count_(-1), 1496 frames_scoping_count_(-1),
1469 scoping_complete_(false), 1497 scoping_complete_(false),
1470 next_invalidate_after_(0) { 1498 next_invalidate_after_(0) {
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
1816 search_text.substr(0, last_search_string_.length()); 1844 search_text.substr(0, last_search_string_.length());
1817 1845
1818 if (previous_search_prefix == last_search_string_) { 1846 if (previous_search_prefix == last_search_string_) {
1819 return false; // Don't search this frame, it will be fruitless. 1847 return false; // Don't search this frame, it will be fruitless.
1820 } 1848 }
1821 } 1849 }
1822 1850
1823 return true; 1851 return true;
1824 } 1852 }
1825 1853
1854 void WebFrameImpl::ScopeStringMatchesSoon(
1855 int identifier, const WebString& search_text,
1856 const WebFindOptions& options, bool reset) {
1857 deferred_scoping_work_.append(new DeferredScopeStringMatches(
1858 this, identifier, search_text, options, reset));
1859 }
1860
1861 void WebFrameImpl::CallScopeStringMatches(
1862 DeferredScopeStringMatches* caller, int identifier,
1863 const WebString& search_text, const WebFindOptions& options, bool reset) {
1864 deferred_scoping_work_.remove(deferred_scoping_work_.find(caller));
1865
1866 scopeStringMatches(identifier, search_text, options, reset);
1867
1868 // This needs to happen last since search_text is passed by reference.
1869 delete caller;
1870 }
1871
1826 void WebFrameImpl::InvalidateIfNecessary() { 1872 void WebFrameImpl::InvalidateIfNecessary() {
1827 if (last_match_count_ > next_invalidate_after_) { 1873 if (last_match_count_ > next_invalidate_after_) {
1828 // TODO(finnur): (http://b/1088165) Optimize the drawing of the 1874 // TODO(finnur): (http://b/1088165) Optimize the drawing of the
1829 // tickmarks and remove this. This calculation sets a milestone for when 1875 // tickmarks and remove this. This calculation sets a milestone for when
1830 // next to invalidate the scrollbar and the content area. We do this so that 1876 // next to invalidate the scrollbar and the content area. We do this so that
1831 // we don't spend too much time drawing the scrollbar over and over again. 1877 // we don't spend too much time drawing the scrollbar over and over again.
1832 // Basically, up until the first 500 matches there is no throttle. After the 1878 // Basically, up until the first 500 matches there is no throttle. After the
1833 // first 500 matches, we set set the milestone further and further out (750, 1879 // first 500 matches, we set set the milestone further and further out (750,
1834 // 1125, 1688, 2K, 3K). 1880 // 1125, 1688, 2K, 3K).
1835 static const int start_slowing_down_after = 500; 1881 static const int start_slowing_down_after = 500;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1870 1916
1871 SecurityOrigin* security_origin = frame_->document()->securityOrigin(); 1917 SecurityOrigin* security_origin = frame_->document()->securityOrigin();
1872 1918
1873 if (!frame_->redirectScheduler()->locationChangePending()) { 1919 if (!frame_->redirectScheduler()->locationChangePending()) {
1874 frame_->loader()->stopAllLoaders(); 1920 frame_->loader()->stopAllLoaders();
1875 frame_->loader()->begin(frame_->loader()->url(), true, security_origin); 1921 frame_->loader()->begin(frame_->loader()->url(), true, security_origin);
1876 frame_->loader()->write(script_result); 1922 frame_->loader()->write(script_result);
1877 frame_->loader()->end(); 1923 frame_->loader()->end();
1878 } 1924 }
1879 } 1925 }
OLDNEW
« no previous file with comments | « webkit/glue/webframe_impl.h ('k') | webkit/glue/webview_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698