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

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

Issue 6099013: Fix race condition where chrome.tabs.executeScript sometimes wouldn't (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: compile Created 9 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/navigation_state.cc ('k') | chrome/renderer/user_script_idle_scheduler.h » ('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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <cmath> 8 #include <cmath>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 3247 matching lines...) Expand 10 before | Expand all | Expand 10 after
3258 break; 3258 break;
3259 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data. 3259 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
3260 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK); 3260 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
3261 break; 3261 break;
3262 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post. 3262 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
3263 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY); 3263 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
3264 break; 3264 break;
3265 } 3265 }
3266 } 3266 }
3267 3267
3268 state->set_user_script_idle_scheduler( 3268 // If this datasource already has a UserScriptIdleScheduler, reuse that one.
3269 new UserScriptIdleScheduler(this, frame)); 3269 // This is for navigations within a page (didNavigateWithinPage). See
3270 // http://code.google.com/p/chromium/issues/detail?id=64093
3271 NavigationState* old_state = NavigationState::FromDataSource(ds);
3272 if (old_state && old_state->user_script_idle_scheduler()) {
3273 state->swap_user_script_idle_scheduler(old_state);
3274 } else {
3275 state->set_user_script_idle_scheduler(
3276 new UserScriptIdleScheduler(this, frame));
3277 }
3270 ds->setExtraData(state); 3278 ds->setExtraData(state);
3271 } 3279 }
3272 3280
3273 void RenderView::didStartProvisionalLoad(WebFrame* frame) { 3281 void RenderView::didStartProvisionalLoad(WebFrame* frame) {
3274 WebDataSource* ds = frame->provisionalDataSource(); 3282 WebDataSource* ds = frame->provisionalDataSource();
3275 NavigationState* navigation_state = NavigationState::FromDataSource(ds); 3283 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3276 3284
3277 // Update the request time if WebKit has better knowledge of it. 3285 // Update the request time if WebKit has better knowledge of it.
3278 if (navigation_state->request_time().is_null()) { 3286 if (navigation_state->request_time().is_null()) {
3279 double event_time = ds->triggeringEventTime(); 3287 double event_time = ds->triggeringEventTime();
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
3588 navigation_state->user_script_idle_scheduler()->DidFinishLoad(); 3596 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
3589 3597
3590 // Let the password manager know which password forms are actually visible. 3598 // Let the password manager know which password forms are actually visible.
3591 password_autocomplete_manager_->SendPasswordForms(frame, true); 3599 password_autocomplete_manager_->SendPasswordForms(frame, true);
3592 3600
3593 Send(new ViewHostMsg_DidFinishLoad(routing_id_, frame->identifier())); 3601 Send(new ViewHostMsg_DidFinishLoad(routing_id_, frame->identifier()));
3594 } 3602 }
3595 3603
3596 void RenderView::didNavigateWithinPage( 3604 void RenderView::didNavigateWithinPage(
3597 WebFrame* frame, bool is_new_navigation) { 3605 WebFrame* frame, bool is_new_navigation) {
3598 // Determine if the UserScriptIdleScheduler already ran scripts on this page,
3599 // since a new one gets created by didCreateDataSource.
3600 NavigationState* state = NavigationState::FromDataSource(frame->dataSource());
3601 bool idle_scheduler_ran = state->user_script_idle_scheduler()->has_run();
3602
3603 // If this was a reference fragment navigation that we initiated, then we 3606 // If this was a reference fragment navigation that we initiated, then we
3604 // could end up having a non-null pending navigation state. We just need to 3607 // could end up having a non-null pending navigation state. We just need to
3605 // update the ExtraData on the datasource so that others who read the 3608 // update the ExtraData on the datasource so that others who read the
3606 // ExtraData will get the new NavigationState. Similarly, if we did not 3609 // ExtraData will get the new NavigationState. Similarly, if we did not
3607 // initiate this navigation, then we need to take care to reset any pre- 3610 // initiate this navigation, then we need to take care to reset any pre-
3608 // existing navigation state to a content-initiated navigation state. 3611 // existing navigation state to a content-initiated navigation state.
3609 // DidCreateDataSource conveniently takes care of this for us. 3612 // DidCreateDataSource conveniently takes care of this for us.
3610 didCreateDataSource(frame, frame->dataSource()); 3613 didCreateDataSource(frame, frame->dataSource());
3611 3614
3612 NavigationState* new_state = 3615 NavigationState* new_state =
3613 NavigationState::FromDataSource(frame->dataSource()); 3616 NavigationState::FromDataSource(frame->dataSource());
3614 new_state->set_was_within_same_page(true); 3617 new_state->set_was_within_same_page(true);
3615 3618
3616 if (idle_scheduler_ran) {
3617 // Update the new UserScriptIdleScheduler so we don't re-run scripts.
3618 new_state->user_script_idle_scheduler()->set_has_run(true);
3619 }
3620
3621 didCommitProvisionalLoad(frame, is_new_navigation); 3619 didCommitProvisionalLoad(frame, is_new_navigation);
3622 3620
3623 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle()); 3621 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
3624 } 3622 }
3625 3623
3626 void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) { 3624 void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
3627 StartNavStateSyncTimerIfNecessary(); 3625 StartNavStateSyncTimerIfNecessary();
3628 } 3626 }
3629 3627
3630 void RenderView::assignIdentifierToRequest( 3628 void RenderView::assignIdentifierToRequest(
(...skipping 2150 matching lines...) Expand 10 before | Expand all | Expand 10 after
5781 } 5779 }
5782 #endif 5780 #endif
5783 5781
5784 void RenderView::OnJavaScriptStressTestControl(int cmd, int param) { 5782 void RenderView::OnJavaScriptStressTestControl(int cmd, int param) {
5785 if (cmd == kJavaScriptStressTestSetStressRunType) { 5783 if (cmd == kJavaScriptStressTestSetStressRunType) {
5786 v8::Testing::SetStressRunType(static_cast<v8::Testing::StressType>(param)); 5784 v8::Testing::SetStressRunType(static_cast<v8::Testing::StressType>(param));
5787 } else if (cmd == kJavaScriptStressTestPrepareStressRun) { 5785 } else if (cmd == kJavaScriptStressTestPrepareStressRun) {
5788 v8::Testing::PrepareStressRun(param); 5786 v8::Testing::PrepareStressRun(param);
5789 } 5787 }
5790 } 5788 }
OLDNEW
« no previous file with comments | « chrome/renderer/navigation_state.cc ('k') | chrome/renderer/user_script_idle_scheduler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698