Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / find_bar / find_bar_cocoa_controller.mm
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
3 // found in the LICENSE file.
4
5 #import <Cocoa/Cocoa.h>
6
7 #include "base/auto_reset.h"
8 #include "base/mac/bundle_locations.h"
9 #include "base/mac/mac_util.h"
10 #include "base/strings/sys_string_conversions.h"
11 #include "chrome/browser/ui/browser_finder.h"
12 #include "chrome/browser/ui/browser_window.h"
13 #include "chrome/browser/ui/cocoa/browser_window_controller.h"
14 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
15 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h"
16 #import "chrome/browser/ui/cocoa/find_bar/find_bar_text_field.h"
17 #import "chrome/browser/ui/cocoa/find_bar/find_bar_text_field_cell.h"
18 #import "chrome/browser/ui/cocoa/image_button_cell.h"
19 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
20 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
21 #include "chrome/browser/ui/find_bar/find_tab_helper.h"
22 #include "content/public/browser/render_view_host.h"
23 #include "content/public/browser/web_contents.h"
24 #include "grit/theme_resources.h"
25 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h"
26 #import "ui/base/cocoa/find_pasteboard.h"
27 #import "ui/base/cocoa/focus_tracker.h"
28 #import "ui/base/cocoa/nsview_additions.h"
29 #include "ui/resources/grit/ui_resources.h"
30
31 using content::NativeWebKeyboardEvent;
32
33 const float kFindBarOpenDuration = 0.2;
34 const float kFindBarCloseDuration = 0.15;
35 const float kFindBarMoveDuration = 0.15;
36 const float kRightEdgeOffset = 25;
37
38
39 @interface FindBarCocoaController (PrivateMethods) <NSAnimationDelegate>
40 // Returns the appropriate frame for a hidden find bar.
41 - (NSRect)hiddenFindBarFrame;
42
43 // Animates the given |view| to the given |endFrame| within |duration| seconds.
44 // Returns a new NSViewAnimation.
45 - (NSViewAnimation*)createAnimationForView:(NSView*)view
46                                    toFrame:(NSRect)endFrame
47                                   duration:(float)duration;
48
49 // Sets the frame of |findBarView_|.  |duration| is ignored if |animate| is NO.
50 - (void)setFindBarFrame:(NSRect)endFrame
51                 animate:(BOOL)animate
52                duration:(float)duration;
53
54 // Returns the horizontal position the FindBar should use in order to avoid
55 // overlapping with the current find result, if there's one.
56 - (float)findBarHorizontalPosition;
57
58 // Adjusts the horizontal position if necessary to avoid overlapping with the
59 // current find result.
60 - (void)moveFindBarIfNecessary:(BOOL)animate;
61
62 // Puts |text| into the find bar and enables the buttons, but doesn't start a
63 // new search for |text|.
64 - (void)prepopulateText:(NSString*)text;
65
66 // Clears the find results for all tabs in browser associated with this find
67 // bar. If |suppressPboardUpdateActions_| is true then the current tab is not
68 // cleared.
69 - (void)clearFindResultsForCurrentBrowser;
70
71 - (BrowserWindowController*)browserWindowController;
72 @end
73
74 @implementation FindBarCocoaController
75
76 @synthesize findBarView = findBarView_;
77
78 - (id)initWithBrowser:(Browser*)browser {
79   if ((self = [super initWithNibName:@"FindBar"
80                               bundle:base::mac::FrameworkBundle()])) {
81     [[NSNotificationCenter defaultCenter]
82         addObserver:self
83            selector:@selector(findPboardUpdated:)
84                name:kFindPasteboardChangedNotification
85              object:[FindPasteboard sharedInstance]];
86     browser_ = browser;
87   }
88   return self;
89 }
90
91 - (void)dealloc {
92   // All animations should have been explicitly stopped before a tab is closed.
93   DCHECK(!showHideAnimation_.get());
94   DCHECK(!moveAnimation_.get());
95   [[NSNotificationCenter defaultCenter] removeObserver:self];
96   [super dealloc];
97 }
98
99 - (void)setFindBarBridge:(FindBarBridge*)findBarBridge {
100   DCHECK(!findBarBridge_);  // should only be called once.
101   findBarBridge_ = findBarBridge;
102 }
103
104 - (void)awakeFromNib {
105   [[closeButton_ cell] setImageID:IDR_CLOSE_1
106                    forButtonState:image_button_cell::kDefaultState];
107   [[closeButton_ cell] setImageID:IDR_CLOSE_1_H
108                    forButtonState:image_button_cell::kHoverState];
109   [[closeButton_ cell] setImageID:IDR_CLOSE_1_P
110                    forButtonState:image_button_cell::kPressedState];
111   [[closeButton_ cell] setImageID:IDR_CLOSE_1
112                    forButtonState:image_button_cell::kDisabledState];
113
114   [findBarView_ setFrame:[self hiddenFindBarFrame]];
115   defaultWidth_ = NSWidth([findBarView_ frame]);
116   [[self view] setHidden:YES];
117
118   [self prepopulateText:[[FindPasteboard sharedInstance] findText]];
119 }
120
121 - (IBAction)close:(id)sender {
122   if (findBarBridge_)
123     findBarBridge_->GetFindBarController()->EndFindSession(
124         FindBarController::kKeepSelectionOnPage,
125         FindBarController::kKeepResultsInFindBox);
126
127   // Turn off hover state on close button else the button will remain
128   // hovered when we bring the find bar back up.
129   // crbug.com/227424
130   [[closeButton_ cell] setIsMouseInside:NO];
131 }
132
133 - (IBAction)previousResult:(id)sender {
134   if (findBarBridge_) {
135     FindTabHelper* findTabHelper = FindTabHelper::FromWebContents(
136         findBarBridge_->GetFindBarController()->web_contents());
137     findTabHelper->StartFinding(
138         base::SysNSStringToUTF16([findText_ stringValue]),
139         false, false);
140   }
141 }
142
143 - (IBAction)nextResult:(id)sender {
144   if (findBarBridge_) {
145     FindTabHelper* findTabHelper = FindTabHelper::FromWebContents(
146         findBarBridge_->GetFindBarController()->web_contents());
147     findTabHelper->StartFinding(
148         base::SysNSStringToUTF16([findText_ stringValue]),
149         true, false);
150   }
151 }
152
153 - (void)findPboardUpdated:(NSNotification*)notification {
154   if (!suppressPboardUpdateActions_)
155     [self prepopulateText:[[FindPasteboard sharedInstance] findText]];
156   [self clearFindResultsForCurrentBrowser];
157 }
158
159 - (void)positionFindBarViewAtMaxY:(CGFloat)maxY maxWidth:(CGFloat)maxWidth {
160   NSView* containerView = [self view];
161   CGFloat containerHeight = NSHeight([containerView frame]);
162   CGFloat containerWidth = std::min(maxWidth, defaultWidth_);
163
164   // Adjust where we'll actually place the find bar.
165   maxY += [containerView cr_lineWidth];
166   maxY_ = maxY;
167   CGFloat x = [self findBarHorizontalPosition];
168   NSRect newFrame = NSMakeRect(x, maxY - containerHeight,
169                                containerWidth, containerHeight);
170
171   if (moveAnimation_.get() != nil) {
172     NSRect frame = [containerView frame];
173     [moveAnimation_ stopAnimation];
174     // Restore to the X position before the animation was stopped. The Y
175     // position is immediately adjusted.
176     frame.origin.y = newFrame.origin.y;
177     [containerView setFrame:frame];
178     moveAnimation_.reset([self createAnimationForView:containerView
179                                               toFrame:newFrame
180                                              duration:kFindBarMoveDuration]);
181   } else {
182     [containerView setFrame:newFrame];
183   }
184 }
185
186 - (BOOL)isOffTheRecordProfile {
187   return browser_ && browser_->profile() &&
188          browser_->profile()->IsOffTheRecord();
189 }
190
191 // NSControl delegate method.
192 - (void)controlTextDidChange:(NSNotification*)aNotification {
193   if (!findBarBridge_)
194     return;
195
196   content::WebContents* webContents =
197       findBarBridge_->GetFindBarController()->web_contents();
198   if (!webContents)
199     return;
200   FindTabHelper* findTabHelper = FindTabHelper::FromWebContents(webContents);
201
202   NSString* findText = [findText_ stringValue];
203   if (![self isOffTheRecordProfile]) {
204     base::AutoReset<BOOL> suppressReset(&suppressPboardUpdateActions_, YES);
205     [[FindPasteboard sharedInstance] setFindText:findText];
206   }
207
208   if ([findText length] > 0) {
209     findTabHelper->
210         StartFinding(base::SysNSStringToUTF16(findText), true, false);
211   } else {
212     // The textbox is empty so we reset.
213     findTabHelper->StopFinding(FindBarController::kClearSelectionOnPage);
214     [self updateUIForFindResult:findTabHelper->find_result()
215                        withText:base::string16()];
216   }
217 }
218
219 // NSControl delegate method
220 - (BOOL)control:(NSControl*)control
221     textView:(NSTextView*)textView
222     doCommandBySelector:(SEL)command {
223   if (command == @selector(insertNewline:)) {
224     // Pressing Return
225     NSEvent* event = [NSApp currentEvent];
226
227     if ([event modifierFlags] & NSShiftKeyMask)
228       [previousButton_ performClick:nil];
229     else
230       [nextButton_ performClick:nil];
231
232     return YES;
233   } else if (command == @selector(insertLineBreak:)) {
234     // Pressing Ctrl-Return
235     if (findBarBridge_) {
236       findBarBridge_->GetFindBarController()->EndFindSession(
237           FindBarController::kActivateSelectionOnPage,
238           FindBarController::kClearResultsInFindBox);
239     }
240     return YES;
241   } else if (command == @selector(pageUp:) ||
242              command == @selector(pageUpAndModifySelection:) ||
243              command == @selector(scrollPageUp:) ||
244              command == @selector(pageDown:) ||
245              command == @selector(pageDownAndModifySelection:) ||
246              command == @selector(scrollPageDown:) ||
247              command == @selector(scrollToBeginningOfDocument:) ||
248              command == @selector(scrollToEndOfDocument:) ||
249              command == @selector(moveUp:) ||
250              command == @selector(moveDown:)) {
251     content::WebContents* web_contents =
252         findBarBridge_->GetFindBarController()->web_contents();
253     if (!web_contents)
254       return NO;
255
256     // Sanity-check to make sure we got a keyboard event.
257     NSEvent* event = [NSApp currentEvent];
258     if ([event type] != NSKeyDown && [event type] != NSKeyUp)
259       return NO;
260
261     // Forward the event to the renderer.
262     // TODO(rohitrao): Should this call -[BaseView keyEvent:]?  Is there code in
263     // that function that we want to keep or avoid? Calling
264     // |ForwardKeyboardEvent()| directly ignores edit commands, which breaks
265     // cmd-up/down if we ever decide to include |moveToBeginningOfDocument:| in
266     // the list above.
267     content::RenderViewHost* render_view_host =
268         web_contents->GetRenderViewHost();
269     render_view_host->ForwardKeyboardEvent(NativeWebKeyboardEvent(event));
270     return YES;
271   }
272
273   return NO;
274 }
275
276 // Methods from FindBar
277 - (void)showFindBar:(BOOL)animate {
278   // Save the currently-focused view.  |findBarView_| is in the view
279   // hierarchy by now.  showFindBar can be called even when the
280   // findbar is already open, so do not overwrite an already saved
281   // view.
282   if (!focusTracker_.get())
283     focusTracker_.reset(
284         [[FocusTracker alloc] initWithWindow:[findBarView_ window]]);
285
286   // The browser window might have changed while the FindBar was hidden.
287   // Update its position now.
288   [[self browserWindowController] layoutSubviews];
289
290   // Move to the correct horizontal position first, to prevent the FindBar
291   // from jumping around when switching tabs.
292   // Prevent jumping while the FindBar is animating (hiding, then showing) too.
293   if (![self isFindBarVisible])
294     [self moveFindBarIfNecessary:NO];
295
296   // Animate the view into place.
297   NSRect frame = [findBarView_ frame];
298   frame.origin = NSZeroPoint;
299   [self setFindBarFrame:frame animate:animate duration:kFindBarOpenDuration];
300 }
301
302 - (void)hideFindBar:(BOOL)animate {
303   NSRect frame = [self hiddenFindBarFrame];
304   [self setFindBarFrame:frame animate:animate duration:kFindBarCloseDuration];
305 }
306
307 - (void)stopAnimation {
308   if (showHideAnimation_.get()) {
309     [showHideAnimation_ stopAnimation];
310     showHideAnimation_.reset(nil);
311   }
312   if (moveAnimation_.get()) {
313     [moveAnimation_ stopAnimation];
314     moveAnimation_.reset(nil);
315   }
316 }
317
318 - (void)setFocusAndSelection {
319   [[findText_ window] makeFirstResponder:findText_];
320
321   // Enable the buttons if the find text is non-empty.
322   BOOL buttonsEnabled = ([[findText_ stringValue] length] > 0) ? YES : NO;
323   [previousButton_ setEnabled:buttonsEnabled];
324   [nextButton_ setEnabled:buttonsEnabled];
325 }
326
327 - (void)restoreSavedFocus {
328   if (!(focusTracker_.get() &&
329         [focusTracker_ restoreFocusInWindow:[findBarView_ window]])) {
330     // Fall back to giving focus to the tab contents.
331     findBarBridge_->GetFindBarController()->web_contents()->Focus();
332   }
333   focusTracker_.reset(nil);
334 }
335
336 - (void)setFindText:(NSString*)findText
337       selectedRange:(const NSRange&)selectedRange {
338   [findText_ setStringValue:findText];
339
340   if (![self isOffTheRecordProfile]) {
341     // Make sure the text in the find bar always ends up in the find pasteboard
342     // (and, via notifications, in the other find bars too).
343     base::AutoReset<BOOL> suppressReset(&suppressPboardUpdateActions_, YES);
344     [[FindPasteboard sharedInstance] setFindText:findText];
345   }
346
347   NSText* editor = [findText_ currentEditor];
348   if (selectedRange.location != NSNotFound)
349     [editor setSelectedRange:selectedRange];
350 }
351
352 - (NSString*)findText {
353   return [findText_ stringValue];
354 }
355
356 - (NSRange)selectedRange {
357   NSText* editor = [findText_ currentEditor];
358   return (editor != nil) ? [editor selectedRange] : NSMakeRange(NSNotFound, 0);
359 }
360
361 - (NSString*)matchCountText {
362   return [[findText_ findBarTextFieldCell] resultsString];
363 }
364
365 - (void)updateFindBarForChangedWebContents {
366   content::WebContents* contents =
367       findBarBridge_->GetFindBarController()->web_contents();
368   if (!contents)
369     return;
370   FindTabHelper* findTabHelper = FindTabHelper::FromWebContents(contents);
371
372   // If the find UI is visible but the results are cleared then also clear
373   // the results label and update the buttons.
374   if (findTabHelper->find_ui_active() &&
375       findTabHelper->previous_find_text().empty()) {
376     BOOL buttonsEnabled = [[findText_ stringValue] length] > 0 ? YES : NO;
377     [previousButton_ setEnabled:buttonsEnabled];
378     [nextButton_ setEnabled:buttonsEnabled];
379     [[findText_ findBarTextFieldCell] clearResults];
380   }
381 }
382
383 - (void)clearResults:(const FindNotificationDetails&)results {
384   // Just call updateUIForFindResult, which will take care of clearing
385   // the search text and the results label.
386   [self updateUIForFindResult:results withText:base::string16()];
387 }
388
389 - (void)updateUIForFindResult:(const FindNotificationDetails&)result
390                      withText:(const base::string16&)findText {
391   // If we don't have any results and something was passed in, then
392   // that means someone pressed Cmd-G while the Find box was
393   // closed. In that case we need to repopulate the Find box with what
394   // was passed in.
395   if ([[findText_ stringValue] length] == 0 && !findText.empty()) {
396     [findText_ setStringValue:base::SysUTF16ToNSString(findText)];
397     [findText_ selectText:self];
398   }
399
400   // Make sure Find Next and Find Previous are enabled if we found any matches.
401   BOOL buttonsEnabled = result.number_of_matches() > 0;
402   [previousButton_ setEnabled:buttonsEnabled];
403   [nextButton_ setEnabled:buttonsEnabled];
404
405   // Update the results label.
406   BOOL validRange = result.active_match_ordinal() != -1 &&
407                     result.number_of_matches() != -1;
408   NSString* searchString = [findText_ stringValue];
409   if ([searchString length] > 0 && validRange) {
410     [[findText_ findBarTextFieldCell]
411         setActiveMatch:result.active_match_ordinal()
412                     of:result.number_of_matches()];
413   } else {
414     // If there was no text entered, we don't show anything in the results area.
415     [[findText_ findBarTextFieldCell] clearResults];
416   }
417
418   [findText_ resetFieldEditorFrameIfNeeded];
419
420   // If we found any results, reset the focus tracker, so we always
421   // restore focus to the tab contents.
422   if (result.number_of_matches() > 0)
423     focusTracker_.reset(nil);
424
425   // Adjust the FindBar position, even when there are no matches (so that it
426   // goes back to the default position, if required).
427   [self moveFindBarIfNecessary:[self isFindBarVisible]];
428 }
429
430 - (BOOL)isFindBarVisible {
431   // Find bar is visible if any part of it is on the screen.
432   return NSIntersectsRect([[self view] bounds], [findBarView_ frame]);
433 }
434
435 - (BOOL)isFindBarAnimating {
436   return (showHideAnimation_.get() != nil) || (moveAnimation_.get() != nil);
437 }
438
439 // NSAnimation delegate methods.
440 - (void)animationDidEnd:(NSAnimation*)animation {
441   // Autorelease the animations (cannot use release because the animation object
442   // is still on the stack.
443   if (animation == showHideAnimation_.get()) {
444     [showHideAnimation_.release() autorelease];
445   } else if (animation == moveAnimation_.get()) {
446     [moveAnimation_.release() autorelease];
447   } else {
448     NOTREACHED();
449   }
450
451   // If the find bar is not visible, make it actually hidden, so it'll no longer
452   // respond to key events.
453   [[self view] setHidden:![self isFindBarVisible]];
454 }
455
456 - (gfx::Point)findBarWindowPosition {
457   gfx::Rect viewRect(NSRectToCGRect([[self view] frame]));
458   // Convert Cocoa coordinates (Y growing up) to Y growing down.
459   // Offset from |maxY_|, which represents the content view's top, instead
460   // of from the superview, which represents the whole browser window.
461   viewRect.set_y(maxY_ - viewRect.bottom());
462   return viewRect.origin();
463 }
464
465 - (int)findBarWidth {
466   return NSWidth([[self view] frame]);
467 }
468
469 @end
470
471 @implementation FindBarCocoaController (PrivateMethods)
472
473 - (NSRect)hiddenFindBarFrame {
474   NSRect frame = [findBarView_ frame];
475   NSRect containerBounds = [[self view] bounds];
476   frame.origin = NSMakePoint(NSMinX(containerBounds), NSMaxY(containerBounds));
477   return frame;
478 }
479
480 - (NSViewAnimation*)createAnimationForView:(NSView*)view
481                                    toFrame:(NSRect)endFrame
482                                   duration:(float)duration {
483   NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:
484       view, NSViewAnimationTargetKey,
485       [NSValue valueWithRect:endFrame], NSViewAnimationEndFrameKey, nil];
486
487   NSViewAnimation* animation =
488       [[NSViewAnimation alloc]
489         initWithViewAnimations:[NSArray arrayWithObjects:dict, nil]];
490   [animation gtm_setDuration:duration
491                    eventMask:NSLeftMouseUpMask];
492   [animation setDelegate:self];
493   [animation startAnimation];
494   return animation;
495 }
496
497 - (void)setFindBarFrame:(NSRect)endFrame
498                 animate:(BOOL)animate
499                duration:(float)duration {
500   // Save the current frame.
501   NSRect startFrame = [findBarView_ frame];
502
503   // Stop any existing animations.
504   [showHideAnimation_ stopAnimation];
505
506   if (!animate) {
507     [findBarView_ setFrame:endFrame];
508     [[self view] setHidden:![self isFindBarVisible]];
509     showHideAnimation_.reset(nil);
510     return;
511   }
512
513   // If animating, ensure that the find bar is not hidden. Hidden status will be
514   // updated at the end of the animation.
515   [[self view] setHidden:NO];
516
517   // Reset the frame to what was saved above.
518   [findBarView_ setFrame:startFrame];
519
520   showHideAnimation_.reset([self createAnimationForView:findBarView_
521                                                 toFrame:endFrame
522                                                duration:duration]);
523 }
524
525 - (float)findBarHorizontalPosition {
526   // Get the rect of the FindBar.
527   NSView* view = [self view];
528   NSRect frame = [view frame];
529   gfx::Rect viewRect(NSRectToCGRect(frame));
530
531   if (!findBarBridge_ || !findBarBridge_->GetFindBarController())
532     return frame.origin.x;
533   content::WebContents* contents =
534       findBarBridge_->GetFindBarController()->web_contents();
535   if (!contents)
536     return frame.origin.x;
537
538   // Get the size of the container.
539   gfx::Rect containerRect(contents->GetContainerBounds().size());
540
541   // Position the FindBar on the top right corner.
542   viewRect.set_x(
543       containerRect.width() - viewRect.width() - kRightEdgeOffset);
544   // Convert from Cocoa coordinates (Y growing up) to Y growing down.
545   // Notice that the view frame's Y offset is relative to the whole window,
546   // while GetLocationForFindbarView() expects it relative to the
547   // content's boundaries. |maxY_| has the correct placement in Cocoa coords,
548   // so we just have to invert the Y coordinate.
549   viewRect.set_y(maxY_ - viewRect.bottom());
550
551   // Get the rect of the current find result, if there is one.
552   const FindNotificationDetails& findResult =
553       FindTabHelper::FromWebContents(contents)->find_result();
554   if (findResult.number_of_matches() == 0)
555     return viewRect.x();
556   gfx::Rect selectionRect(findResult.selection_rect());
557
558   // Adjust |view_rect| to avoid the |selection_rect| within |container_rect|.
559   gfx::Rect newPos = FindBarController::GetLocationForFindbarView(
560       viewRect, containerRect, selectionRect);
561
562   return newPos.x();
563 }
564
565 - (void)moveFindBarIfNecessary:(BOOL)animate {
566   // Don't animate during tests.
567   if (FindBarBridge::disable_animations_during_testing_)
568     animate = NO;
569
570   NSView* view = [self view];
571   NSRect frame = [view frame];
572   float x = [self findBarHorizontalPosition];
573   if (frame.origin.x == x)
574     return;
575
576   if (animate) {
577     [moveAnimation_ stopAnimation];
578     // Restore to the position before the animation was stopped.
579     [view setFrame:frame];
580     frame.origin.x = x;
581     moveAnimation_.reset([self createAnimationForView:view
582                                               toFrame:frame
583                                              duration:kFindBarMoveDuration]);
584   } else {
585     frame.origin.x = x;
586     [view setFrame:frame];
587   }
588 }
589
590 - (void)prepopulateText:(NSString*)text {
591   [self setFindText:text selectedRange:NSMakeRange(NSNotFound, 0)];
592
593   // Has to happen after |ClearResults()| above.
594   BOOL buttonsEnabled = [text length] > 0 ? YES : NO;
595   [previousButton_ setEnabled:buttonsEnabled];
596   [nextButton_ setEnabled:buttonsEnabled];
597 }
598
599 - (void)clearFindResultsForCurrentBrowser {
600   if (!browser_)
601     return;
602
603   content::WebContents* activeWebContents =
604       findBarBridge_->GetFindBarController()->web_contents();
605
606   TabStripModel* tabStripModel = browser_->tab_strip_model();
607   for (int i = 0; i < tabStripModel->count(); ++i) {
608     content::WebContents* webContents = tabStripModel->GetWebContentsAt(i);
609     if (suppressPboardUpdateActions_ && activeWebContents == webContents)
610       continue;
611     FindTabHelper* findTabHelper =
612         FindTabHelper::FromWebContents(webContents);
613     findTabHelper->StopFinding(FindBarController::kClearSelectionOnPage);
614     findBarBridge_->ClearResults(findTabHelper->find_result());
615   }
616 }
617
618 - (BrowserWindowController*)browserWindowController {
619   if (!browser_)
620     return nil;
621   return [BrowserWindowController
622       browserWindowControllerForWindow:browser_->window()->GetNativeWindow()];
623 }
624
625 @end