| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. | 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 #include "core/dom/PendingScript.h" | 26 #include "core/dom/PendingScript.h" |
| 27 | 27 |
| 28 #include "core/dom/ScriptElementBase.h" | 28 #include "core/dom/ScriptElementBase.h" |
| 29 #include "platform/wtf/CurrentTime.h" | 29 #include "platform/wtf/CurrentTime.h" |
| 30 | 30 |
| 31 namespace blink { | 31 namespace blink { |
| 32 | 32 |
| 33 PendingScript::PendingScript(ScriptElementBase* element, | 33 PendingScript::PendingScript(ScriptElementBase* element, |
| 34 const TextPosition& starting_position) | 34 const TextPosition& starting_position) |
| 35 : watching_for_load_(false), | 35 : element_(element), |
| 36 element_(element), | |
| 37 starting_position_(starting_position), | 36 starting_position_(starting_position), |
| 38 parser_blocking_load_start_time_(0), | 37 parser_blocking_load_start_time_(0), |
| 39 client_(nullptr) {} | 38 client_(nullptr) {} |
| 40 | 39 |
| 41 PendingScript::~PendingScript() {} | 40 PendingScript::~PendingScript() {} |
| 42 | 41 |
| 43 void PendingScript::Dispose() { | 42 void PendingScript::Dispose() { |
| 44 StopWatchingForLoad(); | 43 StopWatchingForLoad(); |
| 45 DCHECK(!Client()); | 44 DCHECK(!Client()); |
| 46 DCHECK(!IsWatchingForLoad()); | 45 DCHECK(!IsWatchingForLoad()); |
| 47 | 46 |
| 48 starting_position_ = TextPosition::BelowRangePosition(); | 47 starting_position_ = TextPosition::BelowRangePosition(); |
| 49 parser_blocking_load_start_time_ = 0; | 48 parser_blocking_load_start_time_ = 0; |
| 50 | 49 |
| 51 DisposeInternal(); | 50 DisposeInternal(); |
| 52 element_ = nullptr; | 51 element_ = nullptr; |
| 53 } | 52 } |
| 54 | 53 |
| 55 void PendingScript::WatchForLoad(PendingScriptClient* client) { | 54 void PendingScript::WatchForLoad(PendingScriptClient* client) { |
| 56 CheckState(); | 55 CheckState(); |
| 57 | 56 |
| 58 DCHECK(!IsWatchingForLoad()); | 57 DCHECK(!IsWatchingForLoad()); |
| 58 DCHECK(client); |
| 59 // addClient() will call streamingFinished() if the load is complete. Callers | 59 // addClient() will call streamingFinished() if the load is complete. Callers |
| 60 // who do not expect to be re-entered from this call should not call | 60 // who do not expect to be re-entered from this call should not call |
| 61 // watchForLoad for a PendingScript which isReady. We also need to set | 61 // watchForLoad for a PendingScript which isReady. We also need to set |
| 62 // m_watchingForLoad early, since addClient() can result in calling | 62 // m_watchingForLoad early, since addClient() can result in calling |
| 63 // notifyFinished and further stopWatchingForLoad(). | 63 // notifyFinished and further stopWatchingForLoad(). |
| 64 watching_for_load_ = true; | |
| 65 client_ = client; | 64 client_ = client; |
| 66 if (IsReady()) | 65 if (IsReady()) |
| 67 client_->PendingScriptFinished(this); | 66 client_->PendingScriptFinished(this); |
| 68 } | 67 } |
| 69 | 68 |
| 70 void PendingScript::StopWatchingForLoad() { | 69 void PendingScript::StopWatchingForLoad() { |
| 71 if (!IsWatchingForLoad()) | 70 if (!IsWatchingForLoad()) |
| 72 return; | 71 return; |
| 73 CheckState(); | 72 CheckState(); |
| 74 DCHECK(IsExternal()); | 73 DCHECK(IsExternal()); |
| 75 client_ = nullptr; | 74 client_ = nullptr; |
| 76 watching_for_load_ = false; | |
| 77 } | 75 } |
| 78 | 76 |
| 79 ScriptElementBase* PendingScript::GetElement() const { | 77 ScriptElementBase* PendingScript::GetElement() const { |
| 80 // As mentioned in the comment at |m_element| declaration, | 78 // As mentioned in the comment at |m_element| declaration, |
| 81 // |m_element| must point to the corresponding ScriptLoader's | 79 // |m_element| must point to the corresponding ScriptLoader's |
| 82 // client. | 80 // client. |
| 83 CHECK(element_); | 81 CHECK(element_); |
| 84 return element_.Get(); | 82 return element_.Get(); |
| 85 } | 83 } |
| 86 | 84 |
| 87 void PendingScript::MarkParserBlockingLoadStartTime() { | 85 void PendingScript::MarkParserBlockingLoadStartTime() { |
| 88 DCHECK_EQ(parser_blocking_load_start_time_, 0.0); | 86 DCHECK_EQ(parser_blocking_load_start_time_, 0.0); |
| 89 parser_blocking_load_start_time_ = MonotonicallyIncreasingTime(); | 87 parser_blocking_load_start_time_ = MonotonicallyIncreasingTime(); |
| 90 } | 88 } |
| 91 | 89 |
| 92 DEFINE_TRACE(PendingScript) { | 90 DEFINE_TRACE(PendingScript) { |
| 93 visitor->Trace(element_); | 91 visitor->Trace(element_); |
| 94 visitor->Trace(client_); | 92 visitor->Trace(client_); |
| 95 } | 93 } |
| 96 | 94 |
| 97 } // namespace blink | 95 } // namespace blink |
| OLD | NEW |