OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #import "ios/chrome/browser/voice/text_to_speech_listener.h" | 5 #import "ios/chrome/browser/voice/text_to_speech_listener.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/ios/weak_nsobject.h" | 9 #include "base/ios/weak_nsobject.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/mac/scoped_nsobject.h" | 11 #include "base/mac/scoped_nsobject.h" |
12 #include "ios/web/public/navigation_manager.h" | 12 #include "ios/web/public/navigation_manager.h" |
13 #include "ios/web/public/web_state/web_state.h" | 13 #include "ios/web/public/web_state/web_state.h" |
14 #include "ios/web/public/web_state/web_state_observer.h" | 14 #include "ios/web/public/web_state/web_state_observer.h" |
15 #import "ios/chrome/browser/voice/text_to_speech_parser.h" | 15 #import "ios/chrome/browser/voice/text_to_speech_parser.h" |
16 #import "ios/chrome/browser/voice/voice_search_url_rewriter.h" | 16 #import "ios/chrome/browser/voice/voice_search_url_rewriter.h" |
17 #include "url/gurl.h" | 17 #include "url/gurl.h" |
18 | 18 |
19 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
20 #error "This file requires ARC support." | |
21 #endif | |
22 | |
19 #pragma mark - TextToSpeechListener Private Interface | 23 #pragma mark - TextToSpeechListener Private Interface |
20 | 24 |
21 class TextToSpeechWebStateObserver; | 25 class TextToSpeechWebStateObserver; |
22 | 26 |
23 @interface TextToSpeechListener () | 27 @interface TextToSpeechListener () |
24 | 28 |
25 // The TextToSpeechListenerDelegate passed on initialization. | 29 // The TextToSpeechListenerDelegate passed on initialization. |
26 @property(nonatomic, readonly) id<TextToSpeechListenerDelegate> delegate; | 30 @property(weak, nonatomic, readonly) id<TextToSpeechListenerDelegate> delegate; |
27 | 31 |
28 @end | 32 @end |
29 | 33 |
30 #pragma mark - TextToSpeechWebStateObserver | 34 #pragma mark - TextToSpeechWebStateObserver |
31 | 35 |
32 class TextToSpeechWebStateObserver : public web::WebStateObserver { | 36 class TextToSpeechWebStateObserver : public web::WebStateObserver { |
33 public: | 37 public: |
34 TextToSpeechWebStateObserver(web::WebState* web_state, | 38 TextToSpeechWebStateObserver(web::WebState* web_state, |
35 TextToSpeechListener* listener); | 39 TextToSpeechListener* listener); |
36 ~TextToSpeechWebStateObserver() override; | 40 ~TextToSpeechWebStateObserver() override; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 } | 78 } |
75 | 79 |
76 void TextToSpeechWebStateObserver::WebStateDestroyed() { | 80 void TextToSpeechWebStateObserver::WebStateDestroyed() { |
77 [listener_.delegate textToSpeechListenerWebStateWasDestroyed:listener_]; | 81 [listener_.delegate textToSpeechListenerWebStateWasDestroyed:listener_]; |
78 } | 82 } |
79 | 83 |
80 #pragma mark - TextToSpeechListener | 84 #pragma mark - TextToSpeechListener |
81 | 85 |
82 @implementation TextToSpeechListener { | 86 @implementation TextToSpeechListener { |
83 // Backing object for property of the same name. | 87 // Backing object for property of the same name. |
84 base::WeakNSProtocol<id<TextToSpeechListenerDelegate>> _delegate; | 88 base::WeakNSProtocol<id<TextToSpeechListenerDelegate>> _delegate; |
noyau (Ping after 24h)
2016/11/21 14:15:03
Why don't you remove all that code? Everything rel
stkhapugin
2016/11/22 14:13:26
Done.
| |
85 // The TextToSpeechWebStateObserver that listens for Text-To-Speech data. | 89 // The TextToSpeechWebStateObserver that listens for Text-To-Speech data. |
86 std::unique_ptr<TextToSpeechWebStateObserver> _webStateObserver; | 90 std::unique_ptr<TextToSpeechWebStateObserver> _webStateObserver; |
87 } | 91 } |
88 | 92 |
89 - (instancetype)initWithWebState:(web::WebState*)webState | 93 - (instancetype)initWithWebState:(web::WebState*)webState |
90 delegate:(id<TextToSpeechListenerDelegate>)delegate { | 94 delegate:(id<TextToSpeechListenerDelegate>)delegate { |
91 if ((self = [super init])) { | 95 if ((self = [super init])) { |
92 DCHECK(webState); | 96 DCHECK(webState); |
93 DCHECK(delegate); | 97 DCHECK(delegate); |
94 _webStateObserver.reset(new TextToSpeechWebStateObserver(webState, self)); | 98 _webStateObserver.reset(new TextToSpeechWebStateObserver(webState, self)); |
95 _delegate.reset(delegate); | 99 _delegate.reset(delegate); |
96 } | 100 } |
97 return self; | 101 return self; |
98 } | 102 } |
99 | 103 |
100 #pragma mark Accessors | 104 #pragma mark Accessors |
101 | 105 |
102 - (web::WebState*)webState { | 106 - (web::WebState*)webState { |
103 return _webStateObserver->web_state(); | 107 return _webStateObserver->web_state(); |
104 } | 108 } |
105 | 109 |
106 - (id<TextToSpeechListenerDelegate>)delegate { | 110 - (id<TextToSpeechListenerDelegate>)delegate { |
107 return _delegate.get(); | 111 return _delegate.get(); |
108 } | 112 } |
109 | 113 |
110 @end | 114 @end |
OLD | NEW |