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

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

Issue 10815051: Send the correct process ID with webNavigation events (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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"
11 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_helper s.h" 11 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_helper s.h"
12 #include "chrome/browser/extensions/extension_tab_util.h" 12 #include "chrome/browser/extensions/extension_tab_util.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/tab_contents/retargeting_details.h" 14 #include "chrome/browser/tab_contents/retargeting_details.h"
15 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_list.h" 16 #include "chrome/browser/ui/browser_list.h"
17 #include "chrome/browser/ui/tab_contents/tab_contents.h" 17 #include "chrome/browser/ui/tab_contents/tab_contents.h"
18 #include "chrome/browser/view_type_utils.h" 18 #include "chrome/browser/view_type_utils.h"
19 #include "chrome/common/chrome_notification_types.h" 19 #include "chrome/common/chrome_notification_types.h"
20 #include "chrome/common/extensions/api/web_navigation.h" 20 #include "chrome/common/extensions/api/web_navigation.h"
21 #include "content/public/browser/resource_request_details.h" 21 #include "content/public/browser/resource_request_details.h"
22 #include "content/public/browser/navigation_details.h" 22 #include "content/public/browser/navigation_details.h"
23 #include "content/public/browser/notification_service.h" 23 #include "content/public/browser/notification_service.h"
24 #include "content/public/browser/notification_types.h" 24 #include "content/public/browser/notification_types.h"
25 #include "content/public/browser/render_process_host.h"
25 #include "content/public/browser/render_view_host.h" 26 #include "content/public/browser/render_view_host.h"
26 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
27 #include "net/base/net_errors.h" 28 #include "net/base/net_errors.h"
28 29
29 namespace GetFrame = extensions::api::web_navigation::GetFrame; 30 namespace GetFrame = extensions::api::web_navigation::GetFrame;
30 namespace GetAllFrames = extensions::api::web_navigation::GetAllFrames; 31 namespace GetAllFrames = extensions::api::web_navigation::GetAllFrames;
31 32
32 namespace extensions { 33 namespace extensions {
33 34
34 namespace helpers = web_navigation_api_helpers; 35 namespace helpers = web_navigation_api_helpers;
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 bool is_main_frame, 296 bool is_main_frame,
296 const GURL& validated_url, 297 const GURL& validated_url,
297 bool is_error_page, 298 bool is_error_page,
298 content::RenderViewHost* render_view_host) { 299 content::RenderViewHost* render_view_host) {
299 if (!render_view_host_) 300 if (!render_view_host_)
300 render_view_host_ = render_view_host; 301 render_view_host_ = render_view_host;
301 if (render_view_host != render_view_host_ && 302 if (render_view_host != render_view_host_ &&
302 render_view_host != pending_render_view_host_) 303 render_view_host != pending_render_view_host_)
303 return; 304 return;
304 305
305 // TODO(jochen): Remove this hack once we properly include the process ID in
306 // the events.
307 // Ignore navigations of sub frames, if the main frame isn't committed yet.
308 // This might happen if a sub frame triggers a navigation for both the main
309 // frame and itself. Since the sub frame is about to be deleted, and there's
310 // no way for an extension to tell that these navigations belong to an old
311 // frame, we just suppress the events here.
312 int64 main_frame_id = navigation_state_.GetMainFrameID();
313 if (!is_main_frame &&
314 !navigation_state_.GetNavigationCommitted(main_frame_id)) {
315 return;
316 }
317
318 navigation_state_.TrackFrame(frame_id, 306 navigation_state_.TrackFrame(frame_id,
319 validated_url, 307 validated_url,
320 is_main_frame, 308 is_main_frame,
321 is_error_page); 309 is_error_page);
322 if (!navigation_state_.CanSendEvents(frame_id)) 310 if (!navigation_state_.CanSendEvents(frame_id))
323 return; 311 return;
324 312
325 helpers::DispatchOnBeforeNavigate( 313 helpers::DispatchOnBeforeNavigate(
326 web_contents(), frame_id, is_main_frame, validated_url); 314 web_contents(), render_view_host->GetProcess()->GetID(), frame_id,
315 is_main_frame, validated_url);
327 } 316 }
328 317
329 void WebNavigationTabObserver::DidCommitProvisionalLoadForFrame( 318 void WebNavigationTabObserver::DidCommitProvisionalLoadForFrame(
330 int64 frame_id, 319 int64 frame_id,
331 bool is_main_frame, 320 bool is_main_frame,
332 const GURL& url, 321 const GURL& url,
333 content::PageTransition transition_type, 322 content::PageTransition transition_type,
334 content::RenderViewHost* render_view_host) { 323 content::RenderViewHost* render_view_host) {
335 if (render_view_host != render_view_host_ && 324 if (render_view_host != render_view_host_ &&
336 render_view_host != pending_render_view_host_) 325 render_view_host != pending_render_view_host_)
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 render_view_host != pending_render_view_host_) 388 render_view_host != pending_render_view_host_)
400 return; 389 return;
401 if (render_view_host == pending_render_view_host_) 390 if (render_view_host == pending_render_view_host_)
402 pending_render_view_host_ = NULL; 391 pending_render_view_host_ = NULL;
403 392
404 if (!navigation_state_.CanSendEvents(frame_id)) 393 if (!navigation_state_.CanSendEvents(frame_id))
405 return; 394 return;
406 395
407 navigation_state_.SetErrorOccurredInFrame(frame_id); 396 navigation_state_.SetErrorOccurredInFrame(frame_id);
408 helpers::DispatchOnErrorOccurred( 397 helpers::DispatchOnErrorOccurred(
409 web_contents(), validated_url, frame_id, is_main_frame, error_code); 398 web_contents(), render_view_host->GetProcess()->GetID(), validated_url,
399 frame_id, is_main_frame, error_code);
410 } 400 }
411 401
412 void WebNavigationTabObserver::DocumentLoadedInFrame( 402 void WebNavigationTabObserver::DocumentLoadedInFrame(
413 int64 frame_id, 403 int64 frame_id,
414 content::RenderViewHost* render_view_host) { 404 content::RenderViewHost* render_view_host) {
415 if (render_view_host != render_view_host_) 405 if (render_view_host != render_view_host_)
416 return; 406 return;
417 if (!navigation_state_.CanSendEvents(frame_id)) 407 if (!navigation_state_.CanSendEvents(frame_id))
418 return; 408 return;
419 helpers::DispatchOnDOMContentLoaded(web_contents(), 409 helpers::DispatchOnDOMContentLoaded(web_contents(),
(...skipping 26 matching lines...) Expand all
446 bool is_main_frame, 436 bool is_main_frame,
447 int error_code, 437 int error_code,
448 const string16& error_description, 438 const string16& error_description,
449 content::RenderViewHost* render_view_host) { 439 content::RenderViewHost* render_view_host) {
450 if (render_view_host != render_view_host_) 440 if (render_view_host != render_view_host_)
451 return; 441 return;
452 if (!navigation_state_.CanSendEvents(frame_id)) 442 if (!navigation_state_.CanSendEvents(frame_id))
453 return; 443 return;
454 navigation_state_.SetErrorOccurredInFrame(frame_id); 444 navigation_state_.SetErrorOccurredInFrame(frame_id);
455 helpers::DispatchOnErrorOccurred( 445 helpers::DispatchOnErrorOccurred(
456 web_contents(), validated_url, frame_id, is_main_frame, error_code); 446 web_contents(), render_view_host->GetProcess()->GetID(), validated_url,
447 frame_id, is_main_frame, error_code);
457 } 448 }
458 449
459 void WebNavigationTabObserver::DidOpenRequestedURL( 450 void WebNavigationTabObserver::DidOpenRequestedURL(
460 content::WebContents* new_contents, 451 content::WebContents* new_contents,
461 const GURL& url, 452 const GURL& url,
462 const content::Referrer& referrer, 453 const content::Referrer& referrer,
463 WindowOpenDisposition disposition, 454 WindowOpenDisposition disposition,
464 content::PageTransition transition, 455 content::PageTransition transition,
465 int64 source_frame_id) { 456 int64 source_frame_id) {
466 if (!navigation_state_.CanSendEvents(source_frame_id)) 457 if (!navigation_state_.CanSendEvents(source_frame_id))
(...skipping 19 matching lines...) Expand all
486 } 477 }
487 478
488 void WebNavigationTabObserver::WebContentsDestroyed(content::WebContents* tab) { 479 void WebNavigationTabObserver::WebContentsDestroyed(content::WebContents* tab) {
489 g_tab_observer.Get().erase(tab); 480 g_tab_observer.Get().erase(tab);
490 for (FrameNavigationState::const_iterator frame = navigation_state_.begin(); 481 for (FrameNavigationState::const_iterator frame = navigation_state_.begin();
491 frame != navigation_state_.end(); ++frame) { 482 frame != navigation_state_.end(); ++frame) {
492 if (!navigation_state_.GetNavigationCompleted(*frame) && 483 if (!navigation_state_.GetNavigationCompleted(*frame) &&
493 navigation_state_.CanSendEvents(*frame)) { 484 navigation_state_.CanSendEvents(*frame)) {
494 helpers::DispatchOnErrorOccurred( 485 helpers::DispatchOnErrorOccurred(
495 tab, 486 tab,
487 tab->GetRenderViewHost()->GetProcess()->GetID(),
496 navigation_state_.GetUrl(*frame), 488 navigation_state_.GetUrl(*frame),
497 *frame, 489 *frame,
498 navigation_state_.IsMainFrame(*frame), 490 navigation_state_.IsMainFrame(*frame),
499 net::ERR_ABORTED); 491 net::ERR_ABORTED);
500 } 492 }
501 } 493 }
502 } 494 }
503 495
504 // See also NavigationController::IsURLInPageNavigation. 496 // See also NavigationController::IsURLInPageNavigation.
505 bool WebNavigationTabObserver::IsReferenceFragmentNavigation( 497 bool WebNavigationTabObserver::IsReferenceFragmentNavigation(
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 frame->frame_id = helpers::GetFrameId( 590 frame->frame_id = helpers::GetFrameId(
599 navigation_state.IsMainFrame(frame_id), frame_id); 591 navigation_state.IsMainFrame(frame_id), frame_id);
600 frame->error_occurred = navigation_state.GetErrorOccurredInFrame(frame_id); 592 frame->error_occurred = navigation_state.GetErrorOccurredInFrame(frame_id);
601 result_list.push_back(frame); 593 result_list.push_back(frame);
602 } 594 }
603 results_ = GetAllFrames::Results::Create(result_list); 595 results_ = GetAllFrames::Results::Create(result_list);
604 return true; 596 return true;
605 } 597 }
606 598
607 } // namespace extensions 599 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698