| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Neither the name of Google Inc. nor the names of its | 10 * * Neither the name of Google Inc. nor the names of its |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #ifndef ContextFeatures_h | 27 #ifndef ContextFeatures_h |
| 28 #define ContextFeatures_h | 28 #define ContextFeatures_h |
| 29 | 29 |
| 30 #include "core/CoreExport.h" | 30 #include "core/CoreExport.h" |
| 31 #include "core/page/Page.h" | 31 #include "core/page/Page.h" |
| 32 #include "platform/heap/Handle.h" | 32 #include "platform/heap/Handle.h" |
| 33 #include <memory> | |
| 34 | 33 |
| 35 namespace blink { | 34 namespace blink { |
| 36 | 35 |
| 37 class ContextFeaturesClient; | 36 class ContextFeaturesClient; |
| 38 class Document; | 37 class Document; |
| 39 class Page; | 38 class Page; |
| 40 | 39 |
| 41 class ContextFeatures final : public GarbageCollectedFinalized<ContextFeatures>,
public Supplement<Page> { | 40 class ContextFeatures final : public GarbageCollectedFinalized<ContextFeatures>,
public Supplement<Page> { |
| 42 USING_GARBAGE_COLLECTED_MIXIN(ContextFeatures); | 41 USING_GARBAGE_COLLECTED_MIXIN(ContextFeatures); |
| 43 public: | 42 public: |
| 44 enum FeatureType { | 43 enum FeatureType { |
| 45 PagePopup = 0, | 44 PagePopup = 0, |
| 46 MutationEvents, | 45 MutationEvents, |
| 47 FeatureTypeSize // Should be the last entry. | 46 FeatureTypeSize // Should be the last entry. |
| 48 }; | 47 }; |
| 49 | 48 |
| 50 static const char* supplementName(); | 49 static const char* supplementName(); |
| 51 static ContextFeatures& defaultSwitch(); | 50 static ContextFeatures& defaultSwitch(); |
| 52 static ContextFeatures* create(std::unique_ptr<ContextFeaturesClient>); | 51 static ContextFeatures* create(PassOwnPtr<ContextFeaturesClient>); |
| 53 | 52 |
| 54 static bool pagePopupEnabled(Document*); | 53 static bool pagePopupEnabled(Document*); |
| 55 static bool mutationEventsEnabled(Document*); | 54 static bool mutationEventsEnabled(Document*); |
| 56 | 55 |
| 57 bool isEnabled(Document*, FeatureType, bool) const; | 56 bool isEnabled(Document*, FeatureType, bool) const; |
| 58 void urlDidChange(Document*); | 57 void urlDidChange(Document*); |
| 59 | 58 |
| 60 private: | 59 private: |
| 61 explicit ContextFeatures(std::unique_ptr<ContextFeaturesClient> client) | 60 explicit ContextFeatures(PassOwnPtr<ContextFeaturesClient> client) |
| 62 : m_client(std::move(client)) | 61 : m_client(std::move(client)) |
| 63 { } | 62 { } |
| 64 | 63 |
| 65 std::unique_ptr<ContextFeaturesClient> m_client; | 64 OwnPtr<ContextFeaturesClient> m_client; |
| 66 }; | 65 }; |
| 67 | 66 |
| 68 class ContextFeaturesClient { | 67 class ContextFeaturesClient { |
| 69 USING_FAST_MALLOC(ContextFeaturesClient); | 68 USING_FAST_MALLOC(ContextFeaturesClient); |
| 70 public: | 69 public: |
| 71 static std::unique_ptr<ContextFeaturesClient> empty(); | 70 static PassOwnPtr<ContextFeaturesClient> empty(); |
| 72 | 71 |
| 73 virtual ~ContextFeaturesClient() { } | 72 virtual ~ContextFeaturesClient() { } |
| 74 virtual bool isEnabled(Document*, ContextFeatures::FeatureType, bool default
Value) { return defaultValue; } | 73 virtual bool isEnabled(Document*, ContextFeatures::FeatureType, bool default
Value) { return defaultValue; } |
| 75 virtual void urlDidChange(Document*) { } | 74 virtual void urlDidChange(Document*) { } |
| 76 }; | 75 }; |
| 77 | 76 |
| 78 CORE_EXPORT void provideContextFeaturesTo(Page&, std::unique_ptr<ContextFeatures
Client>); | 77 CORE_EXPORT void provideContextFeaturesTo(Page&, PassOwnPtr<ContextFeaturesClien
t>); |
| 79 void provideContextFeaturesToDocumentFrom(Document&, Page&); | 78 void provideContextFeaturesToDocumentFrom(Document&, Page&); |
| 80 | 79 |
| 81 inline ContextFeatures* ContextFeatures::create(std::unique_ptr<ContextFeaturesC
lient> client) | 80 inline ContextFeatures* ContextFeatures::create(PassOwnPtr<ContextFeaturesClient
> client) |
| 82 { | 81 { |
| 83 return new ContextFeatures(std::move(client)); | 82 return new ContextFeatures(std::move(client)); |
| 84 } | 83 } |
| 85 | 84 |
| 86 inline bool ContextFeatures::isEnabled(Document* document, FeatureType type, boo
l defaultValue) const | 85 inline bool ContextFeatures::isEnabled(Document* document, FeatureType type, boo
l defaultValue) const |
| 87 { | 86 { |
| 88 if (!m_client) | 87 if (!m_client) |
| 89 return defaultValue; | 88 return defaultValue; |
| 90 return m_client->isEnabled(document, type, defaultValue); | 89 return m_client->isEnabled(document, type, defaultValue); |
| 91 } | 90 } |
| 92 | 91 |
| 93 inline void ContextFeatures::urlDidChange(Document* document) | 92 inline void ContextFeatures::urlDidChange(Document* document) |
| 94 { | 93 { |
| 95 // FIXME: The original code, commented out below, is obviously | 94 // FIXME: The original code, commented out below, is obviously |
| 96 // wrong, but the seemingly correct fix of negating the test to | 95 // wrong, but the seemingly correct fix of negating the test to |
| 97 // the more logical 'if (!m_client)' crashes the renderer. | 96 // the more logical 'if (!m_client)' crashes the renderer. |
| 98 // See issue 294180 | 97 // See issue 294180 |
| 99 // | 98 // |
| 100 // if (m_client) | 99 // if (m_client) |
| 101 // return; | 100 // return; |
| 102 // m_client->urlDidChange(document); | 101 // m_client->urlDidChange(document); |
| 103 } | 102 } |
| 104 | 103 |
| 105 } // namespace blink | 104 } // namespace blink |
| 106 | 105 |
| 107 #endif // ContextFeatures_h | 106 #endif // ContextFeatures_h |
| OLD | NEW |