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

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

Issue 689163002: 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 kDelaySecondsForContentStateSyncHidden = 5; 328 const int kHiddenPageStateSendingDelaySeconds = 5;
329 const int kDelaySecondsForContentStateSync = 1; 329 const int kPageStateSendingDelaySeconds = 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),
653 enabled_bindings_(0), 652 enabled_bindings_(0),
654 send_preferred_size_changes_(false), 653 send_preferred_size_changes_(false),
655 navigation_gesture_(NavigationGestureUnknown), 654 navigation_gesture_(NavigationGestureUnknown),
656 opened_by_user_gesture_(true), 655 opened_by_user_gesture_(true),
657 opener_suppressed_(false), 656 opener_suppressed_(false),
658 suppress_dialogs_until_swap_out_(false), 657 suppress_dialogs_until_swap_out_(false),
658 page_state_sent_immediately_(false),
659 page_state_dirty_(false),
659 page_id_(-1), 660 page_id_(-1),
660 last_page_id_sent_to_browser_(-1), 661 last_page_id_sent_to_browser_(-1),
661 next_page_id_(params->next_page_id), 662 next_page_id_(params->next_page_id),
662 history_list_offset_(-1), 663 history_list_offset_(-1),
663 history_list_length_(0), 664 history_list_length_(0),
664 frames_in_progress_(0), 665 frames_in_progress_(0),
665 target_url_status_(TARGET_NONE), 666 target_url_status_(TARGET_NONE),
666 uses_temporary_zoom_level_(false), 667 uses_temporary_zoom_level_(false),
667 #if defined(OS_ANDROID) 668 #if defined(OS_ANDROID)
668 top_controls_constraints_(cc::BOTH), 669 top_controls_constraints_(cc::BOTH),
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after
1520 return; 1521 return;
1521 if (in_live_resize) 1522 if (in_live_resize)
1522 webview()->willStartLiveResize(); 1523 webview()->willStartLiveResize();
1523 else 1524 else
1524 webview()->willEndLiveResize(); 1525 webview()->willEndLiveResize();
1525 } 1526 }
1526 #endif 1527 #endif
1527 1528
1528 /////////////////////////////////////////////////////////////////////////////// 1529 ///////////////////////////////////////////////////////////////////////////////
1529 1530
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
1553 bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) { 1531 bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1554 // Before WebKit asks us to show an alert (etc.), it takes care of doing the 1532 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1555 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog 1533 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1556 // it is particularly important that we do not call willEnterModalLoop as 1534 // it is particularly important that we do not call willEnterModalLoop as
1557 // that would defer resource loads for the dialog itself. 1535 // that would defer resource loads for the dialog itself.
1558 if (RenderThreadImpl::current()) // Will be NULL during unit tests. 1536 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1559 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop(); 1537 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
1560 1538
1561 message->EnableMessagePumping(); // Runs a nested message loop. 1539 message->EnableMessagePumping(); // Runs a nested message loop.
1562 return Send(message); 1540 return Send(message);
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
1892 } 1870 }
1893 } 1871 }
1894 1872
1895 gfx::RectF RenderViewImpl::ClientRectToPhysicalWindowRect( 1873 gfx::RectF RenderViewImpl::ClientRectToPhysicalWindowRect(
1896 const gfx::RectF& rect) const { 1874 const gfx::RectF& rect) const {
1897 gfx::RectF window_rect = rect; 1875 gfx::RectF window_rect = rect;
1898 window_rect.Scale(device_scale_factor_ * webview()->pageScaleFactor()); 1876 window_rect.Scale(device_scale_factor_ * webview()->pageScaleFactor());
1899 return window_rect; 1877 return window_rect;
1900 } 1878 }
1901 1879
1902 void RenderViewImpl::StartNavStateSyncTimerIfNecessary() { 1880 void RenderViewImpl::MarkPageStateAsDirty() {
1903 // No need to update state if no page has committed yet. 1881 // No need to send state if no page has committed yet.
1904 if (page_id_ == -1) 1882 if (page_id_ == -1)
1905 return; 1883 return;
1906 1884
1885 page_state_dirty_ = true;
1886
1907 int delay; 1887 int delay;
1908 if (send_content_state_immediately_) 1888 if (page_state_sent_immediately_)
1909 delay = 0; 1889 delay = 0;
1910 else if (is_hidden()) 1890 else if (is_hidden())
1911 delay = kDelaySecondsForContentStateSyncHidden; 1891 delay = kHiddenPageStateSendingDelaySeconds;
1912 else 1892 else
1913 delay = kDelaySecondsForContentStateSync; 1893 delay = kPageStateSendingDelaySeconds;
1914 1894
1915 if (nav_state_sync_timer_.IsRunning()) { 1895 if (page_state_timer_.IsRunning()) {
1916 // The timer is already running. If the delay of the timer maches the amount 1896 // The timer is already running. If the delay of the timer maches the amount
1917 // we want to delay by, then return. Otherwise stop the timer so that it 1897 // we want to delay by, then return. Otherwise stop the timer so that it
1918 // gets started with the right delay. 1898 // gets started with the right delay.
1919 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay) 1899 if (page_state_timer_.GetCurrentDelay().InSeconds() == delay)
1920 return; 1900 return;
1921 nav_state_sync_timer_.Stop(); 1901 page_state_timer_.Stop();
1922 } 1902 }
1923 1903
1924 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this, 1904 page_state_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
1925 &RenderViewImpl::SyncNavigationState); 1905 &RenderViewImpl::FlushPageState);
1906 }
1907
1908 void RenderViewImpl::FlushPageState() {
1909 if (!page_state_dirty_ || page_id_ == -1 || !webview())
Charlie Reis 2014/10/31 21:38:49 Just want to verify that I understand the implicat
Avi (use Gerrit) 2014/10/31 22:11:12 Exactly. This is an intentional change, where we d
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;
1926 } 1924 }
1927 1925
1928 void RenderViewImpl::setMouseOverURL(const WebURL& url) { 1926 void RenderViewImpl::setMouseOverURL(const WebURL& url) {
1929 mouse_over_url_ = GURL(url); 1927 mouse_over_url_ = GURL(url);
1930 UpdateTargetURL(mouse_over_url_, focus_url_); 1928 UpdateTargetURL(mouse_over_url_, focus_url_);
1931 } 1929 }
1932 1930
1933 void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) { 1931 void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
1934 focus_url_ = GURL(url); 1932 focus_url_ = GURL(url);
1935 UpdateTargetURL(focus_url_, mouse_over_url_); 1933 UpdateTargetURL(focus_url_, mouse_over_url_);
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
2401 for (size_t i = 0; i < icon_urls.size(); i++) { 2399 for (size_t i = 0; i < icon_urls.size(); i++) {
2402 std::vector<gfx::Size> sizes; 2400 std::vector<gfx::Size> sizes;
2403 ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes); 2401 ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes);
2404 urls.push_back(FaviconURL( 2402 urls.push_back(FaviconURL(
2405 icon_urls[i].iconURL(), ToFaviconType(icon_urls[i].iconType()), sizes)); 2403 icon_urls[i].iconURL(), ToFaviconType(icon_urls[i].iconType()), sizes));
2406 } 2404 }
2407 SendUpdateFaviconURL(urls); 2405 SendUpdateFaviconURL(urls);
2408 } 2406 }
2409 2407
2410 void RenderViewImpl::didUpdateCurrentHistoryItem(WebLocalFrame* frame) { 2408 void RenderViewImpl::didUpdateCurrentHistoryItem(WebLocalFrame* frame) {
2411 StartNavStateSyncTimerIfNecessary(); 2409 MarkPageStateAsDirty();
2412 } 2410 }
2413 2411
2414 void RenderViewImpl::CheckPreferredSize() { 2412 void RenderViewImpl::CheckPreferredSize() {
2415 // We don't always want to send the change messages over IPC, only if we've 2413 // We don't always want to send the change messages over IPC, only if we've
2416 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| 2414 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2417 // message. 2415 // message.
2418 if (!send_preferred_size_changes_ || !webview()) 2416 if (!send_preferred_size_changes_ || !webview())
2419 return; 2417 return;
2420 2418
2421 gfx::Size size = webview()->contentsPreferredMinimumSize(); 2419 gfx::Size size = webview()->contentsPreferredMinimumSize();
(...skipping 12 matching lines...) Expand all
2434 preferred_size_)); 2432 preferred_size_));
2435 } 2433 }
2436 2434
2437 BrowserPluginManager* RenderViewImpl::GetBrowserPluginManager() { 2435 BrowserPluginManager* RenderViewImpl::GetBrowserPluginManager() {
2438 if (!browser_plugin_manager_.get()) 2436 if (!browser_plugin_manager_.get())
2439 browser_plugin_manager_ = BrowserPluginManager::Create(this); 2437 browser_plugin_manager_ = BrowserPluginManager::Create(this);
2440 return browser_plugin_manager_.get(); 2438 return browser_plugin_manager_.get();
2441 } 2439 }
2442 2440
2443 void RenderViewImpl::didChangeScrollOffset(WebLocalFrame* frame) { 2441 void RenderViewImpl::didChangeScrollOffset(WebLocalFrame* frame) {
2444 StartNavStateSyncTimerIfNecessary(); 2442 MarkPageStateAsDirty();
2445 2443
2446 FOR_EACH_OBSERVER( 2444 FOR_EACH_OBSERVER(
2447 RenderViewObserver, observers_, DidChangeScrollOffset(frame)); 2445 RenderViewObserver, observers_, DidChangeScrollOffset(frame));
2448 } 2446 }
2449 2447
2450 void RenderViewImpl::SendFindReply(int request_id, 2448 void RenderViewImpl::SendFindReply(int request_id,
2451 int match_count, 2449 int match_count,
2452 int ordinal, 2450 int ordinal,
2453 const WebRect& selection_rect, 2451 const WebRect& selection_rect,
2454 bool final_status_update) { 2452 bool final_status_update) {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
2558 bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const { 2556 bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
2559 return (!send_preferred_size_changes_ || 2557 return (!send_preferred_size_changes_ ||
2560 (disable_scrollbars_size_limit_.width() <= width || 2558 (disable_scrollbars_size_limit_.width() <= width ||
2561 disable_scrollbars_size_limit_.height() <= height)); 2559 disable_scrollbars_size_limit_.height() <= height));
2562 } 2560 }
2563 2561
2564 int RenderViewImpl::GetEnabledBindings() const { 2562 int RenderViewImpl::GetEnabledBindings() const {
2565 return enabled_bindings_; 2563 return enabled_bindings_;
2566 } 2564 }
2567 2565
2568 bool RenderViewImpl::GetContentStateImmediately() const { 2566 bool RenderViewImpl::GetPageStateSentImmediately() const {
2569 return send_content_state_immediately_; 2567 return page_state_sent_immediately_;
2570 } 2568 }
2571 2569
2572 blink::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const { 2570 blink::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
2573 return visibilityState(); 2571 return visibilityState();
2574 } 2572 }
2575 2573
2576 void RenderViewImpl::DidStartLoading() { 2574 void RenderViewImpl::DidStartLoading() {
2577 main_render_frame_->didStartLoading(true); 2575 main_render_frame_->didStartLoading(true);
2578 } 2576 }
2579 2577
2580 void RenderViewImpl::DidStopLoading() { 2578 void RenderViewImpl::DidStopLoading() {
2581 main_render_frame_->didStopLoading(); 2579 main_render_frame_->didStopLoading();
2582 } 2580 }
2583 2581
2584 void RenderViewImpl::SyncNavigationState() { 2582 void RenderViewImpl::ForcePageStateFlushForTesting() {
2585 if (!webview()) 2583 FlushPageState();
2586 return;
2587 SendUpdateState(history_controller_->GetCurrentEntry());
2588 } 2584 }
2589 2585
2590 blink::WebPlugin* RenderViewImpl::GetWebPluginForFind() { 2586 blink::WebPlugin* RenderViewImpl::GetWebPluginForFind() {
2591 if (!webview()) 2587 if (!webview())
2592 return NULL; 2588 return NULL;
2593 2589
2594 WebFrame* main_frame = webview()->mainFrame(); 2590 WebFrame* main_frame = webview()->mainFrame();
2595 if (main_frame->isWebLocalFrame() && 2591 if (main_frame->isWebLocalFrame() &&
2596 main_frame->document().isPluginDocument()) 2592 main_frame->document().isPluginDocument())
2597 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin(); 2593 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
(...skipping 1616 matching lines...) Expand 10 before | Expand all | Expand 10 after
4214 std::vector<gfx::Size> sizes; 4210 std::vector<gfx::Size> sizes;
4215 ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes); 4211 ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes);
4216 if (!url.isEmpty()) 4212 if (!url.isEmpty())
4217 urls.push_back( 4213 urls.push_back(
4218 FaviconURL(url, ToFaviconType(icon_urls[i].iconType()), sizes)); 4214 FaviconURL(url, ToFaviconType(icon_urls[i].iconType()), sizes));
4219 } 4215 }
4220 SendUpdateFaviconURL(urls); 4216 SendUpdateFaviconURL(urls);
4221 } 4217 }
4222 4218
4223 } // namespace content 4219 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698