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

Side by Side Diff: content/renderer/render_view_impl.cc

Issue 694963003: Revert of Clean up the page state saving mechanism. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
OLDNEW
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/renderer/render_view_impl.h" 5 #include "content/renderer/render_view_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 LAZY_INSTANCE_INITIALIZER; 318 LAZY_INSTANCE_INITIALIZER;
319 319
320 // Time, in seconds, we delay before sending content state changes (such as form 320 // Time, in seconds, we delay before sending content state changes (such as form
321 // state and scroll position) to the browser. We delay sending changes to avoid 321 // state and scroll position) to the browser. We delay sending changes to avoid
322 // spamming the browser. 322 // spamming the browser.
323 // To avoid having tab/session restore require sending a message to get the 323 // To avoid having tab/session restore require sending a message to get the
324 // current content state during tab closing we use a shorter timeout for the 324 // current content state during tab closing we use a shorter timeout for the
325 // foreground renderer. This means there is a small window of time from which 325 // foreground renderer. This means there is a small window of time from which
326 // content state is modified and not sent to session restore, but this is 326 // content state is modified and not sent to session restore, but this is
327 // better than having to wake up all renderers during shutdown. 327 // better than having to wake up all renderers during shutdown.
328 const int kHiddenPageStateSendingDelaySeconds = 5; 328 const int kDelaySecondsForContentStateSyncHidden = 5;
329 const int kPageStateSendingDelaySeconds = 1; 329 const int kDelaySecondsForContentStateSync = 1;
330 330
331 #if defined(OS_ANDROID) 331 #if defined(OS_ANDROID)
332 // Delay between tapping in content and launching the associated android intent. 332 // Delay between tapping in content and launching the associated android intent.
333 // Used to allow users see what has been recognized as content. 333 // Used to allow users see what has been recognized as content.
334 const size_t kContentIntentDelayMilliseconds = 700; 334 const size_t kContentIntentDelayMilliseconds = 700;
335 #endif 335 #endif
336 336
337 static RenderViewImpl* (*g_create_render_view_impl)(RenderViewImplParams*) = 337 static RenderViewImpl* (*g_create_render_view_impl)(RenderViewImplParams*) =
338 NULL; 338 NULL;
339 339
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 642
643 } // namespace 643 } // namespace
644 644
645 RenderViewImpl::RenderViewImpl(RenderViewImplParams* params) 645 RenderViewImpl::RenderViewImpl(RenderViewImplParams* params)
646 : RenderWidget(blink::WebPopupTypeNone, 646 : RenderWidget(blink::WebPopupTypeNone,
647 params->screen_info, 647 params->screen_info,
648 params->swapped_out, 648 params->swapped_out,
649 params->hidden, 649 params->hidden,
650 params->never_visible), 650 params->never_visible),
651 webkit_preferences_(params->webkit_prefs), 651 webkit_preferences_(params->webkit_prefs),
652 send_content_state_immediately_(false),
652 enabled_bindings_(0), 653 enabled_bindings_(0),
653 send_preferred_size_changes_(false), 654 send_preferred_size_changes_(false),
654 navigation_gesture_(NavigationGestureUnknown), 655 navigation_gesture_(NavigationGestureUnknown),
655 opened_by_user_gesture_(true), 656 opened_by_user_gesture_(true),
656 opener_suppressed_(false), 657 opener_suppressed_(false),
657 suppress_dialogs_until_swap_out_(false), 658 suppress_dialogs_until_swap_out_(false),
658 page_state_sent_immediately_(false),
659 page_state_dirty_(false),
660 page_id_(-1), 659 page_id_(-1),
661 last_page_id_sent_to_browser_(-1), 660 last_page_id_sent_to_browser_(-1),
662 next_page_id_(params->next_page_id), 661 next_page_id_(params->next_page_id),
663 history_list_offset_(-1), 662 history_list_offset_(-1),
664 history_list_length_(0), 663 history_list_length_(0),
665 frames_in_progress_(0), 664 frames_in_progress_(0),
666 target_url_status_(TARGET_NONE), 665 target_url_status_(TARGET_NONE),
667 uses_temporary_zoom_level_(false), 666 uses_temporary_zoom_level_(false),
668 #if defined(OS_ANDROID) 667 #if defined(OS_ANDROID)
669 top_controls_constraints_(cc::BOTH), 668 top_controls_constraints_(cc::BOTH),
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after
1521 return; 1520 return;
1522 if (in_live_resize) 1521 if (in_live_resize)
1523 webview()->willStartLiveResize(); 1522 webview()->willStartLiveResize();
1524 else 1523 else
1525 webview()->willEndLiveResize(); 1524 webview()->willEndLiveResize();
1526 } 1525 }
1527 #endif 1526 #endif
1528 1527
1529 /////////////////////////////////////////////////////////////////////////////// 1528 ///////////////////////////////////////////////////////////////////////////////
1530 1529
1530 // Sends the current history state to the browser so it will be saved before we
1531 // navigate to a new page.
1532 void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) {
1533 // If we have a valid page ID at this point, then it corresponds to the page
1534 // we are navigating away from. Otherwise, this is the first navigation, so
1535 // there is no past session history to record.
1536 if (page_id_ == -1)
1537 return;
1538 SendUpdateState(history_controller_->GetCurrentEntry());
1539 }
1540
1541 void RenderViewImpl::SendUpdateState(HistoryEntry* entry) {
1542 if (!entry)
1543 return;
1544
1545 // Don't send state updates for kSwappedOutURL.
1546 if (entry->root().urlString() == WebString::fromUTF8(kSwappedOutURL))
1547 return;
1548
1549 Send(new ViewHostMsg_UpdateState(
1550 routing_id_, page_id_, HistoryEntryToPageState(entry)));
1551 }
1552
1531 bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) { 1553 bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1532 // Before WebKit asks us to show an alert (etc.), it takes care of doing the 1554 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1533 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog 1555 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1534 // it is particularly important that we do not call willEnterModalLoop as 1556 // it is particularly important that we do not call willEnterModalLoop as
1535 // that would defer resource loads for the dialog itself. 1557 // that would defer resource loads for the dialog itself.
1536 if (RenderThreadImpl::current()) // Will be NULL during unit tests. 1558 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1537 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop(); 1559 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
1538 1560
1539 message->EnableMessagePumping(); // Runs a nested message loop. 1561 message->EnableMessagePumping(); // Runs a nested message loop.
1540 return Send(message); 1562 return Send(message);
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
1870 } 1892 }
1871 } 1893 }
1872 1894
1873 gfx::RectF RenderViewImpl::ClientRectToPhysicalWindowRect( 1895 gfx::RectF RenderViewImpl::ClientRectToPhysicalWindowRect(
1874 const gfx::RectF& rect) const { 1896 const gfx::RectF& rect) const {
1875 gfx::RectF window_rect = rect; 1897 gfx::RectF window_rect = rect;
1876 window_rect.Scale(device_scale_factor_ * webview()->pageScaleFactor()); 1898 window_rect.Scale(device_scale_factor_ * webview()->pageScaleFactor());
1877 return window_rect; 1899 return window_rect;
1878 } 1900 }
1879 1901
1880 void RenderViewImpl::MarkPageStateAsDirty() { 1902 void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
1881 // No need to send state if no page has committed yet. 1903 // No need to update state if no page has committed yet.
1882 if (page_id_ == -1) 1904 if (page_id_ == -1)
1883 return; 1905 return;
1884 1906
1885 page_state_dirty_ = true;
1886
1887 int delay; 1907 int delay;
1888 if (page_state_sent_immediately_) 1908 if (send_content_state_immediately_)
1889 delay = 0; 1909 delay = 0;
1890 else if (is_hidden()) 1910 else if (is_hidden())
1891 delay = kHiddenPageStateSendingDelaySeconds; 1911 delay = kDelaySecondsForContentStateSyncHidden;
1892 else 1912 else
1893 delay = kPageStateSendingDelaySeconds; 1913 delay = kDelaySecondsForContentStateSync;
1894 1914
1895 if (page_state_timer_.IsRunning()) { 1915 if (nav_state_sync_timer_.IsRunning()) {
1896 // The timer is already running. If the delay of the timer maches the amount 1916 // The timer is already running. If the delay of the timer maches the amount
1897 // we want to delay by, then return. Otherwise stop the timer so that it 1917 // we want to delay by, then return. Otherwise stop the timer so that it
1898 // gets started with the right delay. 1918 // gets started with the right delay.
1899 if (page_state_timer_.GetCurrentDelay().InSeconds() == delay) 1919 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1900 return; 1920 return;
1901 page_state_timer_.Stop(); 1921 nav_state_sync_timer_.Stop();
1902 } 1922 }
1903 1923
1904 page_state_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this, 1924 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
1905 &RenderViewImpl::FlushPageState); 1925 &RenderViewImpl::SyncNavigationState);
1906 }
1907
1908 void RenderViewImpl::FlushPageState() {
1909 if (!page_state_dirty_ || page_id_ == -1 || !webview())
1910 return;
1911
1912 HistoryEntry* entry = history_controller_->GetCurrentEntry();
1913 if (!entry)
1914 return;
1915
1916 // Don't send state updates for kSwappedOutURL.
1917 if (entry->root().urlString() == WebString::fromUTF8(kSwappedOutURL))
1918 return;
1919
1920 Send(new ViewHostMsg_UpdateState(
1921 routing_id_, page_id_, HistoryEntryToPageState(entry)));
1922
1923 page_state_dirty_ = false;
1924 } 1926 }
1925 1927
1926 void RenderViewImpl::setMouseOverURL(const WebURL& url) { 1928 void RenderViewImpl::setMouseOverURL(const WebURL& url) {
1927 mouse_over_url_ = GURL(url); 1929 mouse_over_url_ = GURL(url);
1928 UpdateTargetURL(mouse_over_url_, focus_url_); 1930 UpdateTargetURL(mouse_over_url_, focus_url_);
1929 } 1931 }
1930 1932
1931 void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) { 1933 void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
1932 focus_url_ = GURL(url); 1934 focus_url_ = GURL(url);
1933 UpdateTargetURL(focus_url_, mouse_over_url_); 1935 UpdateTargetURL(focus_url_, mouse_over_url_);
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
2399 for (size_t i = 0; i < icon_urls.size(); i++) { 2401 for (size_t i = 0; i < icon_urls.size(); i++) {
2400 std::vector<gfx::Size> sizes; 2402 std::vector<gfx::Size> sizes;
2401 ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes); 2403 ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes);
2402 urls.push_back(FaviconURL( 2404 urls.push_back(FaviconURL(
2403 icon_urls[i].iconURL(), ToFaviconType(icon_urls[i].iconType()), sizes)); 2405 icon_urls[i].iconURL(), ToFaviconType(icon_urls[i].iconType()), sizes));
2404 } 2406 }
2405 SendUpdateFaviconURL(urls); 2407 SendUpdateFaviconURL(urls);
2406 } 2408 }
2407 2409
2408 void RenderViewImpl::didUpdateCurrentHistoryItem(WebLocalFrame* frame) { 2410 void RenderViewImpl::didUpdateCurrentHistoryItem(WebLocalFrame* frame) {
2409 MarkPageStateAsDirty(); 2411 StartNavStateSyncTimerIfNecessary();
2410 } 2412 }
2411 2413
2412 void RenderViewImpl::CheckPreferredSize() { 2414 void RenderViewImpl::CheckPreferredSize() {
2413 // We don't always want to send the change messages over IPC, only if we've 2415 // We don't always want to send the change messages over IPC, only if we've
2414 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| 2416 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2415 // message. 2417 // message.
2416 if (!send_preferred_size_changes_ || !webview()) 2418 if (!send_preferred_size_changes_ || !webview())
2417 return; 2419 return;
2418 2420
2419 gfx::Size size = webview()->contentsPreferredMinimumSize(); 2421 gfx::Size size = webview()->contentsPreferredMinimumSize();
(...skipping 12 matching lines...) Expand all
2432 preferred_size_)); 2434 preferred_size_));
2433 } 2435 }
2434 2436
2435 BrowserPluginManager* RenderViewImpl::GetBrowserPluginManager() { 2437 BrowserPluginManager* RenderViewImpl::GetBrowserPluginManager() {
2436 if (!browser_plugin_manager_.get()) 2438 if (!browser_plugin_manager_.get())
2437 browser_plugin_manager_ = BrowserPluginManager::Create(this); 2439 browser_plugin_manager_ = BrowserPluginManager::Create(this);
2438 return browser_plugin_manager_.get(); 2440 return browser_plugin_manager_.get();
2439 } 2441 }
2440 2442
2441 void RenderViewImpl::didChangeScrollOffset(WebLocalFrame* frame) { 2443 void RenderViewImpl::didChangeScrollOffset(WebLocalFrame* frame) {
2442 MarkPageStateAsDirty(); 2444 StartNavStateSyncTimerIfNecessary();
2443 2445
2444 FOR_EACH_OBSERVER( 2446 FOR_EACH_OBSERVER(
2445 RenderViewObserver, observers_, DidChangeScrollOffset(frame)); 2447 RenderViewObserver, observers_, DidChangeScrollOffset(frame));
2446 } 2448 }
2447 2449
2448 void RenderViewImpl::SendFindReply(int request_id, 2450 void RenderViewImpl::SendFindReply(int request_id,
2449 int match_count, 2451 int match_count,
2450 int ordinal, 2452 int ordinal,
2451 const WebRect& selection_rect, 2453 const WebRect& selection_rect,
2452 bool final_status_update) { 2454 bool final_status_update) {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
2556 bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const { 2558 bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
2557 return (!send_preferred_size_changes_ || 2559 return (!send_preferred_size_changes_ ||
2558 (disable_scrollbars_size_limit_.width() <= width || 2560 (disable_scrollbars_size_limit_.width() <= width ||
2559 disable_scrollbars_size_limit_.height() <= height)); 2561 disable_scrollbars_size_limit_.height() <= height));
2560 } 2562 }
2561 2563
2562 int RenderViewImpl::GetEnabledBindings() const { 2564 int RenderViewImpl::GetEnabledBindings() const {
2563 return enabled_bindings_; 2565 return enabled_bindings_;
2564 } 2566 }
2565 2567
2566 bool RenderViewImpl::IsPageStateSentImmediately() const { 2568 bool RenderViewImpl::GetContentStateImmediately() const {
2567 return page_state_sent_immediately_; 2569 return send_content_state_immediately_;
2568 } 2570 }
2569 2571
2570 blink::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const { 2572 blink::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
2571 return visibilityState(); 2573 return visibilityState();
2572 } 2574 }
2573 2575
2574 void RenderViewImpl::DidStartLoading() { 2576 void RenderViewImpl::DidStartLoading() {
2575 main_render_frame_->didStartLoading(true); 2577 main_render_frame_->didStartLoading(true);
2576 } 2578 }
2577 2579
2578 void RenderViewImpl::DidStopLoading() { 2580 void RenderViewImpl::DidStopLoading() {
2579 main_render_frame_->didStopLoading(); 2581 main_render_frame_->didStopLoading();
2580 } 2582 }
2581 2583
2582 void RenderViewImpl::ForcePageStateFlushForTesting() { 2584 void RenderViewImpl::SyncNavigationState() {
2583 FlushPageState(); 2585 if (!webview())
2586 return;
2587 SendUpdateState(history_controller_->GetCurrentEntry());
2584 } 2588 }
2585 2589
2586 blink::WebPlugin* RenderViewImpl::GetWebPluginForFind() { 2590 blink::WebPlugin* RenderViewImpl::GetWebPluginForFind() {
2587 if (!webview()) 2591 if (!webview())
2588 return NULL; 2592 return NULL;
2589 2593
2590 WebFrame* main_frame = webview()->mainFrame(); 2594 WebFrame* main_frame = webview()->mainFrame();
2591 if (main_frame->isWebLocalFrame() && 2595 if (main_frame->isWebLocalFrame() &&
2592 main_frame->document().isPluginDocument()) 2596 main_frame->document().isPluginDocument())
2593 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin(); 2597 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
(...skipping 1616 matching lines...) Expand 10 before | Expand all | Expand 10 after
4210 std::vector<gfx::Size> sizes; 4214 std::vector<gfx::Size> sizes;
4211 ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes); 4215 ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes);
4212 if (!url.isEmpty()) 4216 if (!url.isEmpty())
4213 urls.push_back( 4217 urls.push_back(
4214 FaviconURL(url, ToFaviconType(icon_urls[i].iconType()), sizes)); 4218 FaviconURL(url, ToFaviconType(icon_urls[i].iconType()), sizes));
4215 } 4219 }
4216 SendUpdateFaviconURL(urls); 4220 SendUpdateFaviconURL(urls);
4217 } 4221 }
4218 4222
4219 } // namespace content 4223 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_view_impl.h ('k') | content/shell/renderer/layout_test/webkit_test_runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698