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

Side by Side Diff: chrome/browser/ui/cocoa/speech_recognition_bubble_cocoa.mm

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
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 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #include "chrome/browser/speech/speech_recognition_bubble.h" 7 #include "chrome/browser/speech/speech_recognition_bubble.h"
8 8
9 #import "base/mac/scoped_nsobject.h" 9 #import "base/mac/scoped_nsobject.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" 11 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h"
12 #include "chrome/browser/ui/cocoa/browser_window_controller.h" 12 #include "chrome/browser/ui/cocoa/browser_window_controller.h"
13 #include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" 13 #include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
14 #import "chrome/browser/ui/cocoa/speech_recognition_window_controller.h" 14 #import "chrome/browser/ui/cocoa/speech_recognition_window_controller.h"
15 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
16 #include "content/public/browser/web_contents_view.h" 16 #include "content/public/browser/web_contents_view.h"
17 #include "ui/gfx/image/image_skia_util_mac.h" 17 #include "ui/gfx/image/image_skia_util_mac.h"
18 18
19 using content::WebContents; 19 using content::WebContents;
20 20
21 namespace { 21 namespace {
22 22
23 // A class to bridge between the speech recognition C++ code and the Objective-C 23 // A class to bridge between the speech recognition C++ code and the Objective-C
24 // bubble implementation. See chrome/browser/speech/speech_recognition_bubble.h 24 // bubble implementation. See chrome/browser/speech/speech_recognition_bubble.h
25 // for more information on how this gets used. 25 // for more information on how this gets used.
26 class SpeechRecognitionBubbleImpl : public SpeechRecognitionBubbleBase { 26 class SpeechRecognitionBubbleImpl : public SpeechRecognitionBubbleBase {
27 public: 27 public:
28 SpeechRecognitionBubbleImpl(WebContents* web_contents, 28 SpeechRecognitionBubbleImpl(WebContents* test_web_contents,
29 Delegate* delegate,
30 const gfx::Rect& element_rect);
31 SpeechRecognitionBubbleImpl(int render_process_id,
32 int render_view_id,
29 Delegate* delegate, 33 Delegate* delegate,
30 const gfx::Rect& element_rect); 34 const gfx::Rect& element_rect);
31 virtual ~SpeechRecognitionBubbleImpl(); 35 virtual ~SpeechRecognitionBubbleImpl();
32 virtual void Show() OVERRIDE; 36 virtual void Show() OVERRIDE;
33 virtual void Hide() OVERRIDE; 37 virtual void Hide() OVERRIDE;
34 virtual void UpdateLayout() OVERRIDE; 38 virtual void UpdateLayout() OVERRIDE;
35 virtual void UpdateImage() OVERRIDE; 39 virtual void UpdateImage() OVERRIDE;
36 40
37 private: 41 private:
38 base::scoped_nsobject<SpeechRecognitionWindowController> window_; 42 base::scoped_nsobject<SpeechRecognitionWindowController> window_;
39 Delegate* delegate_; 43 Delegate* delegate_;
40 gfx::Rect element_rect_; 44 gfx::Rect element_rect_;
41 }; 45 };
42 46
43 SpeechRecognitionBubbleImpl::SpeechRecognitionBubbleImpl( 47 SpeechRecognitionBubbleImpl::SpeechRecognitionBubbleImpl(
44 WebContents* web_contents, 48 WebContents* test_web_contents,
45 Delegate* delegate, 49 Delegate* delegate,
46 const gfx::Rect& element_rect) 50 const gfx::Rect& element_rect)
47 : SpeechRecognitionBubbleBase(web_contents), 51 : SpeechRecognitionBubbleBase(test_web_contents),
48 delegate_(delegate), 52 delegate_(delegate),
49 element_rect_(element_rect) { 53 element_rect_(element_rect) {
50 } 54 }
55
56 SpeechRecognitionBubbleImpl::SpeechRecognitionBubbleImpl(
57 int render_process_id,
58 int render_view_id,
59 Delegate* delegate,
60 const gfx::Rect& element_rect)
61 : SpeechRecognitionBubbleBase(render_process_id, render_view_id),
62 delegate_(delegate),
63 element_rect_(element_rect) {
64 }
51 65
52 SpeechRecognitionBubbleImpl::~SpeechRecognitionBubbleImpl() { 66 SpeechRecognitionBubbleImpl::~SpeechRecognitionBubbleImpl() {
53 if (window_.get()) 67 if (window_.get())
54 [window_.get() close]; 68 [window_.get() close];
55 } 69 }
56 70
57 void SpeechRecognitionBubbleImpl::UpdateImage() { 71 void SpeechRecognitionBubbleImpl::UpdateImage() {
58 if (window_.get()) 72 if (window_.get() && GetWebContents())
59 [window_.get() setImage:gfx::NSImageFromImageSkia(icon_image())]; 73 [window_.get() setImage:gfx::NSImageFromImageSkia(icon_image())];
60 } 74 }
61 75
62 void SpeechRecognitionBubbleImpl::Show() { 76 void SpeechRecognitionBubbleImpl::Show() {
77 if (!GetWebContents())
78 return;
79
63 if (window_.get()) { 80 if (window_.get()) {
64 [window_.get() show]; 81 [window_.get() show];
65 return; 82 return;
66 } 83 }
67 84
68 // Find the screen coordinates for the given tab and position the bubble's 85 // Find the screen coordinates for the given tab and position the bubble's
69 // arrow anchor point inside that to point at the bottom-left of the html 86 // arrow anchor point inside that to point at the bottom-left of the html
70 // input element rect if the position is valid, otherwise point it towards 87 // input element rect if the position is valid, otherwise point it towards
71 // the page icon in the omnibox. 88 // the page icon in the omnibox.
72 gfx::NativeView view = GetWebContents()->GetView()->GetNativeView(); 89 gfx::NativeView view = GetWebContents()->GetView()->GetNativeView();
(...skipping 27 matching lines...) Expand all
100 window_.reset([[SpeechRecognitionWindowController alloc] 117 window_.reset([[SpeechRecognitionWindowController alloc]
101 initWithParentWindow:parent_window 118 initWithParentWindow:parent_window
102 delegate:delegate_ 119 delegate:delegate_
103 anchoredAt:anchor]); 120 anchoredAt:anchor]);
104 121
105 UpdateLayout(); 122 UpdateLayout();
106 [window_.get() show]; 123 [window_.get() show];
107 } 124 }
108 125
109 void SpeechRecognitionBubbleImpl::Hide() { 126 void SpeechRecognitionBubbleImpl::Hide() {
110 if (!window_.get()) 127 if (!window_.get() || !GetWebContents())
111 return; 128 return;
112 129
113 [window_.get() close]; 130 [window_.get() close];
114 window_.reset(); 131 window_.reset();
115 } 132 }
116 133
117 void SpeechRecognitionBubbleImpl::UpdateLayout() { 134 void SpeechRecognitionBubbleImpl::UpdateLayout() {
118 if (!window_.get()) 135 if (!window_.get() || !GetWebContents())
119 return; 136 return;
120 137
121 [window_.get() updateLayout:display_mode() 138 [window_.get() updateLayout:display_mode()
122 messageText:message_text() 139 messageText:message_text()
123 iconImage:gfx::NSImageFromImageSkia(icon_image())]; 140 iconImage:gfx::NSImageFromImageSkia(icon_image())];
124 } 141 }
125 142
126 } // namespace 143 } // namespace
127 144
128 SpeechRecognitionBubble* SpeechRecognitionBubble::CreateNativeBubble( 145 SpeechRecognitionBubble* SpeechRecognitionBubble::CreateNativeBubble(
129 WebContents* web_contents, 146 WebContents* test_web_contents,
130 Delegate* delegate, 147 Delegate* delegate,
131 const gfx::Rect& element_rect) { 148 const gfx::Rect& element_rect) {
132 return new SpeechRecognitionBubbleImpl(web_contents, delegate, element_rect); 149 return new SpeechRecognitionBubbleImpl(test_web_contents,
150 delegate,
151 element_rect);
133 } 152 }
153
154 SpeechRecognitionBubble* SpeechRecognitionBubble::CreateNativeBubble(
155 int render_process_id,
156 int render_view_id,
157 Delegate* delegate,
158 const gfx::Rect& element_rect) {
159 return new SpeechRecognitionBubbleImpl(render_process_id,
160 render_view_id,
161 delegate,
162 element_rect);
163 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698