OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All |
7 * rights reserved. | 7 * rights reserved. |
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. |
9 * (http://www.torchmobile.com/) | 9 * (http://www.torchmobile.com/) |
10 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. | 10 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 contains_validity_style_rules_(false), | 481 contains_validity_style_rules_(false), |
482 contains_plugins_(false), | 482 contains_plugins_(false), |
483 ignore_destructive_write_count_(0), | 483 ignore_destructive_write_count_(0), |
484 throw_on_dynamic_markup_insertion_count_(0), | 484 throw_on_dynamic_markup_insertion_count_(0), |
485 markers_(new DocumentMarkerController(*this)), | 485 markers_(new DocumentMarkerController(*this)), |
486 update_focus_appearance_timer_( | 486 update_focus_appearance_timer_( |
487 TaskRunnerHelper::Get(TaskType::kUnspecedTimer, this), | 487 TaskRunnerHelper::Get(TaskType::kUnspecedTimer, this), |
488 this, | 488 this, |
489 &Document::UpdateFocusAppearanceTimerFired), | 489 &Document::UpdateFocusAppearanceTimerFired), |
490 css_target_(nullptr), | 490 css_target_(nullptr), |
491 load_event_progress_(kLoadEventNotRun), | 491 load_event_progress_(kLoadEventCompleted), |
492 start_time_(CurrentTime()), | 492 start_time_(CurrentTime()), |
493 script_runner_(ScriptRunner::Create(this)), | 493 script_runner_(ScriptRunner::Create(this)), |
494 xml_version_("1.0"), | 494 xml_version_("1.0"), |
495 xml_standalone_(kStandaloneUnspecified), | 495 xml_standalone_(kStandaloneUnspecified), |
496 has_xml_declaration_(0), | 496 has_xml_declaration_(0), |
497 design_mode_(false), | 497 design_mode_(false), |
498 is_running_exec_command_(false), | 498 is_running_exec_command_(false), |
499 has_annotated_regions_(false), | 499 has_annotated_regions_(false), |
500 annotated_regions_dirty_(false), | 500 annotated_regions_dirty_(false), |
501 document_classes_(document_classes), | 501 document_classes_(document_classes), |
(...skipping 2261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2763 RemoveAllEventListenersRecursively(); | 2763 RemoveAllEventListenersRecursively(); |
2764 ResetTreeScope(); | 2764 ResetTreeScope(); |
2765 if (frame_) | 2765 if (frame_) |
2766 frame_->Selection().Clear(); | 2766 frame_->Selection().Clear(); |
2767 ImplicitOpen(kForceSynchronousParsing); | 2767 ImplicitOpen(kForceSynchronousParsing); |
2768 if (ScriptableDocumentParser* parser = GetScriptableDocumentParser()) | 2768 if (ScriptableDocumentParser* parser = GetScriptableDocumentParser()) |
2769 parser->SetWasCreatedByScript(true); | 2769 parser->SetWasCreatedByScript(true); |
2770 | 2770 |
2771 if (frame_) | 2771 if (frame_) |
2772 frame_->Loader().DidExplicitOpen(); | 2772 frame_->Loader().DidExplicitOpen(); |
2773 if (load_event_progress_ != kLoadEventInProgress && | |
2774 PageDismissalEventBeingDispatched() == kNoDismissal) | |
2775 load_event_progress_ = kLoadEventNotRun; | |
2776 } | 2773 } |
2777 | 2774 |
2778 void Document::DetachParser() { | 2775 void Document::DetachParser() { |
2779 if (!parser_) | 2776 if (!parser_) |
2780 return; | 2777 return; |
2781 parser_->Detach(); | 2778 parser_->Detach(); |
2782 parser_.Clear(); | 2779 parser_.Clear(); |
2783 DocumentParserTiming::From(*this).MarkParserDetached(); | 2780 DocumentParserTiming::From(*this).MarkParserDetached(); |
2784 } | 2781 } |
2785 | 2782 |
2786 void Document::CancelParsing() { | 2783 void Document::CancelParsing() { |
2787 DetachParser(); | 2784 DetachParser(); |
2788 SetParsingState(kFinishedParsing); | 2785 SetParsingState(kFinishedParsing); |
2789 SetReadyState(kComplete); | 2786 SetReadyState(kComplete); |
| 2787 SuppressLoadEvent(); |
2790 } | 2788 } |
2791 | 2789 |
2792 DocumentParser* Document::ImplicitOpen( | 2790 DocumentParser* Document::ImplicitOpen( |
2793 ParserSynchronizationPolicy parser_sync_policy) { | 2791 ParserSynchronizationPolicy parser_sync_policy) { |
2794 DetachParser(); | |
2795 | |
2796 RemoveChildren(); | 2792 RemoveChildren(); |
2797 DCHECK(!focused_element_); | 2793 DCHECK(!focused_element_); |
2798 | 2794 |
2799 SetCompatibilityMode(kNoQuirksMode); | 2795 SetCompatibilityMode(kNoQuirksMode); |
2800 | 2796 |
2801 if (!ThreadedParsingEnabledForTesting()) { | 2797 if (!ThreadedParsingEnabledForTesting()) { |
2802 parser_sync_policy = kForceSynchronousParsing; | 2798 parser_sync_policy = kForceSynchronousParsing; |
2803 } else if (parser_sync_policy == kAllowAsynchronousParsing && | 2799 } else if (parser_sync_policy == kAllowAsynchronousParsing && |
2804 IsPrefetchOnly()) { | 2800 IsPrefetchOnly()) { |
2805 // Prefetch must be synchronous. | 2801 // Prefetch must be synchronous. |
2806 parser_sync_policy = kForceSynchronousParsing; | 2802 parser_sync_policy = kForceSynchronousParsing; |
2807 } | 2803 } |
2808 | 2804 |
| 2805 DetachParser(); |
2809 parser_sync_policy_ = parser_sync_policy; | 2806 parser_sync_policy_ = parser_sync_policy; |
2810 parser_ = CreateParser(); | 2807 parser_ = CreateParser(); |
2811 DocumentParserTiming::From(*this).MarkParserStart(); | 2808 DocumentParserTiming::From(*this).MarkParserStart(); |
2812 SetParsingState(kParsing); | 2809 SetParsingState(kParsing); |
2813 SetReadyState(kLoading); | 2810 SetReadyState(kLoading); |
| 2811 if (load_event_progress_ != kLoadEventInProgress && |
| 2812 PageDismissalEventBeingDispatched() == kNoDismissal) { |
| 2813 load_event_progress_ = kLoadEventNotRun; |
| 2814 } |
2814 | 2815 |
2815 return parser_; | 2816 return parser_; |
2816 } | 2817 } |
2817 | 2818 |
2818 HTMLElement* Document::body() const { | 2819 HTMLElement* Document::body() const { |
2819 if (!documentElement() || !isHTMLHtmlElement(documentElement())) | 2820 if (!documentElement() || !isHTMLHtmlElement(documentElement())) |
2820 return 0; | 2821 return 0; |
2821 | 2822 |
2822 for (HTMLElement* child = | 2823 for (HTMLElement* child = |
2823 Traversal<HTMLElement>::FirstChild(*documentElement()); | 2824 Traversal<HTMLElement>::FirstChild(*documentElement()); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2945 | 2946 |
2946 close(); | 2947 close(); |
2947 } | 2948 } |
2948 | 2949 |
2949 void Document::close() { | 2950 void Document::close() { |
2950 if (!GetScriptableDocumentParser() || | 2951 if (!GetScriptableDocumentParser() || |
2951 !GetScriptableDocumentParser()->WasCreatedByScript() || | 2952 !GetScriptableDocumentParser()->WasCreatedByScript() || |
2952 !GetScriptableDocumentParser()->IsParsing()) | 2953 !GetScriptableDocumentParser()->IsParsing()) |
2953 return; | 2954 return; |
2954 | 2955 |
2955 if (DocumentParser* parser = parser_) | 2956 parser_->Finish(); |
2956 parser->Finish(); | 2957 if (!parser_ || !parser_->IsParsing()) |
2957 | 2958 SetReadyState(kComplete); |
2958 if (!frame_) { | 2959 CheckCompleted(); |
2959 // Because we have no frame, we don't know if all loading has completed, | |
2960 // so we just call implicitClose() immediately. FIXME: This might fire | |
2961 // the load event prematurely | |
2962 // <http://bugs.webkit.org/show_bug.cgi?id=14568>. | |
2963 ImplicitClose(); | |
2964 return; | |
2965 } | |
2966 | |
2967 frame_->Loader().CheckCompleted(); | |
2968 } | 2960 } |
2969 | 2961 |
2970 void Document::ImplicitClose() { | 2962 void Document::ImplicitClose() { |
2971 DCHECK(!InStyleRecalc()); | 2963 DCHECK(!InStyleRecalc()); |
2972 if (ProcessingLoadEvent() || !parser_) | 2964 DCHECK(parser_); |
2973 return; | |
2974 if (GetFrame() && | |
2975 GetFrame()->GetNavigationScheduler().LocationChangePending()) { | |
2976 SuppressLoadEvent(); | |
2977 return; | |
2978 } | |
2979 | 2965 |
2980 load_event_progress_ = kLoadEventInProgress; | 2966 load_event_progress_ = kLoadEventInProgress; |
2981 | 2967 |
2982 ScriptableDocumentParser* parser = GetScriptableDocumentParser(); | 2968 ScriptableDocumentParser* parser = GetScriptableDocumentParser(); |
2983 well_formed_ = parser && parser->WellFormed(); | 2969 well_formed_ = parser && parser->WellFormed(); |
2984 | 2970 |
2985 // We have to clear the parser, in case someone document.write()s from the | 2971 // We have to clear the parser, in case someone document.write()s from the |
2986 // onLoad event handler, as in Radar 3206524. | 2972 // onLoad event handler, as in Radar 3206524. |
2987 DetachParser(); | 2973 DetachParser(); |
2988 | 2974 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3050 cache->HandleLoadComplete(this); | 3036 cache->HandleLoadComplete(this); |
3051 else | 3037 else |
3052 cache->HandleLayoutComplete(this); | 3038 cache->HandleLayoutComplete(this); |
3053 } | 3039 } |
3054 } | 3040 } |
3055 | 3041 |
3056 if (SvgExtensions()) | 3042 if (SvgExtensions()) |
3057 AccessSVGExtensions().StartAnimations(); | 3043 AccessSVGExtensions().StartAnimations(); |
3058 } | 3044 } |
3059 | 3045 |
| 3046 static bool AllDescendantsAreComplete(Frame* frame) { |
| 3047 if (!frame) |
| 3048 return true; |
| 3049 for (Frame* child = frame->Tree().FirstChild(); child; |
| 3050 child = child->Tree().TraverseNext(frame)) { |
| 3051 if (child->IsLoading()) |
| 3052 return false; |
| 3053 } |
| 3054 return true; |
| 3055 } |
| 3056 |
| 3057 bool Document::ShouldComplete() { |
| 3058 return parsing_state_ == kFinishedParsing && HaveImportsLoaded() && |
| 3059 !fetcher_->BlockingRequestCount() && !IsDelayingLoadEvent() && |
| 3060 load_event_progress_ != kLoadEventInProgress && |
| 3061 AllDescendantsAreComplete(frame_); |
| 3062 } |
| 3063 |
| 3064 void Document::CheckCompleted() { |
| 3065 if (!ShouldComplete()) |
| 3066 return; |
| 3067 |
| 3068 if (frame_) { |
| 3069 frame_->Client()->RunScriptsAtDocumentIdle(); |
| 3070 |
| 3071 // Injected scripts may have disconnected this frame. |
| 3072 if (!frame_) |
| 3073 return; |
| 3074 |
| 3075 // Check again, because runScriptsAtDocumentIdle() may have delayed the load |
| 3076 // event. |
| 3077 if (!ShouldComplete()) |
| 3078 return; |
| 3079 } |
| 3080 |
| 3081 // OK, completed. Fire load completion events as needed. |
| 3082 SetReadyState(kComplete); |
| 3083 if (LoadEventStillNeeded()) |
| 3084 ImplicitClose(); |
| 3085 |
| 3086 // The readystatechanged or load event may have disconnected this frame. |
| 3087 if (!frame_ || !frame_->IsAttached()) |
| 3088 return; |
| 3089 frame_->GetNavigationScheduler().StartTimer(); |
| 3090 View()->HandleLoadCompleted(); |
| 3091 // The document itself is complete, but if a child frame was restarted due to |
| 3092 // an event, this document is still considered to be in progress. |
| 3093 if (!AllDescendantsAreComplete(frame_)) |
| 3094 return; |
| 3095 |
| 3096 // No need to repeat if we've already notified this load as finished. |
| 3097 if (!Loader()->SentDidFinishLoad()) { |
| 3098 if (frame_->IsMainFrame()) |
| 3099 ViewportDescription().ReportMobilePageStats(frame_); |
| 3100 Loader()->SetSentDidFinishLoad(); |
| 3101 frame_->Client()->DispatchDidFinishLoad(); |
| 3102 if (!frame_) |
| 3103 return; |
| 3104 } |
| 3105 |
| 3106 frame_->Loader().DidFinishNavigation(); |
| 3107 } |
| 3108 |
3060 bool Document::DispatchBeforeUnloadEvent(ChromeClient& chrome_client, | 3109 bool Document::DispatchBeforeUnloadEvent(ChromeClient& chrome_client, |
3061 bool is_reload, | 3110 bool is_reload, |
3062 bool& did_allow_navigation) { | 3111 bool& did_allow_navigation) { |
3063 if (!dom_window_) | 3112 if (!dom_window_) |
3064 return true; | 3113 return true; |
3065 | 3114 |
3066 if (!body()) | 3115 if (!body()) |
3067 return true; | 3116 return true; |
3068 | 3117 |
3069 if (ProcessingBeforeUnload()) | 3118 if (ProcessingBeforeUnload()) |
(...skipping 2903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5973 --load_event_delay_count_; | 6022 --load_event_delay_count_; |
5974 | 6023 |
5975 if (!load_event_delay_count_) | 6024 if (!load_event_delay_count_) |
5976 CheckLoadEventSoon(); | 6025 CheckLoadEventSoon(); |
5977 } | 6026 } |
5978 | 6027 |
5979 void Document::DecrementLoadEventDelayCountAndCheckLoadEvent() { | 6028 void Document::DecrementLoadEventDelayCountAndCheckLoadEvent() { |
5980 DCHECK(load_event_delay_count_); | 6029 DCHECK(load_event_delay_count_); |
5981 --load_event_delay_count_; | 6030 --load_event_delay_count_; |
5982 | 6031 |
5983 if (!load_event_delay_count_ && GetFrame()) | 6032 if (!load_event_delay_count_) |
5984 GetFrame()->Loader().CheckCompleted(); | 6033 CheckCompleted(); |
5985 } | 6034 } |
5986 | 6035 |
5987 void Document::CheckLoadEventSoon() { | 6036 void Document::CheckLoadEventSoon() { |
5988 if (GetFrame() && !load_event_delay_timer_.IsActive()) | 6037 if (GetFrame() && !load_event_delay_timer_.IsActive()) |
5989 load_event_delay_timer_.StartOneShot(0, BLINK_FROM_HERE); | 6038 load_event_delay_timer_.StartOneShot(0, BLINK_FROM_HERE); |
5990 } | 6039 } |
5991 | 6040 |
5992 bool Document::IsDelayingLoadEvent() { | 6041 bool Document::IsDelayingLoadEvent() { |
5993 // Always delay load events until after garbage collection. | 6042 // Always delay load events until after garbage collection. |
5994 // This way we don't have to explicitly delay load events via | 6043 // This way we don't have to explicitly delay load events via |
5995 // incrementLoadEventDelayCount and decrementLoadEventDelayCount in | 6044 // incrementLoadEventDelayCount and decrementLoadEventDelayCount in |
5996 // Node destructors. | 6045 // Node destructors. |
5997 if (ThreadState::Current()->SweepForbidden()) { | 6046 if (ThreadState::Current()->SweepForbidden()) { |
5998 if (!load_event_delay_count_) | 6047 if (!load_event_delay_count_) |
5999 CheckLoadEventSoon(); | 6048 CheckLoadEventSoon(); |
6000 return true; | 6049 return true; |
6001 } | 6050 } |
6002 return load_event_delay_count_; | 6051 return load_event_delay_count_; |
6003 } | 6052 } |
6004 | 6053 |
6005 void Document::LoadEventDelayTimerFired(TimerBase*) { | 6054 void Document::LoadEventDelayTimerFired(TimerBase*) { |
6006 if (GetFrame()) | 6055 CheckCompleted(); |
6007 GetFrame()->Loader().CheckCompleted(); | |
6008 } | 6056 } |
6009 | 6057 |
6010 void Document::LoadPluginsSoon() { | 6058 void Document::LoadPluginsSoon() { |
6011 // FIXME: Remove this timer once we don't need to compute layout to load | 6059 // FIXME: Remove this timer once we don't need to compute layout to load |
6012 // plugins. | 6060 // plugins. |
6013 if (!plugin_loading_timer_.IsActive()) | 6061 if (!plugin_loading_timer_.IsActive()) |
6014 plugin_loading_timer_.StartOneShot(0, BLINK_FROM_HERE); | 6062 plugin_loading_timer_.StartOneShot(0, BLINK_FROM_HERE); |
6015 } | 6063 } |
6016 | 6064 |
6017 void Document::PluginLoadingTimerFired(TimerBase*) { | 6065 void Document::PluginLoadingTimerFired(TimerBase*) { |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6665 } | 6713 } |
6666 | 6714 |
6667 void showLiveDocumentInstances() { | 6715 void showLiveDocumentInstances() { |
6668 WeakDocumentSet& set = liveDocumentSet(); | 6716 WeakDocumentSet& set = liveDocumentSet(); |
6669 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); | 6717 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); |
6670 for (blink::Document* document : set) | 6718 for (blink::Document* document : set) |
6671 fprintf(stderr, "- Document %p URL: %s\n", document, | 6719 fprintf(stderr, "- Document %p URL: %s\n", document, |
6672 document->Url().GetString().Utf8().Data()); | 6720 document->Url().GetString().Utf8().Data()); |
6673 } | 6721 } |
6674 #endif | 6722 #endif |
OLD | NEW |