OLD | NEW |
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/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 // that weren't reguarly loaded. | 313 // that weren't reguarly loaded. |
314 if (!navigation_state_.IsValidFrame(render_frame_host)) | 314 if (!navigation_state_.IsValidFrame(render_frame_host)) |
315 return; | 315 return; |
316 | 316 |
317 navigation_state_.SetDocumentLoadCompleted(render_frame_host); | 317 navigation_state_.SetDocumentLoadCompleted(render_frame_host); |
318 if (!navigation_state_.CanSendEvents(render_frame_host)) | 318 if (!navigation_state_.CanSendEvents(render_frame_host)) |
319 return; | 319 return; |
320 | 320 |
321 // A new navigation might have started before the old one completed. | 321 // A new navigation might have started before the old one completed. |
322 // Ignore the old navigation completion in that case. | 322 // Ignore the old navigation completion in that case. |
323 if (navigation_state_.GetUrl(render_frame_host) != validated_url) | 323 // srcdoc iframes will report a url of about:blank, still let it through. |
| 324 if (navigation_state_.GetUrl(render_frame_host) != validated_url && |
| 325 (navigation_state_.GetUrl(render_frame_host) != |
| 326 content::kAboutSrcDocURL || |
| 327 validated_url != url::kAboutBlankURL)) { |
324 return; | 328 return; |
| 329 } |
325 | 330 |
326 // The load might already have finished by the time we finished parsing. For | 331 // The load might already have finished by the time we finished parsing. For |
327 // compatibility reasons, we artifically delay the load completed signal until | 332 // compatibility reasons, we artifically delay the load completed signal until |
328 // after parsing was completed. | 333 // after parsing was completed. |
329 if (!navigation_state_.GetParsingFinished(render_frame_host)) | 334 if (!navigation_state_.GetParsingFinished(render_frame_host)) |
330 return; | 335 return; |
331 helpers::DispatchOnCompleted(web_contents(), | 336 helpers::DispatchOnCompleted(web_contents(), |
332 render_frame_host, | 337 render_frame_host, |
333 navigation_state_.GetUrl(render_frame_host)); | 338 navigation_state_.GetUrl(render_frame_host)); |
334 } | 339 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 } | 392 } |
388 | 393 |
389 void WebNavigationTabObserver::HandleCommit( | 394 void WebNavigationTabObserver::HandleCommit( |
390 content::NavigationHandle* navigation_handle) { | 395 content::NavigationHandle* navigation_handle) { |
391 bool is_reference_fragment_navigation = IsReferenceFragmentNavigation( | 396 bool is_reference_fragment_navigation = IsReferenceFragmentNavigation( |
392 navigation_handle->GetRenderFrameHost(), navigation_handle->GetURL()); | 397 navigation_handle->GetRenderFrameHost(), navigation_handle->GetURL()); |
393 | 398 |
394 navigation_state_.StartTrackingDocumentLoad( | 399 navigation_state_.StartTrackingDocumentLoad( |
395 navigation_handle->GetRenderFrameHost(), navigation_handle->GetURL(), | 400 navigation_handle->GetRenderFrameHost(), navigation_handle->GetURL(), |
396 navigation_handle->IsSamePage(), | 401 navigation_handle->IsSamePage(), |
397 false); // is_error_page | 402 false, // is_error_page |
| 403 navigation_handle->IsSrcdoc()); |
398 | 404 |
399 events::HistogramValue histogram_value = events::UNKNOWN; | 405 events::HistogramValue histogram_value = events::UNKNOWN; |
400 std::string event_name; | 406 std::string event_name; |
401 if (is_reference_fragment_navigation) { | 407 if (is_reference_fragment_navigation) { |
402 histogram_value = events::WEB_NAVIGATION_ON_REFERENCE_FRAGMENT_UPDATED; | 408 histogram_value = events::WEB_NAVIGATION_ON_REFERENCE_FRAGMENT_UPDATED; |
403 event_name = web_navigation::OnReferenceFragmentUpdated::kEventName; | 409 event_name = web_navigation::OnReferenceFragmentUpdated::kEventName; |
404 } else if (navigation_handle->IsSamePage()) { | 410 } else if (navigation_handle->IsSamePage()) { |
405 histogram_value = events::WEB_NAVIGATION_ON_HISTORY_STATE_UPDATED; | 411 histogram_value = events::WEB_NAVIGATION_ON_HISTORY_STATE_UPDATED; |
406 event_name = web_navigation::OnHistoryStateUpdated::kEventName; | 412 event_name = web_navigation::OnHistoryStateUpdated::kEventName; |
407 } else { | 413 } else { |
408 histogram_value = events::WEB_NAVIGATION_ON_COMMITTED; | 414 histogram_value = events::WEB_NAVIGATION_ON_COMMITTED; |
409 event_name = web_navigation::OnCommitted::kEventName; | 415 event_name = web_navigation::OnCommitted::kEventName; |
410 } | 416 } |
411 helpers::DispatchOnCommitted(histogram_value, event_name, navigation_handle); | 417 helpers::DispatchOnCommitted(histogram_value, event_name, navigation_handle); |
412 } | 418 } |
413 | 419 |
414 void WebNavigationTabObserver::HandleError( | 420 void WebNavigationTabObserver::HandleError( |
415 content::NavigationHandle* navigation_handle) { | 421 content::NavigationHandle* navigation_handle) { |
416 if (navigation_handle->HasCommitted()) { | 422 if (navigation_handle->HasCommitted()) { |
417 navigation_state_.StartTrackingDocumentLoad( | 423 navigation_state_.StartTrackingDocumentLoad( |
418 navigation_handle->GetRenderFrameHost(), navigation_handle->GetURL(), | 424 navigation_handle->GetRenderFrameHost(), navigation_handle->GetURL(), |
419 navigation_handle->IsSamePage(), | 425 navigation_handle->IsSamePage(), |
420 true); // is_error_page | 426 true, // is_error_page |
| 427 navigation_handle->IsSrcdoc()); |
421 } | 428 } |
422 | 429 |
423 helpers::DispatchOnErrorOccurred(navigation_handle); | 430 helpers::DispatchOnErrorOccurred(navigation_handle); |
424 } | 431 } |
425 | 432 |
426 // See also NavigationController::IsURLInPageNavigation. | 433 // See also NavigationController::IsURLInPageNavigation. |
427 bool WebNavigationTabObserver::IsReferenceFragmentNavigation( | 434 bool WebNavigationTabObserver::IsReferenceFragmentNavigation( |
428 content::RenderFrameHost* render_frame_host, | 435 content::RenderFrameHost* render_frame_host, |
429 const GURL& url) { | 436 const GURL& url) { |
430 GURL existing_url = navigation_state_.GetUrl(render_frame_host); | 437 GURL existing_url = navigation_state_.GetUrl(render_frame_host); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 return g_factory.Pointer(); | 560 return g_factory.Pointer(); |
554 } | 561 } |
555 | 562 |
556 void WebNavigationAPI::OnListenerAdded(const EventListenerInfo& details) { | 563 void WebNavigationAPI::OnListenerAdded(const EventListenerInfo& details) { |
557 web_navigation_event_router_.reset(new WebNavigationEventRouter( | 564 web_navigation_event_router_.reset(new WebNavigationEventRouter( |
558 Profile::FromBrowserContext(browser_context_))); | 565 Profile::FromBrowserContext(browser_context_))); |
559 EventRouter::Get(browser_context_)->UnregisterObserver(this); | 566 EventRouter::Get(browser_context_)->UnregisterObserver(this); |
560 } | 567 } |
561 | 568 |
562 } // namespace extensions | 569 } // namespace extensions |
OLD | NEW |