Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(290)

Side by Side Diff: chrome/browser/speech/speech_recognition_bubble.h

Issue 148343008: Speech Recognition API: Safeguarding against page closes during startup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/speech/speech_recognition_bubble.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_SPEECH_SPEECH_RECOGNITION_BUBBLE_H_ 5 #ifndef CHROME_BROWSER_SPEECH_SPEECH_RECOGNITION_BUBBLE_H_
6 #define CHROME_BROWSER_SPEECH_SPEECH_RECOGNITION_BUBBLE_H_ 6 #define CHROME_BROWSER_SPEECH_SPEECH_RECOGNITION_BUBBLE_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 // The InfoBubble window is no longer visible on screen and the caller can 48 // The InfoBubble window is no longer visible on screen and the caller can
49 // free the InfoBubble instance. This callback is not issued if the bubble 49 // free the InfoBubble instance. This callback is not issued if the bubble
50 // got closed because the object was destroyed by the caller. 50 // got closed because the object was destroyed by the caller.
51 virtual void InfoBubbleFocusChanged() = 0; 51 virtual void InfoBubbleFocusChanged() = 0;
52 52
53 protected: 53 protected:
54 virtual ~Delegate() { 54 virtual ~Delegate() {
55 } 55 }
56 }; 56 };
57 57
58 // Factory method to create new instances. 58 // Factory methods to create new instances.
59 // Creates the bubble, call |Show| to display it on screen. 59 // Creates the bubble, call |Show| to display it on screen.
60
60 // |web_contents| is the WebContents hosting the page. 61 // |web_contents| is the WebContents hosting the page.
61 // |element_rect| is the display bounds of the html element requesting speech 62 // |element_rect| is the display bounds of the html element requesting speech
62 // recognition (in page coordinates). 63 // recognition (in page coordinates).
63 static SpeechRecognitionBubble* Create(content::WebContents* web_contents, 64 // This should ONLY be called from for tests
sky 2014/02/12 18:12:18 Isn't there a way to make the tests go through the
64 Delegate* delegate, 65 static SpeechRecognitionBubble* Create(
65 const gfx::Rect& element_rect); 66 content::WebContents*,
66
67 // This is implemented by platform specific code to create the underlying
68 // bubble window. Not to be called directly by users of this class.
69 static SpeechRecognitionBubble* CreateNativeBubble(
70 content::WebContents* web_contents,
71 Delegate* delegate, 67 Delegate* delegate,
72 const gfx::Rect& element_rect); 68 const gfx::Rect& element_rect);
73 69
70 // |render_process_id| and |render_view_id| is used to extract the
71 // correct WebContents.
72 // |element_rect| is the display bounds of the html element requesting speech
73 // recognition (in page coordinates).
74 static SpeechRecognitionBubble* Create(
75 int render_process_id,
76 int render_view_id,
77 Delegate* delegate,
78 const gfx::Rect& element_rect);
79
80 // These are implemented by platform specific code to create the underlying
81 // bubble window. Not to be called directly by users of this class.
82 static SpeechRecognitionBubble* CreateNativeBubble(
83 content::WebContents*,
84 Delegate* delegate,
85 const gfx::Rect& element_rect);
86 static SpeechRecognitionBubble* CreateNativeBubble(
87 int render_process_id,
88 int render_view_id,
89 Delegate* delegate,
90 const gfx::Rect& element_rect);
91
74 // |Create| uses the currently registered FactoryMethod to create the 92 // |Create| uses the currently registered FactoryMethod to create the
75 // SpeechRecognitionBubble instances. FactoryMethod is intended for testing. 93 // SpeechRecognitionBubble instances. FactoryMethod is intended for testing.
76 typedef SpeechRecognitionBubble* (*FactoryMethod)(content::WebContents*, 94 typedef SpeechRecognitionBubble* (*FactoryMethod)(content::WebContents*,
77 Delegate*, 95 Delegate*,
78 const gfx::Rect&); 96 const gfx::Rect&);
79 // Sets the factory used by the static method Create. SpeechRecognitionBubble 97 // Sets the factory used by the static method Create. SpeechRecognitionBubble
80 // does not take ownership of |factory|. A value of NULL results in a 98 // does not take ownership of |factory|. A value of NULL results in a
81 // SpeechRecognitionBubble being created directly. 99 // SpeechRecognitionBubble being created directly.
82 #if defined(UNIT_TEST) 100 #if defined(UNIT_TEST)
83 static void set_factory(FactoryMethod factory) { factory_ = factory; } 101 static void set_factory(FactoryMethod factory) { factory_ = factory; }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 public: 146 public:
129 // The current display mode of the bubble, useful only for the platform 147 // The current display mode of the bubble, useful only for the platform
130 // specific implementation. 148 // specific implementation.
131 enum DisplayMode { 149 enum DisplayMode {
132 DISPLAY_MODE_WARM_UP, 150 DISPLAY_MODE_WARM_UP,
133 DISPLAY_MODE_RECORDING, 151 DISPLAY_MODE_RECORDING,
134 DISPLAY_MODE_RECOGNIZING, 152 DISPLAY_MODE_RECOGNIZING,
135 DISPLAY_MODE_MESSAGE 153 DISPLAY_MODE_MESSAGE
136 }; 154 };
137 155
138 explicit SpeechRecognitionBubbleBase(content::WebContents* web_contents); 156 // Only for tests
157 explicit SpeechRecognitionBubbleBase(content::WebContents* test_web_contents);
158
159 SpeechRecognitionBubbleBase(int render_process_id, int render_view_id);
139 virtual ~SpeechRecognitionBubbleBase(); 160 virtual ~SpeechRecognitionBubbleBase();
140 161
141 // SpeechRecognitionBubble methods 162 // SpeechRecognitionBubble methods
142 virtual void SetWarmUpMode() OVERRIDE; 163 virtual void SetWarmUpMode() OVERRIDE;
143 virtual void SetRecordingMode() OVERRIDE; 164 virtual void SetRecordingMode() OVERRIDE;
144 virtual void SetRecognizingMode() OVERRIDE; 165 virtual void SetRecognizingMode() OVERRIDE;
145 virtual void SetMessage(const base::string16& text) OVERRIDE; 166 virtual void SetMessage(const base::string16& text) OVERRIDE;
146 virtual void SetInputVolume(float volume, float noise_volume) OVERRIDE; 167 virtual void SetInputVolume(float volume, float noise_volume) OVERRIDE;
147 virtual content::WebContents* GetWebContents() OVERRIDE; 168 virtual content::WebContents* GetWebContents() OVERRIDE;
148 169
149 protected: 170 protected:
150 // Updates the platform specific UI layout for the current display mode. 171 // Updates the platform specific UI layout for the current display mode.
151 virtual void UpdateLayout() = 0; 172 virtual void UpdateLayout() = 0;
152 173
153 // Overridden by subclasses to copy |icon_image()| to the screen. 174 // Overridden by subclasses to copy |icon_image()| to the screen.
154 virtual void UpdateImage() = 0; 175 virtual void UpdateImage() = 0;
155 176
156 DisplayMode display_mode() const { return display_mode_; } 177 DisplayMode display_mode() const { return display_mode_; }
157 178
158 const base::string16& message_text() const { return message_text_; } 179 const base::string16& message_text() const { return message_text_; }
159 180
160 gfx::ImageSkia icon_image(); 181 gfx::ImageSkia icon_image();
161 182
162 private: 183 private:
184 void Initialize();
185
163 void DoRecognizingAnimationStep(); 186 void DoRecognizingAnimationStep();
164 void DoWarmingUpAnimationStep(); 187 void DoWarmingUpAnimationStep();
165 void SetImage(const gfx::ImageSkia& image); 188 void SetImage(const gfx::ImageSkia& image);
166 189
167 void DrawVolumeOverlay(SkCanvas* canvas, 190 void DrawVolumeOverlay(SkCanvas* canvas,
168 const gfx::ImageSkia& image_skia, 191 const gfx::ImageSkia& image_skia,
169 float volume); 192 float volume);
170 193
171 // Task factory used for animation timer. 194 // Task factory used for animation timer.
172 base::WeakPtrFactory<SpeechRecognitionBubbleBase> weak_factory_; 195 base::WeakPtrFactory<SpeechRecognitionBubbleBase> weak_factory_;
173 int animation_step_; // Current index/step of the animation. 196 int animation_step_; // Current index/step of the animation.
174 197
175 DisplayMode display_mode_; 198 DisplayMode display_mode_;
176 base::string16 message_text_; // Text displayed in DISPLAY_MODE_MESSAGE 199 base::string16 message_text_; // Text displayed in DISPLAY_MODE_MESSAGE
177 200
178 // The current microphone image with volume level indication. 201 // The current microphone image with volume level indication.
179 scoped_ptr<SkBitmap> mic_image_; 202 scoped_ptr<SkBitmap> mic_image_;
180 // A temporary buffer image used in creating the above mic image. 203 // A temporary buffer image used in creating the above mic image.
181 scoped_ptr<SkBitmap> buffer_image_; 204 scoped_ptr<SkBitmap> buffer_image_;
205
182 // WebContents in which this this bubble gets displayed. 206 // WebContents in which this this bubble gets displayed.
183 content::WebContents* web_contents_; 207 content::WebContents* test_web_contents_;
208 int render_process_id_;
209 int render_view_id_;
210
184 // The current image displayed in the bubble's icon widget. 211 // The current image displayed in the bubble's icon widget.
185 gfx::ImageSkia icon_image_; 212 gfx::ImageSkia icon_image_;
186 // The scale factor used for the web-contents. 213 // The scale factor used for the web-contents.
187 float scale_; 214 float scale_;
188 215
189 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionBubbleBase); 216 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionBubbleBase);
190 }; 217 };
191 218
192 // This typedef is to workaround the issue with certain versions of 219 // This typedef is to workaround the issue with certain versions of
193 // Visual Studio where it gets confused between multiple Delegate 220 // Visual Studio where it gets confused between multiple Delegate
194 // classes and gives a C2500 error. (I saw this error on the try bots - 221 // classes and gives a C2500 error. (I saw this error on the try bots -
195 // the workaround was not needed for my machine). 222 // the workaround was not needed for my machine).
196 typedef SpeechRecognitionBubble::Delegate SpeechRecognitionBubbleDelegate; 223 typedef SpeechRecognitionBubble::Delegate SpeechRecognitionBubbleDelegate;
197 224
198 #endif // CHROME_BROWSER_SPEECH_SPEECH_RECOGNITION_BUBBLE_H_ 225 #endif // CHROME_BROWSER_SPEECH_SPEECH_RECOGNITION_BUBBLE_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/speech/speech_recognition_bubble.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698