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

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

Issue 10808097: Revert 148074 - Pass the render process id to the FrameNavigationState. (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"
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 if (!tab_observer) { 173 if (!tab_observer) {
174 // If you hit this DCHECK(), please add reproduction steps to 174 // If you hit this DCHECK(), please add reproduction steps to
175 // http://crbug.com/109464. 175 // http://crbug.com/109464.
176 DCHECK(chrome::GetViewType(details->source_web_contents) != 176 DCHECK(chrome::GetViewType(details->source_web_contents) !=
177 chrome::VIEW_TYPE_TAB_CONTENTS); 177 chrome::VIEW_TYPE_TAB_CONTENTS);
178 return; 178 return;
179 } 179 }
180 const FrameNavigationState& frame_navigation_state = 180 const FrameNavigationState& frame_navigation_state =
181 tab_observer->frame_navigation_state(); 181 tab_observer->frame_navigation_state();
182 182
183 FrameNavigationState::FrameID frame_id( 183 if (!frame_navigation_state.CanSendEvents(details->source_frame_id))
184 details->source_frame_id,
185 details->source_web_contents->GetRenderViewHost()->GetProcess()->GetID());
186 if (!frame_navigation_state.CanSendEvents(frame_id))
187 return; 184 return;
188 185
189 // If the WebContents was created as a response to an IPC from a renderer 186 // If the WebContents was created as a response to an IPC from a renderer
190 // (and therefore doesn't yet have a TabContents), or if it isn't yet inserted 187 // (and therefore doesn't yet have a TabContents), or if it isn't yet inserted
191 // into a tab strip, we need to delay the extension event until the 188 // into a tab strip, we need to delay the extension event until the
192 // WebContents is fully initialized. 189 // WebContents is fully initialized.
193 if (TabContents::FromWebContents(details->target_web_contents) == NULL || 190 if (TabContents::FromWebContents(details->target_web_contents) == NULL ||
194 details->not_yet_in_tabstrip) { 191 details->not_yet_in_tabstrip) {
195 pending_web_contents_[details->target_web_contents] = 192 pending_web_contents_[details->target_web_contents] =
196 PendingWebContents( 193 PendingWebContents(
197 details->source_web_contents, 194 details->source_web_contents,
198 details->source_frame_id, 195 details->source_frame_id,
199 frame_navigation_state.IsMainFrame(frame_id), 196 frame_navigation_state.IsMainFrame(details->source_frame_id),
200 details->target_web_contents, 197 details->target_web_contents,
201 details->target_url); 198 details->target_url);
202 } else { 199 } else {
203 helpers::DispatchOnCreatedNavigationTarget( 200 helpers::DispatchOnCreatedNavigationTarget(
204 details->source_web_contents, 201 details->source_web_contents,
205 details->target_web_contents->GetBrowserContext(), 202 details->target_web_contents->GetBrowserContext(),
206 details->source_frame_id, 203 details->source_frame_id,
207 frame_navigation_state.IsMainFrame(frame_id), 204 frame_navigation_state.IsMainFrame(details->source_frame_id),
208 details->target_web_contents, 205 details->target_web_contents,
209 details->target_url); 206 details->target_url);
210 } 207 }
211 } 208 }
212 209
213 void WebNavigationEventRouter::TabAdded(content::WebContents* tab) { 210 void WebNavigationEventRouter::TabAdded(content::WebContents* tab) {
214 std::map<content::WebContents*, PendingWebContents>::iterator iter = 211 std::map<content::WebContents*, PendingWebContents>::iterator iter =
215 pending_web_contents_.find(tab); 212 pending_web_contents_.find(tab);
216 if (iter == pending_web_contents_.end()) 213 if (iter == pending_web_contents_.end())
217 return; 214 return;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 const content::NotificationSource& source, 261 const content::NotificationSource& source,
265 const content::NotificationDetails& details) { 262 const content::NotificationDetails& details) {
266 switch (type) { 263 switch (type) {
267 case content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT: { 264 case content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT: {
268 content::ResourceRedirectDetails* resource_redirect_details = 265 content::ResourceRedirectDetails* resource_redirect_details =
269 content::Details<content::ResourceRedirectDetails>(details).ptr(); 266 content::Details<content::ResourceRedirectDetails>(details).ptr();
270 ResourceType::Type resource_type = 267 ResourceType::Type resource_type =
271 resource_redirect_details->resource_type; 268 resource_redirect_details->resource_type;
272 if (resource_type == ResourceType::MAIN_FRAME || 269 if (resource_type == ResourceType::MAIN_FRAME ||
273 resource_type == ResourceType::SUB_FRAME) { 270 resource_type == ResourceType::SUB_FRAME) {
274 FrameNavigationState::FrameID frame_id( 271 int64 frame_id = resource_redirect_details->frame_id;
275 resource_redirect_details->frame_id,
276 resource_redirect_details->origin_child_id);
277 if (!navigation_state_.CanSendEvents(frame_id)) 272 if (!navigation_state_.CanSendEvents(frame_id))
278 return; 273 return;
279 navigation_state_.SetIsServerRedirected(frame_id); 274 navigation_state_.SetIsServerRedirected(frame_id);
280 } 275 }
281 break; 276 break;
282 } 277 }
283 278
284 default: 279 default:
285 NOTREACHED(); 280 NOTREACHED();
286 } 281 }
287 } 282 }
288 283
289 void WebNavigationTabObserver::AboutToNavigateRenderView( 284 void WebNavigationTabObserver::AboutToNavigateRenderView(
290 content::RenderViewHost* render_view_host) { 285 content::RenderViewHost* render_view_host) {
291 if (!render_view_host_) { 286 if (!render_view_host_) {
292 render_view_host_ = render_view_host; 287 render_view_host_ = render_view_host;
293 } else if (render_view_host != render_view_host_) { 288 } else if (render_view_host != render_view_host_) {
294 // TODO(jochen): If pending_render_view_host_ is non-NULL, send error events 289 // TODO(jochen): If pending_render_view_host_ is non-NULL, send error events
295 // for all ongoing navigations in that RVH. 290 // for all ongoing navigations in that RVH.
296 pending_render_view_host_ = render_view_host; 291 pending_render_view_host_ = render_view_host;
297 } 292 }
298 } 293 }
299 294
300 void WebNavigationTabObserver::DidStartProvisionalLoadForFrame( 295 void WebNavigationTabObserver::DidStartProvisionalLoadForFrame(
301 int64 frame_num, 296 int64 frame_id,
302 bool is_main_frame, 297 bool is_main_frame,
303 const GURL& validated_url, 298 const GURL& validated_url,
304 bool is_error_page, 299 bool is_error_page,
305 content::RenderViewHost* render_view_host) { 300 content::RenderViewHost* render_view_host) {
306 if (!render_view_host_) 301 if (!render_view_host_)
307 render_view_host_ = render_view_host; 302 render_view_host_ = render_view_host;
308 if (render_view_host != render_view_host_ && 303 if (render_view_host != render_view_host_ &&
309 render_view_host != pending_render_view_host_) 304 render_view_host != pending_render_view_host_)
310 return; 305 return;
311 306
312 FrameNavigationState::FrameID frame_id(
313 frame_num, render_view_host->GetProcess()->GetID());
314
315 navigation_state_.TrackFrame(frame_id, 307 navigation_state_.TrackFrame(frame_id,
316 validated_url, 308 validated_url,
317 is_main_frame, 309 is_main_frame,
318 is_error_page); 310 is_error_page);
319 if (!navigation_state_.CanSendEvents(frame_id)) 311 if (!navigation_state_.CanSendEvents(frame_id))
320 return; 312 return;
321 313
322 helpers::DispatchOnBeforeNavigate( 314 helpers::DispatchOnBeforeNavigate(
323 web_contents(), render_view_host->GetProcess()->GetID(), frame_num, 315 web_contents(), render_view_host->GetProcess()->GetID(), frame_id,
324 is_main_frame, validated_url); 316 is_main_frame, validated_url);
325 } 317 }
326 318
327 void WebNavigationTabObserver::DidCommitProvisionalLoadForFrame( 319 void WebNavigationTabObserver::DidCommitProvisionalLoadForFrame(
328 int64 frame_num, 320 int64 frame_id,
329 bool is_main_frame, 321 bool is_main_frame,
330 const GURL& url, 322 const GURL& url,
331 content::PageTransition transition_type, 323 content::PageTransition transition_type,
332 content::RenderViewHost* render_view_host) { 324 content::RenderViewHost* render_view_host) {
333 if (render_view_host != render_view_host_ && 325 if (render_view_host != render_view_host_ &&
334 render_view_host != pending_render_view_host_) 326 render_view_host != pending_render_view_host_)
335 return; 327 return;
336 // TODO(jochen): If we switched the RVH, send error events for all ongoing 328 // TODO(jochen): If we switched the RVH, send error events for all ongoing
337 // navigations in the old RVH. 329 // navigations in the old RVH.
338 render_view_host_ = render_view_host; 330 render_view_host_ = render_view_host;
339 pending_render_view_host_ = NULL; 331 pending_render_view_host_ = NULL;
340 332
341 FrameNavigationState::FrameID frame_id(
342 frame_num, render_view_host->GetProcess()->GetID());
343 if (!navigation_state_.CanSendEvents(frame_id)) 333 if (!navigation_state_.CanSendEvents(frame_id))
344 return; 334 return;
345 335
346 bool is_reference_fragment_navigation = 336 bool is_reference_fragment_navigation =
347 IsReferenceFragmentNavigation(frame_id, url); 337 IsReferenceFragmentNavigation(frame_id, url);
348 bool is_history_navigation = 338 bool is_history_navigation =
349 navigation_state_.GetNavigationCommitted(frame_id); 339 navigation_state_.GetNavigationCommitted(frame_id);
350 340
351 // Update the URL as it might have changed. 341 // Update the URL as it might have changed.
352 navigation_state_.UpdateFrame(frame_id, url); 342 navigation_state_.UpdateFrame(frame_id, url);
353 navigation_state_.SetNavigationCommitted(frame_id); 343 navigation_state_.SetNavigationCommitted(frame_id);
354 344
355 if (is_reference_fragment_navigation) { 345 if (is_reference_fragment_navigation) {
356 helpers::DispatchOnCommitted( 346 helpers::DispatchOnCommitted(
357 keys::kOnReferenceFragmentUpdated, 347 keys::kOnReferenceFragmentUpdated,
358 web_contents(), 348 web_contents(),
359 frame_num, 349 frame_id,
360 is_main_frame, 350 is_main_frame,
361 url, 351 url,
362 transition_type); 352 transition_type);
363 navigation_state_.SetNavigationCompleted(frame_id); 353 navigation_state_.SetNavigationCompleted(frame_id);
364 } else if (is_history_navigation) { 354 } else if (is_history_navigation) {
365 // Make the transition type match the one for reference fragment updates. 355 // Make the transition type match the one for reference fragment updates.
366 transition_type = static_cast<content::PageTransition>( 356 transition_type = static_cast<content::PageTransition>(
367 transition_type | content::PAGE_TRANSITION_CLIENT_REDIRECT); 357 transition_type | content::PAGE_TRANSITION_CLIENT_REDIRECT);
368 helpers::DispatchOnCommitted( 358 helpers::DispatchOnCommitted(
369 keys::kOnHistoryStateUpdated, 359 keys::kOnHistoryStateUpdated,
370 web_contents(), 360 web_contents(),
371 frame_num, 361 frame_id,
372 is_main_frame, 362 is_main_frame,
373 url, 363 url,
374 transition_type); 364 transition_type);
375 navigation_state_.SetNavigationCompleted(frame_id); 365 navigation_state_.SetNavigationCompleted(frame_id);
376 } else { 366 } else {
377 if (navigation_state_.GetIsServerRedirected(frame_id)) { 367 if (navigation_state_.GetIsServerRedirected(frame_id)) {
378 transition_type = static_cast<content::PageTransition>( 368 transition_type = static_cast<content::PageTransition>(
379 transition_type | content::PAGE_TRANSITION_SERVER_REDIRECT); 369 transition_type | content::PAGE_TRANSITION_SERVER_REDIRECT);
380 } 370 }
381 helpers::DispatchOnCommitted( 371 helpers::DispatchOnCommitted(
382 keys::kOnCommitted, 372 keys::kOnCommitted,
383 web_contents(), 373 web_contents(),
384 frame_num, 374 frame_id,
385 is_main_frame, 375 is_main_frame,
386 url, 376 url,
387 transition_type); 377 transition_type);
388 } 378 }
389 } 379 }
390 380
391 void WebNavigationTabObserver::DidFailProvisionalLoad( 381 void WebNavigationTabObserver::DidFailProvisionalLoad(
392 int64 frame_num, 382 int64 frame_id,
393 bool is_main_frame, 383 bool is_main_frame,
394 const GURL& validated_url, 384 const GURL& validated_url,
395 int error_code, 385 int error_code,
396 const string16& error_description, 386 const string16& error_description,
397 content::RenderViewHost* render_view_host) { 387 content::RenderViewHost* render_view_host) {
398 if (render_view_host != render_view_host_ && 388 if (render_view_host != render_view_host_ &&
399 render_view_host != pending_render_view_host_) 389 render_view_host != pending_render_view_host_)
400 return; 390 return;
401 if (render_view_host == pending_render_view_host_) 391 if (render_view_host == pending_render_view_host_)
402 pending_render_view_host_ = NULL; 392 pending_render_view_host_ = NULL;
403 393
404 FrameNavigationState::FrameID frame_id(
405 frame_num, render_view_host->GetProcess()->GetID());
406 if (!navigation_state_.CanSendEvents(frame_id)) 394 if (!navigation_state_.CanSendEvents(frame_id))
407 return; 395 return;
408 396
409 navigation_state_.SetErrorOccurredInFrame(frame_id); 397 navigation_state_.SetErrorOccurredInFrame(frame_id);
410 helpers::DispatchOnErrorOccurred( 398 helpers::DispatchOnErrorOccurred(
411 web_contents(), render_view_host->GetProcess()->GetID(), validated_url, 399 web_contents(), render_view_host->GetProcess()->GetID(), validated_url,
412 frame_num, is_main_frame, error_code); 400 frame_id, is_main_frame, error_code);
413 } 401 }
414 402
415 void WebNavigationTabObserver::DocumentLoadedInFrame( 403 void WebNavigationTabObserver::DocumentLoadedInFrame(
416 int64 frame_num, 404 int64 frame_id,
417 content::RenderViewHost* render_view_host) { 405 content::RenderViewHost* render_view_host) {
418 if (render_view_host != render_view_host_) 406 if (render_view_host != render_view_host_)
419 return; 407 return;
420 FrameNavigationState::FrameID frame_id(
421 frame_num, render_view_host->GetProcess()->GetID());
422 if (!navigation_state_.CanSendEvents(frame_id)) 408 if (!navigation_state_.CanSendEvents(frame_id))
423 return; 409 return;
424 helpers::DispatchOnDOMContentLoaded(web_contents(), 410 helpers::DispatchOnDOMContentLoaded(web_contents(),
425 navigation_state_.GetUrl(frame_id), 411 navigation_state_.GetUrl(frame_id),
426 navigation_state_.IsMainFrame(frame_id), 412 navigation_state_.IsMainFrame(frame_id),
427 frame_num); 413 frame_id);
428 } 414 }
429 415
430 void WebNavigationTabObserver::DidFinishLoad( 416 void WebNavigationTabObserver::DidFinishLoad(
431 int64 frame_num, 417 int64 frame_id,
432 const GURL& validated_url, 418 const GURL& validated_url,
433 bool is_main_frame, 419 bool is_main_frame,
434 content::RenderViewHost* render_view_host) { 420 content::RenderViewHost* render_view_host) {
435 if (render_view_host != render_view_host_) 421 if (render_view_host != render_view_host_)
436 return; 422 return;
437 FrameNavigationState::FrameID frame_id(
438 frame_num, render_view_host->GetProcess()->GetID());
439 if (!navigation_state_.CanSendEvents(frame_id)) 423 if (!navigation_state_.CanSendEvents(frame_id))
440 return; 424 return;
441 navigation_state_.SetNavigationCompleted(frame_id); 425 navigation_state_.SetNavigationCompleted(frame_id);
442 DCHECK_EQ(navigation_state_.GetUrl(frame_id), validated_url); 426 DCHECK_EQ(navigation_state_.GetUrl(frame_id), validated_url);
443 DCHECK_EQ(navigation_state_.IsMainFrame(frame_id), is_main_frame); 427 DCHECK_EQ(navigation_state_.IsMainFrame(frame_id), is_main_frame);
444 helpers::DispatchOnCompleted(web_contents(), 428 helpers::DispatchOnCompleted(web_contents(),
445 validated_url, 429 validated_url,
446 is_main_frame, 430 is_main_frame,
447 frame_num); 431 frame_id);
448 } 432 }
449 433
450 void WebNavigationTabObserver::DidFailLoad( 434 void WebNavigationTabObserver::DidFailLoad(
451 int64 frame_num, 435 int64 frame_id,
452 const GURL& validated_url, 436 const GURL& validated_url,
453 bool is_main_frame, 437 bool is_main_frame,
454 int error_code, 438 int error_code,
455 const string16& error_description, 439 const string16& error_description,
456 content::RenderViewHost* render_view_host) { 440 content::RenderViewHost* render_view_host) {
457 if (render_view_host != render_view_host_) 441 if (render_view_host != render_view_host_)
458 return; 442 return;
459 FrameNavigationState::FrameID frame_id(
460 frame_num, render_view_host->GetProcess()->GetID());
461 if (!navigation_state_.CanSendEvents(frame_id)) 443 if (!navigation_state_.CanSendEvents(frame_id))
462 return; 444 return;
463 navigation_state_.SetErrorOccurredInFrame(frame_id); 445 navigation_state_.SetErrorOccurredInFrame(frame_id);
464 helpers::DispatchOnErrorOccurred( 446 helpers::DispatchOnErrorOccurred(
465 web_contents(), render_view_host->GetProcess()->GetID(), validated_url, 447 web_contents(), render_view_host->GetProcess()->GetID(), validated_url,
466 frame_num, is_main_frame, error_code); 448 frame_id, is_main_frame, error_code);
467 } 449 }
468 450
469 void WebNavigationTabObserver::DidOpenRequestedURL( 451 void WebNavigationTabObserver::DidOpenRequestedURL(
470 content::WebContents* new_contents, 452 content::WebContents* new_contents,
471 const GURL& url, 453 const GURL& url,
472 const content::Referrer& referrer, 454 const content::Referrer& referrer,
473 WindowOpenDisposition disposition, 455 WindowOpenDisposition disposition,
474 content::PageTransition transition, 456 content::PageTransition transition,
475 int64 source_frame_num) { 457 int64 source_frame_id) {
476 FrameNavigationState::FrameID frame_id( 458 if (!navigation_state_.CanSendEvents(source_frame_id))
477 source_frame_num, render_view_host_->GetProcess()->GetID());
478 if (!navigation_state_.CanSendEvents(frame_id))
479 return; 459 return;
480 460
481 // We only send the onCreatedNavigationTarget if we end up creating a new 461 // We only send the onCreatedNavigationTarget if we end up creating a new
482 // window. 462 // window.
483 if (disposition != SINGLETON_TAB && 463 if (disposition != SINGLETON_TAB &&
484 disposition != NEW_FOREGROUND_TAB && 464 disposition != NEW_FOREGROUND_TAB &&
485 disposition != NEW_BACKGROUND_TAB && 465 disposition != NEW_BACKGROUND_TAB &&
486 disposition != NEW_POPUP && 466 disposition != NEW_POPUP &&
487 disposition != NEW_WINDOW && 467 disposition != NEW_WINDOW &&
488 disposition != OFF_THE_RECORD) 468 disposition != OFF_THE_RECORD)
489 return; 469 return;
490 470
491 helpers::DispatchOnCreatedNavigationTarget( 471 helpers::DispatchOnCreatedNavigationTarget(
492 web_contents(), 472 web_contents(),
493 new_contents->GetBrowserContext(), 473 new_contents->GetBrowserContext(),
494 source_frame_num, 474 source_frame_id,
495 navigation_state_.IsMainFrame(frame_id), 475 navigation_state_.IsMainFrame(source_frame_id),
496 new_contents, 476 new_contents,
497 url); 477 url);
498 } 478 }
499 479
500 void WebNavigationTabObserver::WebContentsDestroyed(content::WebContents* tab) { 480 void WebNavigationTabObserver::WebContentsDestroyed(content::WebContents* tab) {
501 g_tab_observer.Get().erase(tab); 481 g_tab_observer.Get().erase(tab);
502 for (FrameNavigationState::const_iterator frame = navigation_state_.begin(); 482 for (FrameNavigationState::const_iterator frame = navigation_state_.begin();
503 frame != navigation_state_.end(); ++frame) { 483 frame != navigation_state_.end(); ++frame) {
504 if (!navigation_state_.GetNavigationCompleted(*frame) && 484 if (!navigation_state_.GetNavigationCompleted(*frame) &&
505 navigation_state_.CanSendEvents(*frame)) { 485 navigation_state_.CanSendEvents(*frame)) {
506 helpers::DispatchOnErrorOccurred( 486 helpers::DispatchOnErrorOccurred(
507 tab, 487 tab,
508 frame->render_process_id, 488 tab->GetRenderViewHost()->GetProcess()->GetID(),
509 navigation_state_.GetUrl(*frame), 489 navigation_state_.GetUrl(*frame),
510 frame->frame_num, 490 *frame,
511 navigation_state_.IsMainFrame(*frame), 491 navigation_state_.IsMainFrame(*frame),
512 net::ERR_ABORTED); 492 net::ERR_ABORTED);
513 } 493 }
514 } 494 }
515 } 495 }
516 496
517 // See also NavigationController::IsURLInPageNavigation. 497 // See also NavigationController::IsURLInPageNavigation.
518 bool WebNavigationTabObserver::IsReferenceFragmentNavigation( 498 bool WebNavigationTabObserver::IsReferenceFragmentNavigation(
519 FrameNavigationState::FrameID frame_id, 499 int64 frame_id,
520 const GURL& url) { 500 const GURL& url) {
521 GURL existing_url = navigation_state_.GetUrl(frame_id); 501 GURL existing_url = navigation_state_.GetUrl(frame_id);
522 if (existing_url == url) 502 if (existing_url == url)
523 return false; 503 return false;
524 504
525 url_canon::Replacements<char> replacements; 505 url_canon::Replacements<char> replacements;
526 replacements.ClearRef(); 506 replacements.ClearRef();
527 return existing_url.ReplaceComponents(replacements) == 507 return existing_url.ReplaceComponents(replacements) ==
528 url.ReplaceComponents(replacements); 508 url.ReplaceComponents(replacements);
529 } 509 }
530 510
531 bool GetFrameFunction::RunImpl() { 511 bool GetFrameFunction::RunImpl() {
532 scoped_ptr<GetFrame::Params> params(GetFrame::Params::Create(*args_)); 512 scoped_ptr<GetFrame::Params> params(GetFrame::Params::Create(*args_));
533 EXTENSION_FUNCTION_VALIDATE(params.get()); 513 EXTENSION_FUNCTION_VALIDATE(params.get());
534 int tab_id = params->details.tab_id; 514 int tab_id = params->details.tab_id;
535 int frame_id = params->details.frame_id; 515 int frame_id = params->details.frame_id;
536 int process_id = params->details.process_id;
537 516
538 SetResult(Value::CreateNullValue()); 517 SetResult(Value::CreateNullValue());
539 518
540 TabContents* tab_contents; 519 TabContents* tab_contents;
541 if (!ExtensionTabUtil::GetTabById(tab_id, 520 if (!ExtensionTabUtil::GetTabById(tab_id,
542 profile(), 521 profile(),
543 include_incognito(), 522 include_incognito(),
544 NULL, NULL, 523 NULL, NULL,
545 &tab_contents, 524 &tab_contents,
546 NULL) || 525 NULL) ||
547 !tab_contents) { 526 !tab_contents) {
548 return true; 527 return true;
549 } 528 }
550 529
551 content::WebContents* web_contents = tab_contents->web_contents(); 530 content::WebContents* web_contents = tab_contents->web_contents();
552 WebNavigationTabObserver* observer = 531 WebNavigationTabObserver* observer =
553 WebNavigationTabObserver::Get(web_contents); 532 WebNavigationTabObserver::Get(web_contents);
554 DCHECK(observer); 533 DCHECK(observer);
555 534
556 const FrameNavigationState& frame_navigation_state = 535 const FrameNavigationState& frame_navigation_state =
557 observer->frame_navigation_state(); 536 observer->frame_navigation_state();
558 537
559 if (frame_id == 0) 538 if (frame_id == 0)
560 frame_id = frame_navigation_state.GetMainFrameID().frame_num; 539 frame_id = frame_navigation_state.GetMainFrameID();
561 540 if (!frame_navigation_state.IsValidFrame(frame_id))
562 FrameNavigationState::FrameID internal_frame_id(frame_id, process_id);
563 if (!frame_navigation_state.IsValidFrame(internal_frame_id))
564 return true; 541 return true;
565 542
566 GURL frame_url = frame_navigation_state.GetUrl(internal_frame_id); 543 GURL frame_url = frame_navigation_state.GetUrl(frame_id);
567 if (!frame_navigation_state.IsValidUrl(frame_url)) 544 if (!frame_navigation_state.IsValidUrl(frame_url))
568 return true; 545 return true;
569 546
570 GetFrame::Results::Details frame_details; 547 GetFrame::Results::Details frame_details;
571 frame_details.url = frame_url.spec(); 548 frame_details.url = frame_url.spec();
572 frame_details.error_occurred = 549 frame_details.error_occurred =
573 frame_navigation_state.GetErrorOccurredInFrame(internal_frame_id); 550 frame_navigation_state.GetErrorOccurredInFrame(frame_id);
574 results_ = GetFrame::Results::Create(frame_details); 551 results_ = GetFrame::Results::Create(frame_details);
575 return true; 552 return true;
576 } 553 }
577 554
578 bool GetAllFramesFunction::RunImpl() { 555 bool GetAllFramesFunction::RunImpl() {
579 scoped_ptr<GetAllFrames::Params> params(GetAllFrames::Params::Create(*args_)); 556 scoped_ptr<GetAllFrames::Params> params(GetAllFrames::Params::Create(*args_));
580 EXTENSION_FUNCTION_VALIDATE(params.get()); 557 EXTENSION_FUNCTION_VALIDATE(params.get());
581 int tab_id = params->details.tab_id; 558 int tab_id = params->details.tab_id;
582 559
583 SetResult(Value::CreateNullValue()); 560 SetResult(Value::CreateNullValue());
(...skipping 13 matching lines...) Expand all
597 WebNavigationTabObserver* observer = 574 WebNavigationTabObserver* observer =
598 WebNavigationTabObserver::Get(web_contents); 575 WebNavigationTabObserver::Get(web_contents);
599 DCHECK(observer); 576 DCHECK(observer);
600 577
601 const FrameNavigationState& navigation_state = 578 const FrameNavigationState& navigation_state =
602 observer->frame_navigation_state(); 579 observer->frame_navigation_state();
603 580
604 std::vector<linked_ptr<GetAllFrames::Results::DetailsElement> > result_list; 581 std::vector<linked_ptr<GetAllFrames::Results::DetailsElement> > result_list;
605 for (FrameNavigationState::const_iterator it = navigation_state.begin(); 582 for (FrameNavigationState::const_iterator it = navigation_state.begin();
606 it != navigation_state.end(); ++it) { 583 it != navigation_state.end(); ++it) {
607 FrameNavigationState::FrameID frame_id = *it; 584 int64 frame_id = *it;
608 GURL frame_url = navigation_state.GetUrl(frame_id); 585 GURL frame_url = navigation_state.GetUrl(frame_id);
609 if (!navigation_state.IsValidUrl(frame_url)) 586 if (!navigation_state.IsValidUrl(frame_url))
610 continue; 587 continue;
611 linked_ptr<GetAllFrames::Results::DetailsElement> frame( 588 linked_ptr<GetAllFrames::Results::DetailsElement> frame(
612 new GetAllFrames::Results::DetailsElement()); 589 new GetAllFrames::Results::DetailsElement());
613 frame->url = frame_url.spec(); 590 frame->url = frame_url.spec();
614 frame->frame_id = helpers::GetFrameId( 591 frame->frame_id = helpers::GetFrameId(
615 navigation_state.IsMainFrame(frame_id), frame_id.frame_num); 592 navigation_state.IsMainFrame(frame_id), frame_id);
616 frame->process_id = frame_id.render_process_id;
617 frame->error_occurred = navigation_state.GetErrorOccurredInFrame(frame_id); 593 frame->error_occurred = navigation_state.GetErrorOccurredInFrame(frame_id);
618 result_list.push_back(frame); 594 result_list.push_back(frame);
619 } 595 }
620 results_ = GetAllFrames::Results::Create(result_list); 596 results_ = GetAllFrames::Results::Create(result_list);
621 return true; 597 return true;
622 } 598 }
623 599
624 } // namespace extensions 600 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698