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

Side by Side Diff: chrome/browser/extensions/api/web_navigation/web_navigation_api.cc

Issue 10801011: When simulating a navigation via TestRenderViewHost, first start a provisional load before committin (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 8 years, 5 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
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 // Implements the Chrome Extensions WebNavigation API. 5 // Implements the Chrome Extensions WebNavigation API.
6 6
7 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" 7 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h"
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta nts.h" 10 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta nts.h"
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 pending_web_contents_.erase(i++); 229 pending_web_contents_.erase(i++);
230 else 230 else
231 ++i; 231 ++i;
232 } 232 }
233 } 233 }
234 234
235 // WebNavigationTabObserver ------------------------------------------ 235 // WebNavigationTabObserver ------------------------------------------
236 236
237 WebNavigationTabObserver::WebNavigationTabObserver( 237 WebNavigationTabObserver::WebNavigationTabObserver(
238 content::WebContents* web_contents) 238 content::WebContents* web_contents)
239 : WebContentsObserver(web_contents) { 239 : WebContentsObserver(web_contents),
240 render_view_host_(NULL),
241 pending_render_view_host_(NULL) {
240 g_tab_observer.Get().insert(TabObserverMap::value_type(web_contents, this)); 242 g_tab_observer.Get().insert(TabObserverMap::value_type(web_contents, this));
241 registrar_.Add(this, 243 registrar_.Add(this,
242 content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, 244 content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
243 content::Source<content::WebContents>(web_contents)); 245 content::Source<content::WebContents>(web_contents));
244 } 246 }
245 247
246 WebNavigationTabObserver::~WebNavigationTabObserver() {} 248 WebNavigationTabObserver::~WebNavigationTabObserver() {}
247 249
248 // static 250 // static
249 WebNavigationTabObserver* WebNavigationTabObserver::Get( 251 WebNavigationTabObserver* WebNavigationTabObserver::Get(
(...skipping 26 matching lines...) Expand all
276 NOTREACHED(); 278 NOTREACHED();
277 } 279 }
278 } 280 }
279 281
280 void WebNavigationTabObserver::DidStartProvisionalLoadForFrame( 282 void WebNavigationTabObserver::DidStartProvisionalLoadForFrame(
281 int64 frame_id, 283 int64 frame_id,
282 bool is_main_frame, 284 bool is_main_frame,
283 const GURL& validated_url, 285 const GURL& validated_url,
284 bool is_error_page, 286 bool is_error_page,
285 content::RenderViewHost* render_view_host) { 287 content::RenderViewHost* render_view_host) {
288 if (render_view_host == pending_render_view_host_) {
289 DCHECK(is_main_frame);
290 // Suppress incorrect duplicate navigation signals triggered by the
291 // TransfernavigationResourceThrottle. http://crbug.com/137219
292 return;
293 }
294
295 if (render_view_host_ == NULL) {
Charlie Reis 2012/07/18 17:21:18 nit: if (!render_view_host_) {
296 render_view_host_ = render_view_host;
297 } else if (render_view_host != render_view_host_) {
298 DCHECK(is_main_frame);
299 DCHECK(!pending_render_view_host_);
Charlie Reis 2012/07/18 17:21:18 Are you sure DidCommit or DidFail is always going
jochen (gone - plz use gerrit) 2012/07/18 18:03:40 No, I'm not sure. However, wouldn't that mean tha
Charlie Reis 2012/07/18 18:51:34 Yes, I don't see why messages couldn't come in fro
300 pending_render_view_host_ = render_view_host;
301 }
302
286 // Ignore navigations of sub frames, if the main frame isn't committed yet. 303 // Ignore navigations of sub frames, if the main frame isn't committed yet.
287 // This might happen if a sub frame triggers a navigation for both the main 304 // This might happen if a sub frame triggers a navigation for both the main
288 // frame and itself. Since the sub frame is about to be deleted, and there's 305 // frame and itself. Since the sub frame is about to be deleted, and there's
289 // no way for an extension to tell that these navigations belong to an old 306 // no way for an extension to tell that these navigations belong to an old
290 // frame, we just suppress the events here. 307 // frame, we just suppress the events here.
291 int64 main_frame_id = navigation_state_.GetMainFrameID(); 308 int64 main_frame_id = navigation_state_.GetMainFrameID();
292 if (!is_main_frame && 309 if (!is_main_frame &&
293 !navigation_state_.GetNavigationCommitted(main_frame_id)) { 310 !navigation_state_.GetNavigationCommitted(main_frame_id)) {
294 return; 311 return;
295 } 312 }
296 313
297 navigation_state_.TrackFrame(frame_id, 314 navigation_state_.TrackFrame(frame_id,
298 validated_url, 315 validated_url,
299 is_main_frame, 316 is_main_frame,
300 is_error_page); 317 is_error_page);
301 if (!navigation_state_.CanSendEvents(frame_id)) 318 if (!navigation_state_.CanSendEvents(frame_id))
302 return; 319 return;
303 helpers::DispatchOnBeforeNavigate( 320 helpers::DispatchOnBeforeNavigate(
304 web_contents(), frame_id, is_main_frame, validated_url); 321 web_contents(), frame_id, is_main_frame, validated_url);
305 } 322 }
306 323
307 void WebNavigationTabObserver::DidCommitProvisionalLoadForFrame( 324 void WebNavigationTabObserver::DidCommitProvisionalLoadForFrame(
308 int64 frame_id, 325 int64 frame_id,
309 bool is_main_frame, 326 bool is_main_frame,
310 const GURL& url, 327 const GURL& url,
311 content::PageTransition transition_type, 328 content::PageTransition transition_type,
312 content::RenderViewHost* render_view_host) { 329 content::RenderViewHost* render_view_host) {
330 DCHECK(render_view_host == render_view_host_ ||
331 (render_view_host == pending_render_view_host_ && is_main_frame));
332 render_view_host_ = render_view_host;
333 pending_render_view_host_ = NULL;
334
313 if (!navigation_state_.CanSendEvents(frame_id)) 335 if (!navigation_state_.CanSendEvents(frame_id))
314 return; 336 return;
315 337
316 bool is_reference_fragment_navigation = 338 bool is_reference_fragment_navigation =
317 IsReferenceFragmentNavigation(frame_id, url); 339 IsReferenceFragmentNavigation(frame_id, url);
318 bool is_history_navigation = 340 bool is_history_navigation =
319 navigation_state_.GetNavigationCommitted(frame_id); 341 navigation_state_.GetNavigationCommitted(frame_id);
320 342
321 // Update the URL as it might have changed. 343 // Update the URL as it might have changed.
322 navigation_state_.UpdateFrame(frame_id, url); 344 navigation_state_.UpdateFrame(frame_id, url);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 } 380 }
359 } 381 }
360 382
361 void WebNavigationTabObserver::DidFailProvisionalLoad( 383 void WebNavigationTabObserver::DidFailProvisionalLoad(
362 int64 frame_id, 384 int64 frame_id,
363 bool is_main_frame, 385 bool is_main_frame,
364 const GURL& validated_url, 386 const GURL& validated_url,
365 int error_code, 387 int error_code,
366 const string16& error_description, 388 const string16& error_description,
367 content::RenderViewHost* render_view_host) { 389 content::RenderViewHost* render_view_host) {
390 DCHECK(render_view_host == render_view_host_ ||
391 (render_view_host == pending_render_view_host_ && is_main_frame));
392 if (render_view_host == pending_render_view_host_)
393 pending_render_view_host_ = NULL;
394
368 if (!navigation_state_.CanSendEvents(frame_id)) 395 if (!navigation_state_.CanSendEvents(frame_id))
369 return; 396 return;
370 navigation_state_.SetErrorOccurredInFrame(frame_id); 397 navigation_state_.SetErrorOccurredInFrame(frame_id);
371 helpers::DispatchOnErrorOccurred( 398 helpers::DispatchOnErrorOccurred(
372 web_contents(), validated_url, frame_id, is_main_frame, error_code); 399 web_contents(), validated_url, frame_id, is_main_frame, error_code);
373 } 400 }
374 401
375 void WebNavigationTabObserver::DocumentLoadedInFrame( 402 void WebNavigationTabObserver::DocumentLoadedInFrame(
376 int64 frame_id) { 403 int64 frame_id) {
377 if (!navigation_state_.CanSendEvents(frame_id)) 404 if (!navigation_state_.CanSendEvents(frame_id))
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 frame->frame_id = helpers::GetFrameId( 579 frame->frame_id = helpers::GetFrameId(
553 navigation_state.IsMainFrame(frame_id), frame_id); 580 navigation_state.IsMainFrame(frame_id), frame_id);
554 frame->error_occurred = navigation_state.GetErrorOccurredInFrame(frame_id); 581 frame->error_occurred = navigation_state.GetErrorOccurredInFrame(frame_id);
555 result_list.push_back(frame); 582 result_list.push_back(frame);
556 } 583 }
557 results_ = GetAllFrames::Results::Create(result_list); 584 results_ = GetAllFrames::Results::Create(result_list);
558 return true; 585 return true;
559 } 586 }
560 587
561 } // namespace extensions 588 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698