| 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_(kLoadEventCompleted), | 491 load_event_progress_(kLoadEventNotRun), |
| 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; |
| 2773 } | 2776 } |
| 2774 | 2777 |
| 2775 void Document::DetachParser() { | 2778 void Document::DetachParser() { |
| 2776 if (!parser_) | 2779 if (!parser_) |
| 2777 return; | 2780 return; |
| 2778 parser_->Detach(); | 2781 parser_->Detach(); |
| 2779 parser_.Clear(); | 2782 parser_.Clear(); |
| 2780 DocumentParserTiming::From(*this).MarkParserDetached(); | 2783 DocumentParserTiming::From(*this).MarkParserDetached(); |
| 2781 } | 2784 } |
| 2782 | 2785 |
| 2783 void Document::CancelParsing() { | 2786 void Document::CancelParsing() { |
| 2784 DetachParser(); | 2787 DetachParser(); |
| 2785 SetParsingState(kFinishedParsing); | 2788 SetParsingState(kFinishedParsing); |
| 2786 SetReadyState(kComplete); | 2789 SetReadyState(kComplete); |
| 2787 SuppressLoadEvent(); | |
| 2788 } | 2790 } |
| 2789 | 2791 |
| 2790 DocumentParser* Document::ImplicitOpen( | 2792 DocumentParser* Document::ImplicitOpen( |
| 2791 ParserSynchronizationPolicy parser_sync_policy) { | 2793 ParserSynchronizationPolicy parser_sync_policy) { |
| 2794 DetachParser(); |
| 2795 |
| 2792 RemoveChildren(); | 2796 RemoveChildren(); |
| 2793 DCHECK(!focused_element_); | 2797 DCHECK(!focused_element_); |
| 2794 | 2798 |
| 2795 SetCompatibilityMode(kNoQuirksMode); | 2799 SetCompatibilityMode(kNoQuirksMode); |
| 2796 | 2800 |
| 2797 if (!ThreadedParsingEnabledForTesting()) { | 2801 if (!ThreadedParsingEnabledForTesting()) { |
| 2798 parser_sync_policy = kForceSynchronousParsing; | 2802 parser_sync_policy = kForceSynchronousParsing; |
| 2799 } else if (parser_sync_policy == kAllowAsynchronousParsing && | 2803 } else if (parser_sync_policy == kAllowAsynchronousParsing && |
| 2800 IsPrefetchOnly()) { | 2804 IsPrefetchOnly()) { |
| 2801 // Prefetch must be synchronous. | 2805 // Prefetch must be synchronous. |
| 2802 parser_sync_policy = kForceSynchronousParsing; | 2806 parser_sync_policy = kForceSynchronousParsing; |
| 2803 } | 2807 } |
| 2804 | 2808 |
| 2805 DetachParser(); | |
| 2806 parser_sync_policy_ = parser_sync_policy; | 2809 parser_sync_policy_ = parser_sync_policy; |
| 2807 parser_ = CreateParser(); | 2810 parser_ = CreateParser(); |
| 2808 DocumentParserTiming::From(*this).MarkParserStart(); | 2811 DocumentParserTiming::From(*this).MarkParserStart(); |
| 2809 SetParsingState(kParsing); | 2812 SetParsingState(kParsing); |
| 2810 SetReadyState(kLoading); | 2813 SetReadyState(kLoading); |
| 2811 if (load_event_progress_ != kLoadEventInProgress && | |
| 2812 PageDismissalEventBeingDispatched() == kNoDismissal) { | |
| 2813 load_event_progress_ = kLoadEventNotRun; | |
| 2814 } | |
| 2815 | 2814 |
| 2816 return parser_; | 2815 return parser_; |
| 2817 } | 2816 } |
| 2818 | 2817 |
| 2819 HTMLElement* Document::body() const { | 2818 HTMLElement* Document::body() const { |
| 2820 if (!documentElement() || !isHTMLHtmlElement(documentElement())) | 2819 if (!documentElement() || !isHTMLHtmlElement(documentElement())) |
| 2821 return 0; | 2820 return 0; |
| 2822 | 2821 |
| 2823 for (HTMLElement* child = | 2822 for (HTMLElement* child = |
| 2824 Traversal<HTMLElement>::FirstChild(*documentElement()); | 2823 Traversal<HTMLElement>::FirstChild(*documentElement()); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2946 | 2945 |
| 2947 close(); | 2946 close(); |
| 2948 } | 2947 } |
| 2949 | 2948 |
| 2950 void Document::close() { | 2949 void Document::close() { |
| 2951 if (!GetScriptableDocumentParser() || | 2950 if (!GetScriptableDocumentParser() || |
| 2952 !GetScriptableDocumentParser()->WasCreatedByScript() || | 2951 !GetScriptableDocumentParser()->WasCreatedByScript() || |
| 2953 !GetScriptableDocumentParser()->IsParsing()) | 2952 !GetScriptableDocumentParser()->IsParsing()) |
| 2954 return; | 2953 return; |
| 2955 | 2954 |
| 2956 parser_->Finish(); | 2955 if (DocumentParser* parser = parser_) |
| 2957 if (!parser_ || !parser_->IsParsing()) | 2956 parser->Finish(); |
| 2958 SetReadyState(kComplete); | 2957 |
| 2959 CheckCompleted(); | 2958 if (!frame_) { |
| 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(); |
| 2960 } | 2968 } |
| 2961 | 2969 |
| 2962 void Document::ImplicitClose() { | 2970 void Document::ImplicitClose() { |
| 2963 DCHECK(!InStyleRecalc()); | 2971 DCHECK(!InStyleRecalc()); |
| 2964 DCHECK(parser_); | 2972 if (ProcessingLoadEvent() || !parser_) |
| 2973 return; |
| 2974 if (GetFrame() && |
| 2975 GetFrame()->GetNavigationScheduler().LocationChangePending()) { |
| 2976 SuppressLoadEvent(); |
| 2977 return; |
| 2978 } |
| 2965 | 2979 |
| 2966 load_event_progress_ = kLoadEventInProgress; | 2980 load_event_progress_ = kLoadEventInProgress; |
| 2967 | 2981 |
| 2968 ScriptableDocumentParser* parser = GetScriptableDocumentParser(); | 2982 ScriptableDocumentParser* parser = GetScriptableDocumentParser(); |
| 2969 well_formed_ = parser && parser->WellFormed(); | 2983 well_formed_ = parser && parser->WellFormed(); |
| 2970 | 2984 |
| 2971 // We have to clear the parser, in case someone document.write()s from the | 2985 // We have to clear the parser, in case someone document.write()s from the |
| 2972 // onLoad event handler, as in Radar 3206524. | 2986 // onLoad event handler, as in Radar 3206524. |
| 2973 DetachParser(); | 2987 DetachParser(); |
| 2974 | 2988 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3036 cache->HandleLoadComplete(this); | 3050 cache->HandleLoadComplete(this); |
| 3037 else | 3051 else |
| 3038 cache->HandleLayoutComplete(this); | 3052 cache->HandleLayoutComplete(this); |
| 3039 } | 3053 } |
| 3040 } | 3054 } |
| 3041 | 3055 |
| 3042 if (SvgExtensions()) | 3056 if (SvgExtensions()) |
| 3043 AccessSVGExtensions().StartAnimations(); | 3057 AccessSVGExtensions().StartAnimations(); |
| 3044 } | 3058 } |
| 3045 | 3059 |
| 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 | |
| 3109 bool Document::DispatchBeforeUnloadEvent(ChromeClient& chrome_client, | 3060 bool Document::DispatchBeforeUnloadEvent(ChromeClient& chrome_client, |
| 3110 bool is_reload, | 3061 bool is_reload, |
| 3111 bool& did_allow_navigation) { | 3062 bool& did_allow_navigation) { |
| 3112 if (!dom_window_) | 3063 if (!dom_window_) |
| 3113 return true; | 3064 return true; |
| 3114 | 3065 |
| 3115 if (!body()) | 3066 if (!body()) |
| 3116 return true; | 3067 return true; |
| 3117 | 3068 |
| 3118 if (ProcessingBeforeUnload()) | 3069 if (ProcessingBeforeUnload()) |
| (...skipping 2903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6022 --load_event_delay_count_; | 5973 --load_event_delay_count_; |
| 6023 | 5974 |
| 6024 if (!load_event_delay_count_) | 5975 if (!load_event_delay_count_) |
| 6025 CheckLoadEventSoon(); | 5976 CheckLoadEventSoon(); |
| 6026 } | 5977 } |
| 6027 | 5978 |
| 6028 void Document::DecrementLoadEventDelayCountAndCheckLoadEvent() { | 5979 void Document::DecrementLoadEventDelayCountAndCheckLoadEvent() { |
| 6029 DCHECK(load_event_delay_count_); | 5980 DCHECK(load_event_delay_count_); |
| 6030 --load_event_delay_count_; | 5981 --load_event_delay_count_; |
| 6031 | 5982 |
| 6032 if (!load_event_delay_count_) | 5983 if (!load_event_delay_count_ && GetFrame()) |
| 6033 CheckCompleted(); | 5984 GetFrame()->Loader().CheckCompleted(); |
| 6034 } | 5985 } |
| 6035 | 5986 |
| 6036 void Document::CheckLoadEventSoon() { | 5987 void Document::CheckLoadEventSoon() { |
| 6037 if (GetFrame() && !load_event_delay_timer_.IsActive()) | 5988 if (GetFrame() && !load_event_delay_timer_.IsActive()) |
| 6038 load_event_delay_timer_.StartOneShot(0, BLINK_FROM_HERE); | 5989 load_event_delay_timer_.StartOneShot(0, BLINK_FROM_HERE); |
| 6039 } | 5990 } |
| 6040 | 5991 |
| 6041 bool Document::IsDelayingLoadEvent() { | 5992 bool Document::IsDelayingLoadEvent() { |
| 6042 // Always delay load events until after garbage collection. | 5993 // Always delay load events until after garbage collection. |
| 6043 // This way we don't have to explicitly delay load events via | 5994 // This way we don't have to explicitly delay load events via |
| 6044 // incrementLoadEventDelayCount and decrementLoadEventDelayCount in | 5995 // incrementLoadEventDelayCount and decrementLoadEventDelayCount in |
| 6045 // Node destructors. | 5996 // Node destructors. |
| 6046 if (ThreadState::Current()->SweepForbidden()) { | 5997 if (ThreadState::Current()->SweepForbidden()) { |
| 6047 if (!load_event_delay_count_) | 5998 if (!load_event_delay_count_) |
| 6048 CheckLoadEventSoon(); | 5999 CheckLoadEventSoon(); |
| 6049 return true; | 6000 return true; |
| 6050 } | 6001 } |
| 6051 return load_event_delay_count_; | 6002 return load_event_delay_count_; |
| 6052 } | 6003 } |
| 6053 | 6004 |
| 6054 void Document::LoadEventDelayTimerFired(TimerBase*) { | 6005 void Document::LoadEventDelayTimerFired(TimerBase*) { |
| 6055 CheckCompleted(); | 6006 if (GetFrame()) |
| 6007 GetFrame()->Loader().CheckCompleted(); |
| 6056 } | 6008 } |
| 6057 | 6009 |
| 6058 void Document::LoadPluginsSoon() { | 6010 void Document::LoadPluginsSoon() { |
| 6059 // FIXME: Remove this timer once we don't need to compute layout to load | 6011 // FIXME: Remove this timer once we don't need to compute layout to load |
| 6060 // plugins. | 6012 // plugins. |
| 6061 if (!plugin_loading_timer_.IsActive()) | 6013 if (!plugin_loading_timer_.IsActive()) |
| 6062 plugin_loading_timer_.StartOneShot(0, BLINK_FROM_HERE); | 6014 plugin_loading_timer_.StartOneShot(0, BLINK_FROM_HERE); |
| 6063 } | 6015 } |
| 6064 | 6016 |
| 6065 void Document::PluginLoadingTimerFired(TimerBase*) { | 6017 void Document::PluginLoadingTimerFired(TimerBase*) { |
| (...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6713 } | 6665 } |
| 6714 | 6666 |
| 6715 void showLiveDocumentInstances() { | 6667 void showLiveDocumentInstances() { |
| 6716 WeakDocumentSet& set = liveDocumentSet(); | 6668 WeakDocumentSet& set = liveDocumentSet(); |
| 6717 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); | 6669 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); |
| 6718 for (blink::Document* document : set) | 6670 for (blink::Document* document : set) |
| 6719 fprintf(stderr, "- Document %p URL: %s\n", document, | 6671 fprintf(stderr, "- Document %p URL: %s\n", document, |
| 6720 document->Url().GetString().Utf8().Data()); | 6672 document->Url().GetString().Utf8().Data()); |
| 6721 } | 6673 } |
| 6722 #endif | 6674 #endif |
| OLD | NEW |